feat: rename invariant to assert and hide in stacktrace (#442) · tinylibs/tinybench@7df7e41
@@ -14,8 +14,8 @@ import type {
14141515import { BenchEvent } from './event'
1616import {
17+assert,
1718getStatisticsSorted,
18-invariant,
1919isFnAsyncResource,
2020isPromiseLike,
2121isValidSamples,
@@ -156,7 +156,7 @@ export class Task extends EventTarget {
156156157157for (const hookName of hookNames) {
158158if (this.#fnOpts[hookName] != null) {
159-invariant(
159+assert(
160160typeof this.#fnOpts[hookName] === 'function',
161161`'${hookName}' must be a function if provided`
162162)
@@ -229,15 +229,15 @@ export class Task extends EventTarget {
229229return this
230230}
231231232-invariant(
232+assert(
233233this.#bench.concurrency === null,
234234'Cannot use `concurrency` option when using `runSync`'
235235)
236236this.#result = startedTaskResult
237237this.dispatchEvent(new BenchEvent('start', this))
238238239239const setupResult = this.#bench.setup(this, 'run')
240-invariant(
240+assert(
241241!isPromiseLike(setupResult),
242242'`setup` function must be sync when using `runSync()`'
243243)
@@ -249,7 +249,7 @@ export class Task extends EventTarget {
249249)
250250251251const teardownResult = this.#bench.teardown(this, 'run')
252-invariant(
252+assert(
253253!isPromiseLike(teardownResult),
254254'`teardown` function must be sync when using `runSync()`'
255255)
@@ -289,7 +289,7 @@ export class Task extends EventTarget {
289289this.dispatchEvent(new BenchEvent('warmup', this))
290290291291const setupResult = this.#bench.setup(this, 'warmup')
292-invariant(
292+assert(
293293!isPromiseLike(setupResult),
294294'`setup` function must be sync when using `runSync()`'
295295)
@@ -301,7 +301,7 @@ export class Task extends EventTarget {
301301)
302302303303const teardownResult = this.#bench.teardown(this, 'warmup')
304-invariant(
304+assert(
305305!isPromiseLike(teardownResult),
306306'`teardown` function must be sync when using `runSync()`'
307307)
@@ -404,7 +404,7 @@ export class Task extends EventTarget {
404404if (this.#fnOpts.beforeAll) {
405405try {
406406const beforeAllResult = this.#fnOpts.beforeAll.call(this, mode)
407-invariant(
407+assert(
408408!isPromiseLike(beforeAllResult),
409409'`beforeAll` function must be sync when using `runSync()`'
410410)
@@ -423,7 +423,7 @@ export class Task extends EventTarget {
423423try {
424424if (this.#fnOpts.beforeEach) {
425425const beforeEachResult = this.#fnOpts.beforeEach.call(this, mode)
426-invariant(
426+assert(
427427!isPromiseLike(beforeEachResult),
428428'`beforeEach` function must be sync when using `runSync()`'
429429)
@@ -436,7 +436,7 @@ export class Task extends EventTarget {
436436} finally {
437437if (this.#fnOpts.afterEach) {
438438const afterEachResult = this.#fnOpts.afterEach.call(this, mode)
439-invariant(
439+assert(
440440!isPromiseLike(afterEachResult),
441441'`afterEach` function must be sync when using `runSync()`'
442442)
@@ -459,7 +459,7 @@ export class Task extends EventTarget {
459459if (this.#fnOpts.afterAll) {
460460try {
461461const afterAllResult = this.#fnOpts.afterAll.call(this, mode)
462-invariant(
462+assert(
463463!isPromiseLike(afterAllResult),
464464'`afterAll` function must be sync when using `runSync()`'
465465)
@@ -500,7 +500,7 @@ export class Task extends EventTarget {
500500const fnResult = this.#fn.call(this)
501501let taskTime = this.#bench.now() - taskStart
502502503-invariant(
503+assert(
504504!isPromiseLike(fnResult),
505505'task function must be sync when using `runSync()`'
506506)