Skip to content

Commit

Permalink
fix: fix error handling in .table()
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
  • Loading branch information
jerome-benoit committed Nov 14, 2024
1 parent c078860 commit 0f417be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"import": "./dist/index.js"
}
},
"files": ["dist/**"],
"files": [
"dist/**"
],
"repository": "tinylibs/tinybench",
"license": "MIT",
"devDependencies": {
Expand All @@ -65,5 +67,9 @@
"typescript": "~5.6.3",
"vitest": "^2.1.5"
},
"keywords": ["benchmark", "tinylibs", "tiny"]
"keywords": [
"benchmark",
"tinylibs",
"tiny"
]
}
2 changes: 0 additions & 2 deletions src/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ export class Bench extends EventTarget {
Error: task.result.error.message,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Stack: task.result.error.stack!,
// eslint-disable-next-line perfectionist/sort-objects
Samples: task.result.latency.samples.length,
}
: (convert?.(task) ?? {
'Task name': task.name,
Expand Down
18 changes: 18 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ test('bench table', async () => {
Samples: expect.any(Number),
},
])

bench.remove('foo')
bench.add('bar', () => {
throw new Error('fake')
})

await bench.run()

expect(bench.table()).toStrictEqual([
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'Task name': expect.any(String),
// eslint-disable-next-line perfectionist/sort-objects, @typescript-eslint/no-unsafe-assignment
Error: expect.any(String),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Stack: expect.any(String),
},
])
})

test('bench task runs and time consistency', async () => {
Expand Down

0 comments on commit 0f417be

Please sign in to comment.