vitest-dev / vitest-dev/vitest
Following documentation, regarding a tip about `@ts-expect-error`, I cannot make tests behave as I would expect from the documentation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
There's a "tip" over at https://vitest.dev/guide/testing-types.html#run-typechecking, saying:
When using @ts-expect-error syntax, you might want to make sure that you didn't make a typo. You can do that by including your type files in test.include config option, so Vitest will also actually run these tests and fail with ReferenceError.
After adjusting the test.include array in vitest.config.ts, I cannot make all my tests work.
There are 3 test files to present the issue:
- test/repro-control.test.ts
- this is a non-type test, to make sure normal tests still report issues
- test/repro-legit-fail.test-d.ts
- this is a legitimate type issue, Vite type testing should report this
- test/repro-typo-fail.test-d.ts
- this is the mentioned "typo" issue, according to the tip Vite should report this as producing a
ReferenceError
- this is the mentioned "typo" issue, according to the tip Vite should report this as producing a
There are 2 npm scripts
npm run test- this is what I believe I should write, utilizing
--typecheck, after reading the docs
- this is what I believe I should write, utilizing
npm run test-no-typecheck- but to make sure the issue is not the
--typecheckflag, there's also this script
- but to make sure the issue is not the
Upon running npm run test, the results are:
- ❌ (FAIL) test/repro-control.test.ts
- ❌ (FAIL) test/repro-legit-fail.test-d.ts
- ✅ (PASS) test/repro-typo-fail.test-d.ts
Upon running npm run test-no-typecheck, the results are:
- ❌ (FAIL) test/repro-control.test.ts
- ✅ (PASS) test/repro-legit-fail.test-d.ts
- ❌ (FAIL) test/repro-typo-fail.test-d.ts
What I would expect, is for at least one of the npm scripts to result in every test failing.
Reproduction
https://github.com/danwithabox/issue_vitest_vitest-dev_5604
System Info
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 37.14 GB / 63.93 GB
Binaries:
Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
npm: 10.3.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 124.0.6367.60
Edge: Chromium (123.0.2420.97)
Internet Explorer: 11.0.22621.1
npmPackages:
vitest: ^1.5.0 => 1.5.0
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the testing-types documentation tip and the linked reproduction repository. Run npm run test and npm run test-no-typecheck, then inspect test/repro-control.test.ts, test/repro-legit-fail.test-d.ts, and test/repro-typo-fail.test-d.ts. Done means the documented configuration and command produce the expected failures, or the documentation clearly explains the differing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100