-
Notifications
You must be signed in to change notification settings - Fork 1
feat: k6 generator #18
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,16 @@ | |||
| { | |||
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 file before was too large. Almost 15MB. If we need one with that many records, can we dynamically make them? Why do they need to be in a static file.
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.
Dynamically creating the information was an issue I ran into due to the nature of k6 and imports, but I can revisit this.
Now that I've nailed the deleting/logging out during the actual test though, the size of this file can be drastically reduced with no impact on the test - I just have to rerun the model generator for a smaller output
packages/k6-generator/src/index.js
Outdated
| const methods = require(`${__dirname}${methodsPath.slice(methodsPath.indexOf('/'))}`); | ||
|
|
||
| const newFile = await new StringPrompt({ | ||
| initial: 'tests/k6/scripts/alpha.js', |
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.
Should we default this to something from the input file? If the input file is expressTemplate.json, we can default the filename to something like expressTemplate.k6.js
packages/k6-generator/src/index.js
Outdated
| let methodUrl = Object.keys(methods.routes)[i]; | ||
|
|
||
| for (let j = 0; j < methods.routes[methodUrl].length; j++) { | ||
| const current = methods.routes[methodUrl][j]; |
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 and other places you can just do:
const { path, uniquePayload } = methods.routes[methodUrl][j];
packages/k6-generator/src/index.js
Outdated
| } | ||
|
|
||
| if (!uniqueObj) { | ||
| uniqueObj = '""'; |
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.
What is this for?
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 because replace-in-file doesn't keep the first set of quotes - so when there was no unique object to define, I would end up with something like uniqueObj = ; which would give me an error
packages/k6-generator/src/index.js
Outdated
| let methodUrl = Object.keys(methods.routes)[i]; | ||
|
|
||
| for (let j = 0; j < methods.routes[methodUrl].length; j++) { | ||
| const current = methods.routes[methodUrl][j]; |
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.
const { tag } = methods.routes[methodUrl][j];
packages/k6-generator/src/index.js
Outdated
| writeVuObj = `let vuObj = ${JSON.stringify(vuObj)};\n\n`; | ||
|
|
||
| // PARSE THROUGH ALL ROUTES AND ADD TO MAIN CONTENT - WITHIN DEFAULT FUNCTION | ||
| const baseUrl = methods['baseUrl']; |
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.
const { baseUrl } = methods;
packages/k6-generator/src/index.js
Outdated
| let fullPath; | ||
|
|
||
| for (let j = 0; j < methods.routes[methodUrl].length; j++) { | ||
| let current = methods.routes[methodUrl][j]; |
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.
Same as above.
packages/k6-generator/src/index.js
Outdated
| customImport = `const SLEEP_DURATION = ${methods['sleep']}\nconst uniqueData = JSON.parse(open('${uniqueFile}'))`; | ||
| uniqueObj = `'${uniqueFile.slice(uniqueFile.lastIndexOf('/') + 1, -5)}'`; | ||
| } | ||
| if (!customImport) { |
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.
I would do something like this for customImport.
customImport = uniquePayload ? `const SLEEP_DURATION = ${methods['sleep']}\nconst uniqueData = JSON.parse(open('${uniqueFile}')) : `const SLEEP_DURATION = ${methods['sleep']}`
Also, I would try to move the const SLEEP_DURATION to the template. And only set the value of it from this generate file.
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.
I couldn't do the exact code example you gave for custom import because of where it was in the code, but I did refactor to something that looks cleaner! And sleep duration is also a separate prompt to replace a value in the template now
packages/k6-generator/src/index.js
Outdated
| payload = []; | ||
| tagName = '${tag}Res';`; | ||
|
|
||
| if (custom) { |
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.
What does custom do?
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 custom property indicates if there is something dynamic in the path, for example a delete path requiring an ${id}. I parse the full path differently in this case
packages/k6-generator/src/index.js
Outdated
| case 'createUser': | ||
| case 'login': | ||
| case 'logout': | ||
| case 'post': |
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.
If you want to get fancy, a lot of this can probably be put into a method template file then find and replace similar to what you are doing with the base k6 one.
- prompt for sleep - initial new file name upgraded - more unique data to use
- generated report has dynamic name and path - docs update - general clean up
- routes can go in any logical order - summary prompt upgrade
- auth added on login and set to null on logout
- no more floating `false;` - setNull property to remove id and token - docs update
- less unique data needed - now we'll need as many unique items as there are simultaneous VU's
- update to account for zero indexing
- https://k6.io/docs/examples/data-parameterization/ - use of Shared array to diminish memory issue
- moved unique/user.json and adjusted checks - renamed summary
- use path.resolve to avoid relative pathing issues - rename 'path' in methods file to fix naming overlap
No description provided.