Skip to content

Commit 412e4a8

Browse files
committed
Switch streaming back to browser tests
1 parent eadccd4 commit 412e4a8

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ overrides:
9393
"import/no-unresolved":
9494
- error
9595
- { ignore: ["k6.*"] }
96+
no-use-before-define:
97+
- error
98+
# We want to allow function.name in options, and place them at the top of the file
99+
- { functions: false }

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ The benchmarking scripts are in `k6` directory, so you can run, for example:
300300
```sh
301301
k6 run k6/root.js
302302
```
303-
to exercise the main page of the dummy app, or `k6/streaming.js` for the streaming page.
303+
to exercise the main page of the dummy app.
304+
305+
For browser tests like `k6/streaming.js`, it's recommended to include `K6_BROWSER_LOG=fatal` for actual measurement after verifying the tests work.
306+
It avoids unnecessary overhead from outputting console messages.
304307
305308
For significant changes, please make sure to run all benchmarks before and after, and include the results in the PR.
306309
Later they will be added to CI, if we can make sure the results there are stable enough.

k6/streaming.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
import { check } from 'k6';
2-
import http from 'k6/http';
2+
import { browser } from 'k6/browser';
33
import { defaultOptions, url } from './lib/util.js';
44

5-
export const options = defaultOptions();
5+
const streamingUrl = url('stream_async_components?delay=5');
66

7-
export default () => {
8-
const streamingUrl = url('stream_async_components?delay=5');
9-
check(http.get(streamingUrl), {
10-
'status was 200': (res) => res.status === 200,
11-
'has all comments': (res) => {
12-
const body = res.html().text();
13-
const commentIds = [1, 2, 3, 4];
14-
const hasAllComments = commentIds.every((commentId) => body.includes(`Comment ${commentId}`));
15-
const hasFailedRequests = !!body.match(/Request to .+ failed/i);
16-
return hasAllComments && !hasFailedRequests;
17-
},
18-
});
7+
export const options = {
8+
scenarios: {
9+
browser: defaultOptions({ isBrowser: true }),
10+
},
11+
};
12+
13+
export default async () => {
14+
const page = await browser.newPage();
15+
try {
16+
const response = await page.goto(streamingUrl);
17+
check(response, {
18+
'status was 200': (res) => res.status() === 200,
19+
});
20+
await page.waitForFunction(() => !document.body.textContent.includes('Loading'), {
21+
// in milliseconds
22+
timeout: 5000,
23+
});
24+
check(await page.locator('html').textContent(), {
25+
'has all comments': (text) => {
26+
// can't define commentIds as a constant outside, this runs in browser context
27+
const commentIds = [1, 2, 3, 4];
28+
return commentIds.every((id) => text.includes(`Comment ${id}`));
29+
},
30+
});
31+
} finally {
32+
await page.close();
33+
}
1934
};

0 commit comments

Comments
 (0)