Skip to content

Commit 69600d9

Browse files
committed
Improve defaultOptions
1 parent d29f348 commit 69600d9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

k6/lib/util.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,36 @@ const envToBoolean = (envVar) => {
66
return !!value && ['true', '1', 'yes'].includes(value.toLowerCase());
77
};
88

9-
/** @type {(env?: { isBrowser?: boolean, isDebug?: boolean }) => import('k6/options').Options} */
10-
export const defaultOptions = ({ isBrowser = false, isDebug = envToBoolean('DEBUG_K6') } = {}) => {
9+
/**
10+
* @param {boolean} [inScenario=isBrowser] Is this used as `scenarios: { <scenarioName>: defaultOptions(...) }`?
11+
* @param {boolean} [isBrowser=false] Is this a browser test?
12+
* @param {boolean} [isDebug=env.DEBUG_K6] Are we running in debug mode?
13+
* @return {import('k6/options').Options}
14+
* */
15+
export const defaultOptions = ({
16+
isBrowser = false,
17+
isDebug = envToBoolean('DEBUG_K6'),
18+
// Browser tests options can only be set inside `scenarios`
19+
// https://grafana.com/docs/k6/latest/using-k6-browser/
20+
inScenario = isBrowser,
21+
} = {}) => {
1122
const baseOptions = isDebug
1223
? {
1324
vus: 1,
1425
iterations: 1,
15-
httpDebug: isBrowser ? undefined : 'full',
26+
httpDebug: inScenario ? undefined : 'full',
1627
}
1728
: {
1829
vus: 10,
1930
duration: '30s',
2031
};
32+
if (inScenario) {
33+
// See https://github.com/grafana/k6-learn/blob/main/Modules/III-k6-Intermediate/08-Setting-load-profiles-with-executors.md
34+
baseOptions.executor = isDebug ? 'shared-iterations' : 'constant-vus';
35+
}
2136
return isBrowser
2237
? {
2338
...baseOptions,
24-
// See https://github.com/grafana/k6-learn/blob/main/Modules/III-k6-Intermediate/08-Setting-load-profiles-with-executors.md
25-
executor: isDebug ? 'shared-iterations' : 'constant-vus',
2639
options: {
2740
browser: {
2841
type: 'chromium',

0 commit comments

Comments
 (0)