Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add test-reporters #55757

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
41 changes: 41 additions & 0 deletions benchmark/test_runner/test-reporters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

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');

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

// No need to run this for every benchmark,
// it should always be the same data.
const stream = run({
files: ['../fixtures/basic-test-runner.js'],
});
let testResults;

async function main({ n, reporter: r }) {
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[r];

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);
}
Loading