Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: simplify util types, add attest unit/bench examples #210
refactor: simplify util types, add attest unit/bench examples #210
Changes from all commits
ce7d842
c6422e1
3530fe2
f82f737
a4d7e27
e0419be
4f6fbcd
0002c92
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives you an idea of the general structure for a set of
attest
benchmarks.It will allow you to chain
.types()
off thebench
call. You just run the file as normal using something likets-node
,tsx
etc. (hopefully bun but they may still have some issues with source maps).When it executes for the first time or with no snapped value, it will populate the inline snapshot with a summary of the instantiation count.
Subsequent runs will summarize the delta between the current result and the snapped one.
If you want to configure it to fail above a certain threshold e.g. for CI, there are two settings you can pass through the CLI:
--benchPercentThreshold
(defaults to20
)--benchErrorOnThresholdExceeded
(defaults to false)If you set --benchErrorOnThresholdExceeded to true like
tsx src/utils.bench.ts ----benchErrorOnThresholdExceeded
, the process should return a non-zero exit code if any of the benchmarks have increased by an amount more than--benchPercentThreshold
.Note those flags haven't really been tested extensively, but figured I'd mentioned then since @tmm expressed an interest in CI integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax closely parallels the type assertions vitest allows, with the benefit of being able to run them conditionally based on your environment since the assertion is still executed as normal at runtime.
Another significant benefit is that you can write these assertions alongside or in combination with your value assertions, so you don't need to have separate
.d.ts
tests.This can be especially helpful when testing types and values that parallel one another, e.g. via APIs like
.throwsAndHasTypeError
It also allows type/value snapshotting, object literal snapshots etc. (see the admittedly underdocumented README).