-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Better node:test
reporter and scripts
#5249
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
we could add a linter rule to enforce strict assertion mode by importing |
Using our own test reporter instead. |
28b6bbb
to
6cc85ee
Compare
This was implemented in another PR |
13bf06a
to
d1787df
Compare
I made this PR depend on #5299 because that was preventing me from passing the CI tests |
"test:coverage": "c8 --reporter html --reporter text --all --src src glob --cmd=\"node --import tsx/esm --test\" \"test/**/*.ts\"", | ||
"test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/**/*.ts\"", | ||
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/**/*.ts\"", | ||
"test:github": "node --import tsx/esm --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=@nomicfoundation/hardhat-node-test-reporter --test-reporter-destination=stdout \"test/**/*.ts\"", |
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.
is this line correct?
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.
Not sure what exactly you mean by "this". Can you expand a bit?
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.
yes, sorry. The test:github
script has --test-reporter
and --test-reporter-destination
set twice. It looks like an error.
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.
Oh, no, it's intentional. You can have multiple reporters. In this case, we have the github one to add comments into our PRs, and ours to have an output during our test runs.
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.
🤯
@@ -1,24 +1,22 @@ | |||
import { readFileSync, readdirSync, statSync } from "node:fs"; |
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.
can you explain why we're using the sync versions?
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 doesn't run anything in parallel, so there's no value in using async versions, and it was just complicating a filter()
call. If this were a test run by the actual test runner, I'd use async versions, but it's a top-level single-purpose script.
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.
I understand the call, but I'm uneasy about starting to use node:fs
directly. If we add exceptions, this practice might spread, and we could miss out on good error handling and other checks. Do you think it's worth adding the sync versions to the utils?
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.
Oh, I see. Your question is not about sync
/async
, but I guess you want to know why not the utils package.
That's not possible because it would introduce a circular dependency between projects, and the typescript will complain.
The reporter used to use the utils package, but as soon as I started using the reporter in the utils package, that error appeared.
I think it's better to have a nicer reporter in -utils than to avoid importing fs directly here.
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.
Got it. Makes sense under that scenario 👍
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.
Left a couple questions
This PR introduces a few changes to make working with
node:test
inv-next
easier:spec
to our own test reporter.test:only
npm script, to run the tests with.only
. Just runpnpm test:only
.v-next/
are consistent with each other.glob
from our peer dependencies, asnode:test
has native support for globs in node 22