Skip to content

Commit 2f3578b

Browse files
committed
Move _util to lib/
1 parent d79e63f commit 2f3578b

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

k6/_util.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

k6/lib/util.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export const url = (path) => `${__ENV.BASE_URL ?? 'http://localhost:3000'}/${path}`;
2+
3+
/** @type {(envVar: string) => boolean} */
4+
const envToBoolean = (envVar) => {
5+
const value = __ENV[envVar];
6+
return !!value && ['true', '1', 'yes'].includes(value.toLowerCase());
7+
};
8+
9+
/** @type {(env?: { isBrowser?: boolean, isDebug?: boolean }) => import('k6/options').Options} */
10+
export const defaultOptions = ({ isBrowser = false, isDebug = envToBoolean('DEBUG_K6') } = {}) => {
11+
const baseOptions = isDebug ?
12+
{
13+
vus: 1,
14+
iterations: 1,
15+
httpDebug: isBrowser ? undefined : 'full',
16+
} :
17+
{
18+
vus: 10,
19+
duration: '30s',
20+
};
21+
return isBrowser ? {
22+
...baseOptions,
23+
executor: 'shared-iterations',
24+
options: {
25+
browser: {
26+
type: 'chromium',
27+
},
28+
},
29+
} : baseOptions;
30+
};

k6/root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { check } from 'k6';
22
import http from 'k6/http';
3-
import { defaultOptions, url } from './_util.js';
3+
import { defaultOptions, url } from './lib/util.js';
44

5-
export const options = defaultOptions(false);
5+
export const options = defaultOptions();
66

77
export default () => {
88
const rootUrl = url('');

k6/streaming.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { check } from 'k6';
22
import http from 'k6/http';
3-
import { defaultOptions, url } from './_util.js';
3+
import { defaultOptions, url } from './lib/util.js';
44

5-
export const options = defaultOptions(false);
5+
export const options = defaultOptions();
66

77
export default () => {
88
const streamingUrl = url('stream_async_components?delay=5');

0 commit comments

Comments
 (0)