Files
node/test/parallel/test-bench-cli-backpressure.js
James M Snell dff7a160fe lib: put node:bench behind an --experimental-bench flag
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65920
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-12 08:29:12 +00:00

65 lines
1.8 KiB
JavaScript

'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', '--experimental-bench', '--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);
}