| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dad9548 commit d8acfc4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,51 @@ | |||
| 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 { | ||
| 7 | + after, | ||
| 8 | + afterEach, | ||
| 9 | + before, | ||
| 10 | + beforeEach, | ||
| 11 | + describe, | ||
| 12 | + it, | ||
| 13 | + } = require('node:test'); | ||
| 14 | + | ||
| 15 | + const bench = common.createBenchmark(main, { | ||
| 16 | + n: [1000], | ||
| 17 | + hook: ['before', 'after', 'beforeEach', 'afterEach'], | ||
| 18 | + }, { | ||
| 19 | + // We don't want to test the reporter here. | ||
| 20 | + flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], | ||
| 21 | + }); | ||
| 22 | + | ||
| 23 | + const hookList = { | ||
| 24 | + before: before, | ||
| 25 | + after: after, | ||
| 26 | + beforeEach: beforeEach, | ||
| 27 | + afterEach: afterEach, | ||
| 28 | + }; | ||
| 29 | + | ||
| 30 | + const noop = () => {}; | ||
| 31 | + | ||
| 32 | + function run(loopAmount, hookFn) { | ||
| 33 | + for (let i = 0; i < loopAmount; i++) { | ||
| 34 | + describe(`${i}`, () => { | ||
| 35 | + hookFn(noop); | ||
| 36 | + it(`${i}`, noop); | ||
| 37 | + }); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + return finished(reporter); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + function main(params) { | ||
| 44 | + const hookFn = hookList[params.hook]; | ||
| 45 | + | ||
| 46 | + bench.start(); | ||
| 47 | + | ||
| 48 | + run(params.n, hookFn).then(() => { | ||
| 49 | + bench.end(params.n); | ||
| 50 | + }); | ||
| 51 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,114 @@ | |||
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments