-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: use tsd
instead of forked mlh-tsd
#25
fix: use tsd
instead of forked mlh-tsd
#25
Conversation
"typescript": "^4.4.4" | ||
}, | ||
"peerDependencies": { | ||
"tsd": ">=0.15.0" |
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.
It felt like peerDependencies
is good idea. v0.15
is the minimal version with necessary API.
tsd
assertions, but instead report the number of test filestsd
in favour of forked mlh-tsd
tsd
in favour of forked mlh-tsd
tsd
instead of forked mlh-tsd
I'm not ignoring this btw, I just haven't found the time to sit down and actually think about what I think makes the most sense 😅 |
Sure. This is also messy PR. It has too many ideas in one place. Few already got moved to separate PRs. Cleaning it up. |
Cleaned it up. One focused change and one new test. The only change is the count of passed / failed assertions. For instance, Jest’s test suite now prints: Test Suites: 4 passed, 4 total
Tests: 283 passed, 283 total If this PR would land: Test Suites: 4 passed, 4 total
Tests: 4 passed, 4 total The only lost information is the count of failures. Drafting (not implemented yet). Here is how 2 errors in 1 failed test could look: For my eye, this is more accurate compared with current |
jestjs/jest#11986 is very interesting case. If the test runs on the I was trying to write the test somehow differently, but couldn’t make it work. That seem like the best solution. Funny situation. |
See #41 |
What if there is no need to patch
tsd
? I was trying to improve error message printed by this library and found something interesting.(Long text. I added summary at the bottom.)
Here is a valid
tsd
test (see docs):This test does not include assertions (any of
expectType
,expectError
, etc). Runningtsd
works as expected (two errors reported), butjest-runner-tsd
prints buggy result (no tests were running, but two failed):The same, but with failing lines removed (no tests were running at all):
In a way, the runner does not work in the same way as
tsd
. What is happening?tsd
is using TS compiler to get diagnostics. This is first source of test errors. Next the list of errors is tweaked by passing it through filters oftsd
assertions (for instance,expectError
is silencing errors). The assertions is the second source of test errors.The patched version of
tsd
is counting only thetsd
assertions, but not the work done by TS compiler. The number oftsd
assertions is reported as the total count of tests. In the examples above we see0 total
, because test file has no assertions. Hence, to report the number of assertions as the number of tests is not accurate.Even more –
tsd
does not have a concept of test. I was trying to improve the error message printed by the runner. It would be nice to pass a test title to Jest, but there are no titles. As well as there are no tests intsd
.In general
tsd
works rather similar totsc --noEmit
. It simply checks TypeScript type definitions (or.d.ts
files) by parsing test files (nothing is executed). I think it is better to count test files than assertions. This is very similar tojest-runner-eslint
.It seems to me that
tsd
is not a testing utility, but a typechecker. So it should be treated differently than the current implementation.Apologies for this long text. Hope it explains the problem and motivation. Thanks for reading.
Summary
tsd
instead of forkedmlh-tsd
mlh-tsd
fork is adding just one tiny feature (which made me to write all this text)mlh-tsd
returns a count of assertions (as a count of tests) together with the diagnostics listtsd
is a typechecker and it does not have the concept of a test, hence the implementation of that feature is questionable