mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
benchmark: add test runner hooks and options
Add benchmarks for node:test hooks and test options. The hooks benchmark covers before, after, beforeEach, and afterEach, with a none mode as the baseline. The test options benchmark covers skip and todo behavior. This adds coverage for part of the benchmark/test_runner gaps tracked in the issue. 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/63754 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
1 parent
4b90031534
commit
c8837e1aa3
2 files changed
+165
No files matched your search
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { finished } = require('node:stream/promises');
|
||||
const reporter = require('../fixtures/empty-test-reporter');
|
||||
const {
|
||||
after,
|
||||
afterEach,
|
||||
before,
|
||||
beforeEach,
|
||||
describe,
|
||||
it,
|
||||
} = require('node:test');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1000],
|
||||
hook: ['before', 'after', 'beforeEach', 'afterEach'],
|
||||
}, {
|
||||
// We don't want to test the reporter here.
|
||||
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
|
||||
});
|
||||
|
||||
const hookList = {
|
||||
before: before,
|
||||
after: after,
|
||||
beforeEach: beforeEach,
|
||||
afterEach: afterEach,
|
||||
};
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
function run(loopAmount, hookFn) {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
describe(`${i}`, () => {
|
||||
hookFn(noop);
|
||||
it(`${i}`, noop);
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
}
|
||||
|
||||
function main(params) {
|
||||
const hookFn = hookList[params.hook];
|
||||
|
||||
bench.start();
|
||||
|
||||
run(params.n, hookFn).then(() => {
|
||||
bench.end(params.n);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { finished } = require('node:stream/promises');
|
||||
const reporter = require('../fixtures/empty-test-reporter');
|
||||
const { it } = require('node:test');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [10000],
|
||||
option: [
|
||||
'none',
|
||||
'skip',
|
||||
'skip-with-message',
|
||||
'skip-method',
|
||||
'skip-method-with-message',
|
||||
'todo',
|
||||
'todo-with-message',
|
||||
'todo-method',
|
||||
'todo-method-with-message',
|
||||
],
|
||||
}, {
|
||||
// We don't want to test the reporter here.
|
||||
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
|
||||
});
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
const allTests = {
|
||||
'none': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, noop);
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'skip': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, { skip: true }, () => {
|
||||
throw new Error('This test should not run.');
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'skip-with-message': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, { skip: 'skip reason' }, () => {
|
||||
throw new Error('This test should not run.');
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'skip-method': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, (t) => {
|
||||
t.skip();
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'skip-method-with-message': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, (t) => {
|
||||
t.skip('skip reason');
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'todo': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, { todo: true }, noop);
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'todo-with-message': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, { todo: 'todo reason' }, noop);
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'todo-method': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, (t) => {
|
||||
t.todo();
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
'todo-method-with-message': (loopAmount) => {
|
||||
for (let i = 0; i < loopAmount; i++) {
|
||||
it(`${i}`, (t) => {
|
||||
t.todo('todo reason');
|
||||
});
|
||||
}
|
||||
|
||||
return finished(reporter);
|
||||
},
|
||||
};
|
||||
|
||||
function main({ n, option }) {
|
||||
const runOption = allTests[option];
|
||||
|
||||
bench.start();
|
||||
|
||||
runOption(n).then(() => {
|
||||
bench.end(n);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user