mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
The only benchmark covers creating selected and non-selected tests when running with --test-only. The mock timers benchmark covers enabling timer mocks, setTimeout, setInterval, setImmediate, scheduler.wait, AbortSignal.timeout, mocked Date.now(), setTime(), and runAll(). Refs: https://github.com/nodejs/node/issues/55723 Signed-off-by: Luan Muniz <luan@luanmuniz.com.br> PR-URL: https://github.com/nodejs/node/pull/64097 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
40 lines
850 B
JavaScript
40 lines
850 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { finished } = require('node:stream/promises');
|
|
const reporter = require('../fixtures/empty-test-reporter');
|
|
const { test } = require('node:test');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [10000],
|
|
selected: [1],
|
|
}, {
|
|
// We don't want to test the reporter here.
|
|
flags: [
|
|
'--test-reporter=./benchmark/fixtures/empty-test-reporter.js',
|
|
'--test-only',
|
|
],
|
|
});
|
|
|
|
async function run({ n, selected }) {
|
|
for (let i = 0; i < selected; i++) {
|
|
test(`selected-${i}`, { only: true }, () => {});
|
|
}
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
test(`not-selected-${i}`, () => {
|
|
throw new Error(`This test ${i} should not run.`);
|
|
});
|
|
}
|
|
|
|
return finished(reporter);
|
|
}
|
|
|
|
function main(params) {
|
|
bench.start();
|
|
|
|
run(params).then(() => {
|
|
bench.end(params.n);
|
|
});
|
|
}
|