feat: rename invariant to assert and hide in stacktrace (#442) · tinylibs/tinybench@7df7e41

@@ -14,8 +14,8 @@ import type {

14141515

import { BenchEvent } from './event'

1616

import {

17+

assert,

1718

getStatisticsSorted,

18-

invariant,

1919

isFnAsyncResource,

2020

isPromiseLike,

2121

isValidSamples,

@@ -156,7 +156,7 @@ export class Task extends EventTarget {

156156157157

for (const hookName of hookNames) {

158158

if (this.#fnOpts[hookName] != null) {

159-

invariant(

159+

assert(

160160

typeof this.#fnOpts[hookName] === 'function',

161161

`'${hookName}' must be a function if provided`

162162

)

@@ -229,15 +229,15 @@ export class Task extends EventTarget {

229229

return this

230230

}

231231232-

invariant(

232+

assert(

233233

this.#bench.concurrency === null,

234234

'Cannot use `concurrency` option when using `runSync`'

235235

)

236236

this.#result = startedTaskResult

237237

this.dispatchEvent(new BenchEvent('start', this))

238238239239

const 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

)

250250251251

const 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 {

289289

this.dispatchEvent(new BenchEvent('warmup', this))

290290291291

const 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

)

302302303303

const 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 {

404404

if (this.#fnOpts.beforeAll) {

405405

try {

406406

const 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 {

423423

try {

424424

if (this.#fnOpts.beforeEach) {

425425

const 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 {

437437

if (this.#fnOpts.afterEach) {

438438

const 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 {

459459

if (this.#fnOpts.afterAll) {

460460

try {

461461

const 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 {

500500

const fnResult = this.#fn.call(this)

501501

let taskTime = this.#bench.now() - taskStart

502502503-

invariant(

503+

assert(

504504

!isPromiseLike(fnResult),

505505

'task function must be sync when using `runSync()`'

506506

)