|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const { finished } = require('node:stream/promises'); |
| 5 | +const reporter = require('../fixtures/empty-test-reporter'); |
| 6 | +const { it } = require('node:test'); |
| 7 | + |
| 8 | +const bench = common.createBenchmark(main, { |
| 9 | + n: [10000], |
| 10 | + option: [ |
| 11 | + 'none', |
| 12 | + 'skip', |
| 13 | + 'skip-with-message', |
| 14 | + 'skip-method', |
| 15 | + 'skip-method-with-message', |
| 16 | + 'todo', |
| 17 | + 'todo-with-message', |
| 18 | + 'todo-method', |
| 19 | + 'todo-method-with-message', |
| 20 | + ], |
| 21 | +}, { |
| 22 | + // We don't want to test the reporter here. |
| 23 | + flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], |
| 24 | +}); |
| 25 | + |
| 26 | +const noop = () => {}; |
| 27 | + |
| 28 | +const allTests = { |
| 29 | + 'none': (loopAmount) => { |
| 30 | + for (let i = 0; i < loopAmount; i++) { |
| 31 | + it(`${i}`, noop); |
| 32 | + } |
| 33 | + |
| 34 | + return finished(reporter); |
| 35 | + }, |
| 36 | + 'skip': (loopAmount) => { |
| 37 | + for (let i = 0; i < loopAmount; i++) { |
| 38 | + it(`${i}`, { skip: true }, () => { |
| 39 | + throw new Error('This test should not run.'); |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + return finished(reporter); |
| 44 | + }, |
| 45 | + 'skip-with-message': (loopAmount) => { |
| 46 | + for (let i = 0; i < loopAmount; i++) { |
| 47 | + it(`${i}`, { skip: 'skip reason' }, () => { |
| 48 | + throw new Error('This test should not run.'); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + return finished(reporter); |
| 53 | + }, |
| 54 | + 'skip-method': (loopAmount) => { |
| 55 | + for (let i = 0; i < loopAmount; i++) { |
| 56 | + it(`${i}`, (t) => { |
| 57 | + t.skip(); |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + return finished(reporter); |
| 62 | + }, |
| 63 | + 'skip-method-with-message': (loopAmount) => { |
| 64 | + for (let i = 0; i < loopAmount; i++) { |
| 65 | + it(`${i}`, (t) => { |
| 66 | + t.skip('skip reason'); |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + return finished(reporter); |
| 71 | + }, |
| 72 | + 'todo': (loopAmount) => { |
| 73 | + for (let i = 0; i < loopAmount; i++) { |
| 74 | + it(`${i}`, { todo: true }, noop); |
| 75 | + } |
| 76 | + |
| 77 | + return finished(reporter); |
| 78 | + }, |
| 79 | + 'todo-with-message': (loopAmount) => { |
| 80 | + for (let i = 0; i < loopAmount; i++) { |
| 81 | + it(`${i}`, { todo: 'todo reason' }, noop); |
| 82 | + } |
| 83 | + |
| 84 | + return finished(reporter); |
| 85 | + }, |
| 86 | + 'todo-method': (loopAmount) => { |
| 87 | + for (let i = 0; i < loopAmount; i++) { |
| 88 | + it(`${i}`, (t) => { |
| 89 | + t.todo(); |
| 90 | + }); |
| 91 | + } |
| 92 | + |
| 93 | + return finished(reporter); |
| 94 | + }, |
| 95 | + 'todo-method-with-message': (loopAmount) => { |
| 96 | + for (let i = 0; i < loopAmount; i++) { |
| 97 | + it(`${i}`, (t) => { |
| 98 | + t.todo('todo reason'); |
| 99 | + }); |
| 100 | + } |
| 101 | + |
| 102 | + return finished(reporter); |
| 103 | + }, |
| 104 | +}; |
| 105 | + |
| 106 | +function main({ n, option }) { |
| 107 | + const runOption = allTests[option]; |
| 108 | + |
| 109 | + bench.start(); |
| 110 | + |
| 111 | + runOption(n).then(() => { |
| 112 | + bench.end(n); |
| 113 | + }); |
| 114 | +} |
0 commit comments