bench-node
Advanced tools
Comparing version 0.0.4-beta.2 to 0.0.4-beta.3
@@ -55,5 +55,11 @@ const { reportConsoleBench } = require('./report'); | ||
validateObject(options, 'options'); | ||
if (options?.reporter) { | ||
validateFunction(options.reporter, 'reporter'); | ||
if (options?.reporter !== undefined) { | ||
if (options?.reporter !== false && options?.reporter !== null) { | ||
validateFunction(options.reporter, 'reporter'); | ||
} | ||
this.#reporter = options.reporter; | ||
} else { | ||
this.#reporter = reportConsoleBench; | ||
} | ||
if (options?.plugins) { | ||
@@ -64,3 +70,2 @@ validateArray(options.plugins, 'plugin'); | ||
this.#plugins = options?.plugins || [new V8NeverOptimizePlugin()]; | ||
this.#reporter = options?.reporter || reportConsoleBench; | ||
} | ||
@@ -107,3 +112,5 @@ | ||
results[i] = result; | ||
this.#reporter(benchmark, result); | ||
if (this.#reporter) { | ||
this.#reporter(benchmark, result); | ||
} | ||
} | ||
@@ -110,0 +117,0 @@ return results; |
{ | ||
"name": "bench-node", | ||
"version": "0.0.4-beta.2", | ||
"version": "0.0.4-beta.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -82,2 +82,9 @@ # `bench-node` | ||
If you don't want results to be printed to the console, `false` and `null` can be used | ||
```js | ||
const { Suite } = require('bench-node'); | ||
const suite = new Suite({ reporter: false }); | ||
``` | ||
### `suite.add(name[, options], fn)` | ||
@@ -84,0 +91,0 @@ |
@@ -34,2 +34,9 @@ const { Suite } = require('../lib/index'); | ||
it('reporter can be false or null', () => { | ||
[false, null].forEach((r) => { | ||
// doesNotThrow | ||
new Suite({ reporter: r }); | ||
}); | ||
}); | ||
describe('suite.add', () => { | ||
@@ -36,0 +43,0 @@ const bench = new Suite({ reporter: noop }); |
61892
1501
242