You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should improve the quality of the generated scripts.
The code currently relies on string concatenation and limited analysis on the intended output. This approach has, for convenience, lead to emitting non-idiomatic code, e.g.:
Importing things that aren't needed.
Single let top-level declarations for e.g. response bodies.
Using an object for storing variables instead of normal variable declarations.
Using computed property names (vars["abc"]) instead of normal dot syntax vars.abc.
String concatenation provides no type-safety, so producing valid output is largely a trial-and-error process. Strings need to be properly escaped on a case-by-case basis.
A common approach to code generation is to build an Abstract Syntax Tree (AST) and use that to generate a script. An AST is a tree structure that represents the semantics of the program without the complexities of syntax, e.g. blocks being contained between { and }. This is the way popular tools such as ESLint, Prettier and TypeScript generate JS.
This approach has already been adopted for the experimental browser recording functionality, and the idea is to use the same code for protocol level tests.
Why
Generating readable scripts will help users understand and troubleshoot their scripts. It can be easier to understand why something happened by looking at the script than it is by looking that the requests list.
The quality of the scripts is also important when using a recording as a starting point. If the quality is poor and requires too much cleanup to be passed off as production-grade, users will be reluctant to use it.
The approach describe here also makes it easier to have configurable output, e.g. generating typescript instead of javascript or emitting different scripts depending on the target version of k6.
The text was updated successfully, but these errors were encountered:
What
We should improve the quality of the generated scripts.
The code currently relies on string concatenation and limited analysis on the intended output. This approach has, for convenience, lead to emitting non-idiomatic code, e.g.:
let
top-level declarations for e.g.response
bodies.vars["abc"]
) instead of normal dot syntaxvars.abc
.String concatenation provides no type-safety, so producing valid output is largely a trial-and-error process. Strings need to be properly escaped on a case-by-case basis.
A common approach to code generation is to build an Abstract Syntax Tree (AST) and use that to generate a script. An AST is a tree structure that represents the semantics of the program without the complexities of syntax, e.g. blocks being contained between
{
and}
. This is the way popular tools such as ESLint, Prettier and TypeScript generate JS.This approach has already been adopted for the experimental browser recording functionality, and the idea is to use the same code for protocol level tests.
Why
Generating readable scripts will help users understand and troubleshoot their scripts. It can be easier to understand why something happened by looking at the script than it is by looking that the requests list.
The quality of the scripts is also important when using a recording as a starting point. If the quality is poor and requires too much cleanup to be passed off as production-grade, users will be reluctant to use it.
The approach describe here also makes it easier to have configurable output, e.g. generating typescript instead of javascript or emitting different scripts depending on the target version of k6.
The text was updated successfully, but these errors were encountered: