k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Define handleSummary and teardown across multiple scripts

Open MoKhajavi75 opened this issue 10 months ago • 1 comments

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

MoKhajavi75 avatar Apr 16 '24 10:04 MoKhajavi75

It is something we might consider during https://github.com/grafana/k6/issues/1342 implementation

codebien avatar Apr 23 '24 10:04 codebien