-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/support scenarios #89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool that we can now generate multiple scenario scripts 🤩
Left a few comments and some questions as well. There is one particular piece that I think needs to be addressed. The execution flow of the persistedImports was for me at least somewhat difficult to follow, more difficult than it needs to be I think.
TL;DR
The following is not a requirement, I just want to pick you and the other reviewers brains a little bit and see what you think.
We have talked about this earlier in the week but I'm going to mention it here again because I encountered it again now when re-reviewing.
So.. one thing that stood out when testing the feature was that it was not so easily tested compared to other features since it requires multiple archives passed in an array rather than one single archive (which means we cannot just simply run har-to-k6 examples/multi-scenario.har
).
I understand that code tries to be as non intrusive as possible to the HAR spec and existing implementation but I think conceptually it would make more sense to have one single data structure for grouping the scenarios since the options needs to be shared.
In the current PR implementation a test can be generated by one or more HARarchives. If multiple archives are passed then the options from the first archive will be the options which end up in the script. @w1kman please correct me if this is wrong.
I think if we instead merge the data into one unit it would make not only the implementation simpler but also would allow CLI support (which is most likely not need tho) but also make it conceptually clearer.
Configuration examples
Current PR implementation (separate archives)
- archive1.har (holds the scenario options)
- archive2.har
convert([archive1, archive2])
Proposition (combined data)
// single HAR file
{
options: {} // script options, scenario options etc..
archives: [
{ Scenario1HAR },
{ Scenario2HAR },
]
}
convert(archive)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments.
I think that the global state needs to be fixed, before I can approve this. It's unlikely to cause any issues, but if it does it's gonna be a pain to figure out why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are my change requests:
- Move resolving logic to convert.js but abstracted into a function
resolveImports
or something fitting. - Only if this case is not already covered, add simple validation rule that prevents multiple default exports.
options(main), | ||
...logicFunctions, | ||
] | ||
.filter(item => item) | ||
.join(`\n\n`) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this is in line with what I requested 👍 I think it should be happening earlier in the cycle though. Rather than having this logic in render I think it makes more sense to have it all the way up in convert.js making the flow:
- normalize
- validate
- parse
- resolveImports
- render
I think it will require minimal changes since this added logic already works on the result from parse.
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it maybe it would make sense to not only validate the archives individually but also the set. If I'm not mistaken the current implementation would not complain if there were multiple archives configured to export default right?
Perhaps we should add a simple validation rule that checks the set then also runs each individual archive like today
function convert() {
return normalize(archives, options)
|> validate // validates both the set and also individual archives
|> parse
|> resolveImports
|> render
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea is to allow an advanced user to convert several HAR objects into one script (rather than have to convert them one by one and then stitch them together). The intended output of a "multi conversion" is multiple test scenarios, excluding options.
Rather than having this logic in render I think it makes more sense to have it all the way up in convert.js making the flow
Sure. The same reasoning should also apply for the function names (moving that as well).
Come to think of it maybe it would make sense to not only validate the archives individually but also the set.
I don't see a case where two archives could pass validation as a single but cause a fail as a set (unless we're building scenario options).
If I'm not mistaken the current implementation would not complain if there were multiple archives configured to export default right?
There can only be one default export per script (no matter the configuration).
Perhaps we should add a simple validation rule that checks the set then also runs each individual archive like today
I cannot come up with anything to validate unless we want to throw on colliding names (which are now resolved instead).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well 👍 📦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small question, but other than that I think it looks good.
semi: false, | ||
arrowParens: 'avoid', | ||
parser: 'babel', | ||
plugins: [babelParser], | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
printWidth: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically a breaking change, as it means that the output will produce a different output from before. What was the reasoning behind it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Produced k6 script should look more like examples on k6.io.
#### Improved - Handle reserved words (javascript and k6/har-to-k6) - Better char replacement - camelCase functions - prettier config updated to generate code with same styling as our example (docs) #### Removed - namedExport from li-har-spec
- __ITER - __VU - open
6d21aee
to
55e92db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work! This is an awesome feature!
Support for converting several archives with
convert
convert
now accepts an array of archives. Every archive will become its own function in the produced script.I've added one optional properties on the
Log
interface to expose some kind of control over the result