Skip to content

Commit 7d28de9

Browse files
author
Aviv Keller
authored
benchmark: add test-reporters
PR-URL: nodejs#55757 Refs: nodejs#55723 Reviewed-By: Pietro Marchini <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Raz Luvaton <[email protected]>
1 parent def4c28 commit 7d28de9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { test } = require('node:test');
2+
3+
test('should pass', () => {});
4+
test('should fail', () => { throw new Error('fail'); });
5+
test('should skip', { skip: true }, () => {});
6+
test('parent', (t) => {
7+
t.test('should fail', () => { throw new Error('fail'); });
8+
t.test('should pass but parent fail', (t, done) => {
9+
setImmediate(done);
10+
});
11+
});
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { run } = require('node:test');
5+
const reporters = require('node:test/reporters');
6+
const { Readable } = require('node:stream');
7+
const assert = require('node:assert');
8+
9+
const bench = common.createBenchmark(main, {
10+
n: [1e4],
11+
reporter: Object.keys(reporters),
12+
});
13+
14+
// No need to run this for every benchmark,
15+
// it should always be the same data.
16+
const stream = run({
17+
files: ['../fixtures/basic-test-runner.js'],
18+
});
19+
let testResults;
20+
21+
async function main({ n, reporter: r }) {
22+
testResults ??= await stream.toArray();
23+
24+
// Create readable streams for each iteration
25+
const readables = Array.from({ length: n }, () => Readable.from(testResults));
26+
27+
// Get the selected reporter
28+
const reporter = reporters[r];
29+
30+
bench.start();
31+
32+
let noDead;
33+
for (const readable of readables) {
34+
// Process each readable stream through the reporter
35+
noDead = await readable.compose(reporter).toArray();
36+
}
37+
38+
bench.end(n);
39+
40+
assert.ok(noDead);
41+
}

0 commit comments

Comments
 (0)