Skip to content

Commit

Permalink
benchmark: add test-reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
avivkeller committed Nov 7, 2024
1 parent f38cefa commit afd583e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions benchmark/fixtures/basic-test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { test } = require('node:test');

test('should pass', () => {});
test('should fail', () => { throw new Error('fail'); });
test('should skip', { skip: true }, () => {});
test('parent', (t) => {
t.test('should fail', () => { throw new Error('fail'); });
t.test('should pass but parent fail', (t, done) => {
setImmediate(done);
});
});
39 changes: 39 additions & 0 deletions benchmark/test_runner/test-reporters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const common = require('../common');
const { run } = require('node:test');
const reporters = require('node:test/reporters');
const { Readable } = require('node:stream');
const assert = require('node:assert');

// Set up the benchmark
const bench = common.createBenchmark(main, {
n: [1e4],
reporter: Object.keys(reporters),
});

// Run the test and get the stream of results
const stream = run({
files: ['../fixtures/basic-test-runner.js']
});

async function main({ n, reporter: reporterKey }) {
// Prepare test data array from stream
const testResults = await stream.toArray();

// Create readable streams for each iteration
const readables = Array.from({ length: n }, () => Readable.from(testResults));

// Get the selected reporter
const reporter = reporters[reporterKey];

bench.start();

let noDead;
for (const readable of readables) {
// Process each readable stream through the reporter
noDead = await readable.compose(reporter).toArray();
}

bench.end(n);

assert.ok(noDead);
}

0 comments on commit afd583e

Please sign in to comment.