k6
k6 copied to clipboard
Define handleSummary and teardown across multiple scripts
Feature Description
I propose adding global lifecycle functions to k6, specifically a shared setup and teardown that apply to every test file. This would simplify processes like customizing the handleSummary()
function across all tests, enhancing efficiency and consistency in test configurations.
Suggested Solution (optional)
For now, there are some workarounds, like (discussed here):
// file: shared/handleSummary.js
export function handleSummary() {
console.log("Here's your shared 'handleSummary'")
}
// file: script1.js
export {handleSummary} from './shared/handleSummary.js'
export default function () {
console.log("Here's one of your scripts")
}
// file: script2.js
export {handleSummary} from './shared/handleSummary.js'
export default function () {
console.log("Here's another of your scripts")
}
but this requires export in every file and with a huge number of tests, this could be a pain!
Already existing or connected issues / PRs (optional)
No response
It is something we might consider during https://github.com/grafana/k6/issues/1342 implementation