Skip to content

Commit afd583e

Browse files
committed
benchmark: add test-reporters
1 parent f38cefa commit afd583e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 11 additions & 0 deletions
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+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const common = require('../common');
2+
const { run } = require('node:test');
3+
const reporters = require('node:test/reporters');
4+
const { Readable } = require('node:stream');
5+
const assert = require('node:assert');
6+
7+
// Set up the benchmark
8+
const bench = common.createBenchmark(main, {
9+
n: [1e4],
10+
reporter: Object.keys(reporters),
11+
});
12+
13+
// Run the test and get the stream of results
14+
const stream = run({
15+
files: ['../fixtures/basic-test-runner.js']
16+
});
17+
18+
async function main({ n, reporter: reporterKey }) {
19+
// Prepare test data array from stream
20+
const testResults = await stream.toArray();
21+
22+
// Create readable streams for each iteration
23+
const readables = Array.from({ length: n }, () => Readable.from(testResults));
24+
25+
// Get the selected reporter
26+
const reporter = reporters[reporterKey];
27+
28+
bench.start();
29+
30+
let noDead;
31+
for (const readable of readables) {
32+
// Process each readable stream through the reporter
33+
noDead = await readable.compose(reporter).toArray();
34+
}
35+
36+
bench.end(n);
37+
38+
assert.ok(noDead);
39+
}

0 commit comments

Comments
 (0)