test: split test-bench-cli to try deflaking it

I believe the test-bench-cli flakes were just because the
one file was doing too much and on some architectures was
taking too long to complete. This splits up the file.
At the very least, if there's still a flake in here, the
smaller, more focused files should help narrow it down

Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65919
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This commit is contained in:
James M Snell authored and Antoine du Hamel committed 2026-09-15 10:54:39 +02:00
1 parent b4a7cd3efb
commit 900fae0a24
5 files changed
+547 -421

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const spawnTimeout = common.platformTimeout(30_000);
function spawnNode(args, options = undefined) {
const result = spawnSync(process.execPath, args, {
__proto__: null,
encoding: 'utf8',
timeout: spawnTimeout,
...options,
});
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
return result;
}
function spawnBench(args, options = undefined) {
return spawnNode(['--no-warnings', '--bench', ...args], options);
}
for (const { args, message } of [
{
args: ['--bench-isolation=invalid', 'unused.js'],
message: /invalid value for --bench-isolation/,
},
{
args: ['--bench-samples=0', 'unused.js'],
message: /--bench-samples must be greater than 0/,
},
{
args: ['--bench-warmup=4294967296', 'unused.js'],
message: /--bench-warmup.*out of range/,
},
{
args: ['--bench-samples=2x', 'unused.js'],
message: /invalid value for --bench-samples/,
},
{
args: ['--bench-warmup=abc', 'unused.js'],
message: /invalid value for --bench-warmup/,
},
{
args: ['--bench-name-pattern=[', 'unused.js'],
message: /invalid regular expression/,
},
{
args: ['--eval=1', 'unused.js'],
message: /either --bench or --eval can be used, not both/,
},
{
args: ['--interactive', 'unused.js'],
message: /either --bench or --interactive can be used, not both/,
},
{
args: ['--watch', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--watch-path=.', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--check', 'unused.js'],
message: /either --bench or --check can be used, not both/,
},
{
args: ['--test', 'unused.js'],
message: /either --bench or --test can be used, not both/,
},
]) {
const result = spawnBench(args);
assert.notStrictEqual(result.status, 0);
assert.match(result.stderr, message);
}
@@ -0,0 +1,62 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');
const spawnTimeout = common.platformTimeout(30_000);
function spawnNode(args, options = undefined) {
const result = spawnSync(process.execPath, args, {
__proto__: null,
encoding: 'utf8',
timeout: spawnTimeout,
...options,
});
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
return result;
}
function spawnBench(args, options = undefined) {
return spawnNode(['--no-warnings', '--bench', ...args], options);
}
function parseRecords(result) {
assert.strictEqual(result.stderr, '');
return parseOutput(result.stdout);
}
function parseOutput(output) {
return output.trim().split('\n').map((line) => JSON.parse(line));
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/slow-reporter.cjs')}`,
fixtures.path('bench-runner/many-records.cjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
const report = JSON.parse(result.stdout);
assert.strictEqual(report.samples, 30);
assert.strictEqual(report.stdout,
Array.from({ length: 30 }, (_, i) => `${i}\n`).join(''));
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/acknowledged-records.mjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert.strictEqual(diagnostics.length, 32);
assert(diagnostics.every(
({ data }) => /^acknowledged 10\d{3}$/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, true);
}
+258
View File
@@ -0,0 +1,258 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');
const spawnTimeout = common.platformTimeout(30_000);
function spawnNode(args, options = undefined) {
const result = spawnSync(process.execPath, args, {
__proto__: null,
encoding: 'utf8',
timeout: spawnTimeout,
...options,
});
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
return result;
}
function spawnBench(args, options = undefined) {
return spawnNode(['--no-warnings', '--bench', ...args], options);
}
function parseRecords(result) {
assert.strictEqual(result.stderr, '');
return parseOutput(result.stdout);
}
function parseOutput(output) {
return output.trim().split('\n').map((line) => JSON.parse(line));
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/error.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const failure = records.find(
({ type }) => type === 'bench:complete').data;
assert.deepStrictEqual(failure.params, { kind: 'structured-error' });
assert.strictEqual(failure.error.name, 'Error');
assert.strictEqual(failure.error.message, 'benchmark fixture failed');
assert.strictEqual(failure.error.code, 'ERR_BENCHMARK_FIXTURE');
assert.deepStrictEqual(failure.error.cause, { value: '42' });
assert.match(failure.error.stack, /error\.cjs/);
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-isolation=none',
'--bench-reporter=json',
fixtures.path('bench-runner/throws-null.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic').data;
assert.strictEqual(diagnostic.message, 'null');
assert.strictEqual(records.at(-1).data.success, false);
}
for (const isolation of ['process', 'none']) {
const result = spawnBench([
`--bench-isolation=${isolation}`,
'--bench-reporter=json',
fixtures.path('bench-runner/load-error-after-declaration.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
assert(records.some(({ type, data }) =>
type === 'bench:diagnostic' &&
data.message === 'load failed after declaration'));
const plan = records.find(({ type }) => type === 'bench:plan').data;
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.strictEqual(plan.name, 'declared before load error');
assert.strictEqual(plan.selected, true);
assert.strictEqual(completion.name, plan.name);
assert.strictEqual(completion.error, undefined);
assert.strictEqual(completion.samples.length, 1);
assert.strictEqual(records.at(-1).data.counts.completed, 1);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/recorded-detail.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.strictEqual(completion.samples.length, 1);
const { rate, ...sample } = completion.samples[0];
assert.deepStrictEqual(sample, {
detail: { index: 0, phase: 'measurement', value: '42' },
duration_ns: '4',
operations: 2,
});
assert(Math.abs(rate - 500_000_000) < 1);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/diagnostic.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic').data;
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.deepStrictEqual(diagnostic.message, {
name: 'node:bench:test:diagnostic',
message: { value: '42' },
});
assert.strictEqual(diagnostic.level, 'info');
assert.strictEqual(diagnostic.phase, 'measurement');
assert.strictEqual(diagnostic.index, 0);
assert.strictEqual(diagnostic.detail, undefined);
assert.strictEqual(diagnostic.benchId, completion.benchId);
assert.strictEqual(diagnostic.fileRunId, completion.fileRunId);
assert.strictEqual(completion.error, undefined);
}
for (const { kind, message } of [
{ kind: 'sequence', message: /valid record sequence/ },
{ kind: 'record', message: /not a valid benchmark record/ },
{ kind: 'identity', message: /not a valid benchmark record/ },
{ kind: 'name-path', message: /not a valid benchmark record/ },
{ kind: 'plan', message: /not a valid benchmark plan/ },
{ kind: 'timeout', message: /not a valid benchmark plan/ },
{ kind: 'diagnostic', message: /not a valid benchmark diagnostic/ },
{ kind: 'diagnostic-order', message: /valid lifecycle sequence/ },
{ kind: 'summary', message: /not a valid benchmark summary/ },
]) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/malformed-record.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_MALFORMED_RECORD: kind,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(({ data }) => message.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/malformed-plan-order.mjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(
({ data }) => /valid lifecycle sequence/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-isolation=none',
'--bench-reporter=json',
fixtures.path('bench-runner/a.cjs'),
fixtures.path('bench-runner/exit-code.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(({ type, data }) =>
type === 'bench:diagnostic' && /set exit code/.test(data.message)).data;
assert.strictEqual(diagnostic.entryFile, null);
assert.strictEqual(diagnostic.fileRunId, null);
assert.strictEqual(diagnostic.file, null);
}
for (const { mode, message } of [
{ mode: 'code', message: /failed with exit code 2/ },
{ mode: 'late', message: /failed with exit code 2/ },
...common.isWindows ? [] : [
{ mode: 'signal', message: /failed with signal SIGTERM/ },
],
]) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/abrupt-exit.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_EXIT_MODE: mode,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(({ data }) => message.test(data.message)));
}
for (const mode of ['callback', 'throw']) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/send-error.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_SEND_ERROR: mode,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
const messages = diagnostics.map(({ data }) => data.message).join('');
assert.match(messages, /benchmark send/);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/run.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic');
assert.match(diagnostic.data.message,
/run\(\) cannot be called from a file run with --bench/);
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/exit-code.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
assert(records.some(({ type, data }) =>
type === 'bench:diagnostic' && /set exit code/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
+149
View File
@@ -0,0 +1,149 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fs = require('fs');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const spawnTimeout = common.platformTimeout(30_000);
tmpdir.refresh();
function spawnNode(args, options = undefined) {
const result = spawnSync(process.execPath, args, {
__proto__: null,
encoding: 'utf8',
timeout: spawnTimeout,
...options,
});
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
return result;
}
function spawnBench(args, options = undefined) {
return spawnNode(['--no-warnings', '--bench', ...args], options);
}
function parseRecords(result) {
assert.strictEqual(result.stderr, '');
return parseOutput(result.stdout);
}
function parseOutput(output) {
return output.trim().split('\n').map((line) => JSON.parse(line));
}
for (const { file, status } of [
{ file: 'a.cjs', status: 0 },
{ file: 'error.cjs', status: 1 },
]) {
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/verifying-reporter.cjs')}`,
fixtures.path(`bench-runner/${file}`),
]);
assert.strictEqual(result.status, status);
assert.strictEqual(result.stderr, '');
assert.strictEqual(result.stdout, 'verified\n');
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stderr',
fixtures.path('bench-runner/output.cjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stdout, '');
const records = parseOutput(result.stderr);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert.deepStrictEqual(diagnostics.map(({ data }) => data.stream).sort(), [
'stderr',
'stdout',
]);
assert(diagnostics.some(
({ data }) => data.message === 'benchmark stdout\n'));
assert(diagnostics.some(
({ data }) => data.message === 'benchmark stderr\n'));
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/utf8-output.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const output = records.filter(
({ type, data }) => type === 'bench:diagnostic' &&
data.stream === 'stdout').map(({ data }) => data.message).join('');
assert.strictEqual(output, 'split:\u20ac\n');
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/failing-reporter.cjs')}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /benchmark reporter failed/);
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/destroying-reporter.cjs')}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /benchmark reporter closed the stream/);
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stdout',
'--bench-reporter=data:text/javascript,export default 0',
'--bench-reporter-destination=stderr',
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /is not a valid reporter/);
}
{
const destination = tmpdir.resolve('bench.txt');
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stdout',
'--bench-reporter=spec',
`--bench-reporter-destination=${destination}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 0);
parseRecords(result);
assert.match(fs.readFileSync(destination, 'utf8'),
/^benchmark \| samples \| mean rate/);
}
{
const result = spawnBench([fixtures.path('bench-runner/a.cjs')]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
assert.match(result.stdout, /^benchmark \| samples \| mean rate/);
assert.match(result.stdout, /1 completed, 0 failed, 0 skipped/);
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter=spec',
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr,
/must match the number of specified '.*destination'/);
}
-421
View File
@@ -315,116 +315,6 @@ for (const isolation of ['process', 'none']) {
assert.strictEqual(filtered.skip, 'name pattern');
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/error.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const failure = records.find(
({ type }) => type === 'bench:complete').data;
assert.deepStrictEqual(failure.params, { kind: 'structured-error' });
assert.strictEqual(failure.error.name, 'Error');
assert.strictEqual(failure.error.message, 'benchmark fixture failed');
assert.strictEqual(failure.error.code, 'ERR_BENCHMARK_FIXTURE');
assert.deepStrictEqual(failure.error.cause, { value: '42' });
assert.match(failure.error.stack, /error\.cjs/);
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-isolation=none',
'--bench-reporter=json',
fixtures.path('bench-runner/throws-null.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic').data;
assert.strictEqual(diagnostic.message, 'null');
assert.strictEqual(records.at(-1).data.success, false);
}
for (const isolation of ['process', 'none']) {
const result = spawnBench([
`--bench-isolation=${isolation}`,
'--bench-reporter=json',
fixtures.path('bench-runner/load-error-after-declaration.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
assert(records.some(({ type, data }) =>
type === 'bench:diagnostic' &&
data.message === 'load failed after declaration'));
const plan = records.find(({ type }) => type === 'bench:plan').data;
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.strictEqual(plan.name, 'declared before load error');
assert.strictEqual(plan.selected, true);
assert.strictEqual(completion.name, plan.name);
assert.strictEqual(completion.error, undefined);
assert.strictEqual(completion.samples.length, 1);
assert.strictEqual(records.at(-1).data.counts.completed, 1);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/recorded-detail.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.strictEqual(completion.samples.length, 1);
const { rate, ...sample } = completion.samples[0];
assert.deepStrictEqual(sample, {
detail: { index: 0, phase: 'measurement', value: '42' },
duration_ns: '4',
operations: 2,
});
assert(Math.abs(rate - 500_000_000) < 1);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/diagnostic.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic').data;
const completion = records.find(
({ type }) => type === 'bench:complete').data;
assert.deepStrictEqual(diagnostic.message, {
name: 'node:bench:test:diagnostic',
message: { value: '42' },
});
assert.strictEqual(diagnostic.level, 'info');
assert.strictEqual(diagnostic.phase, 'measurement');
assert.strictEqual(diagnostic.index, 0);
assert.strictEqual(diagnostic.detail, undefined);
assert.strictEqual(diagnostic.benchId, completion.benchId);
assert.strictEqual(diagnostic.fileRunId, completion.fileRunId);
assert.strictEqual(completion.error, undefined);
}
for (const { file, status } of [
{ file: 'a.cjs', status: 0 },
{ file: 'error.cjs', status: 1 },
]) {
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/verifying-reporter.cjs')}`,
fixtures.path(`bench-runner/${file}`),
]);
assert.strictEqual(result.status, status);
assert.strictEqual(result.stderr, '');
assert.strictEqual(result.stdout, 'verified\n');
}
{
const result = spawnBench([
'--require',
@@ -484,108 +374,6 @@ for (const isolation of ['process', 'none']) {
fixtures.path('bench-runner/ipc.cjs'));
}
for (const { kind, message } of [
{ kind: 'sequence', message: /valid record sequence/ },
{ kind: 'record', message: /not a valid benchmark record/ },
{ kind: 'identity', message: /not a valid benchmark record/ },
{ kind: 'name-path', message: /not a valid benchmark record/ },
{ kind: 'plan', message: /not a valid benchmark plan/ },
{ kind: 'timeout', message: /not a valid benchmark plan/ },
{ kind: 'diagnostic', message: /not a valid benchmark diagnostic/ },
{ kind: 'diagnostic-order', message: /valid lifecycle sequence/ },
{ kind: 'summary', message: /not a valid benchmark summary/ },
]) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/malformed-record.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_MALFORMED_RECORD: kind,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(({ data }) => message.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/malformed-plan-order.mjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(
({ data }) => /valid lifecycle sequence/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
'--bench-isolation=none',
'--bench-reporter=json',
fixtures.path('bench-runner/a.cjs'),
fixtures.path('bench-runner/exit-code.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(({ type, data }) =>
type === 'bench:diagnostic' && /set exit code/.test(data.message)).data;
assert.strictEqual(diagnostic.entryFile, null);
assert.strictEqual(diagnostic.fileRunId, null);
assert.strictEqual(diagnostic.file, null);
}
for (const { mode, message } of [
{ mode: 'code', message: /failed with exit code 2/ },
{ mode: 'late', message: /failed with exit code 2/ },
...common.isWindows ? [] : [
{ mode: 'signal', message: /failed with signal SIGTERM/ },
],
]) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/abrupt-exit.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_EXIT_MODE: mode,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert(diagnostics.some(({ data }) => message.test(data.message)));
}
for (const mode of ['callback', 'throw']) {
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/send-error.cjs'),
], {
env: {
__proto__: null,
...process.env,
NODE_BENCH_SEND_ERROR: mode,
},
});
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
const messages = diagnostics.map(({ data }) => data.message).join('');
assert.match(messages, /benchmark send/);
}
{
const result = spawnBench([
'--bench-reporter=json',
@@ -616,125 +404,6 @@ if (common.hasInspector) {
assert.strictEqual(completion.params.inspectPort, '--inspect-port=0');
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stderr',
fixtures.path('bench-runner/output.cjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stdout, '');
const records = parseOutput(result.stderr);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert.deepStrictEqual(diagnostics.map(({ data }) => data.stream).sort(), [
'stderr',
'stdout',
]);
assert(diagnostics.some(
({ data }) => data.message === 'benchmark stdout\n'));
assert(diagnostics.some(
({ data }) => data.message === 'benchmark stderr\n'));
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/utf8-output.cjs'),
]);
assert.strictEqual(result.status, 0);
const records = parseRecords(result);
const output = records.filter(
({ type, data }) => type === 'bench:diagnostic' &&
data.stream === 'stdout').map(({ data }) => data.message).join('');
assert.strictEqual(output, 'split:\u20ac\n');
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/run.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
const diagnostic = records.find(
({ type }) => type === 'bench:diagnostic');
assert.match(diagnostic.data.message,
/run\(\) cannot be called from a file run with --bench/);
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/failing-reporter.cjs')}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /benchmark reporter failed/);
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/slow-reporter.cjs')}`,
fixtures.path('bench-runner/many-records.cjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
const report = JSON.parse(result.stdout);
assert.strictEqual(report.samples, 30);
assert.strictEqual(report.stdout,
Array.from({ length: 30 }, (_, i) => `${i}\n`).join(''));
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/acknowledged-records.mjs'),
]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
const records = parseRecords(result);
const diagnostics = records.filter(
({ type }) => type === 'bench:diagnostic');
assert.strictEqual(diagnostics.length, 32);
assert(diagnostics.every(
({ data }) => /^acknowledged 10\d{3}$/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, true);
}
{
const result = spawnBench([
`--bench-reporter=${fixtures.fileURL('bench-runner/destroying-reporter.cjs')}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /benchmark reporter closed the stream/);
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stdout',
'--bench-reporter=data:text/javascript,export default 0',
'--bench-reporter-destination=stderr',
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /is not a valid reporter/);
}
{
const result = spawnBench([
'--bench-reporter=json',
fixtures.path('bench-runner/exit-code.cjs'),
]);
assert.strictEqual(result.status, 1);
const records = parseRecords(result);
assert(records.some(({ type, data }) =>
type === 'bench:diagnostic' && /set exit code/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, false);
}
{
const result = spawnNode([
'--no-warnings',
@@ -746,93 +415,3 @@ if (common.hasInspector) {
assert.strictEqual(records.find(
({ type }) => type === 'bench:complete').data.samples.length, 1);
}
{
const destination = tmpdir.resolve('bench.txt');
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter-destination=stdout',
'--bench-reporter=spec',
`--bench-reporter-destination=${destination}`,
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 0);
parseRecords(result);
assert.match(fs.readFileSync(destination, 'utf8'),
/^benchmark \| samples \| mean rate/);
}
{
const result = spawnBench([fixtures.path('bench-runner/a.cjs')]);
assert.strictEqual(result.status, 0);
assert.strictEqual(result.stderr, '');
assert.match(result.stdout, /^benchmark \| samples \| mean rate/);
assert.match(result.stdout, /1 completed, 0 failed, 0 skipped/);
}
{
const result = spawnBench([
'--bench-reporter=json',
'--bench-reporter=spec',
fixtures.path('bench-runner/a.cjs'),
]);
assert.strictEqual(result.status, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr,
/must match the number of specified '.*destination'/);
}
for (const { args, message } of [
{
args: ['--bench-isolation=invalid', 'unused.js'],
message: /invalid value for --bench-isolation/,
},
{
args: ['--bench-samples=0', 'unused.js'],
message: /--bench-samples must be greater than 0/,
},
{
args: ['--bench-warmup=4294967296', 'unused.js'],
message: /--bench-warmup.*out of range/,
},
{
args: ['--bench-samples=2x', 'unused.js'],
message: /invalid value for --bench-samples/,
},
{
args: ['--bench-warmup=abc', 'unused.js'],
message: /invalid value for --bench-warmup/,
},
{
args: ['--bench-name-pattern=[', 'unused.js'],
message: /invalid regular expression/,
},
{
args: ['--eval=1', 'unused.js'],
message: /either --bench or --eval can be used, not both/,
},
{
args: ['--interactive', 'unused.js'],
message: /either --bench or --interactive can be used, not both/,
},
{
args: ['--watch', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--watch-path=.', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--check', 'unused.js'],
message: /either --bench or --check can be used, not both/,
},
{
args: ['--test', 'unused.js'],
message: /either --bench or --test can be used, not both/,
},
]) {
const result = spawnBench(args);
assert.notStrictEqual(result.status, 0);
assert.match(result.stderr, message);
}