[Bug]: Calling `require` from test file suppresses TS compliation errors
GravlLift opened this issue · comments
Version
29.0.5
Steps to reproduce
- Clone my reproduction repository from https://github.com/GravlLift/ts-jest-bug-repro
npm i
npx jest
Expected behavior
If the code in index.test.ts
is replaced with the commented code in that file, you can see the expected typescript compilation error printed to console:
src/index.ts:1:39 - error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1 import packageJson from './test.json' assert { type: 'json' };
Actual behavior
Console prints failing tests with no explanation:
FAIL src/__tests__/index.test.ts
swagger
× should demonstrate issue (16 ms)
● swagger › should demonstrate issue
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.934 s, estimated 2 s
Ran all test suites.
Debug log
Relevant logs:
{
"context": {
"call": null,
"logLevel": 20,
"namespace": "hoist-jest",
"package": "ts-jest",
"version": "28.0.8"
},
"message": "visitSourceFileNode(): hoist jest",
"sequence": 4844,
"time": "2023-03-10T16:39:20.440Z"
},
{
"context": {
"fileName": "<obfuscated>\\src\\swagger\\versionInfo.ts",
"logLevel": 20,
"namespace": "ts-compiler",
"package": "ts-jest",
"version": "28.0.8"
},
"message": "_doTypeChecking(): computing diagnostics using language service",
"sequence": 4845,
"time": "2023-03-10T16:39:20.455Z"
},
{
"context": {
"diagnosticCodes": [
2821
],
"diagnosticText": "\u001B[96msrc/swagger/versionInfo.ts\u001B[0m:\u001B[93m5\u001B[0m:\u001B[93m53\u001B[0m - \u001B[91merror\u001B[0m\u001B[90m TS2821: \u001B[0mImport assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.\n\n\u001B[7m5\u001B[0m import packageJson from \"../../../npm/package.json\" assert { type: \"json\" }\n\u001B[7m \u001B[0m \u001B[91m ~~~~~~~~~~~~~~~~~~~~~~~\u001B[0m\n",
"logLevel": 20,
"namespace": "TSError",
"package": "ts-jest",
"version": "28.0.8"
},
"message": "created new TSError",
"sequence": 4846,
"time": "2023-03-10T16:39:20.457Z"
},
{
"context": {
"logLevel": 20,
"namespace": "ts-jest-transformer",
"package": "ts-jest",
"version": "28.0.8"
},
"message": "created new transformer",
"sequence": 4847,
"time": "2023-03-10T16:39:20.494Z"
}
]
Additional context
I'm not entirely sure why the TS2821 error is occurring here (VS Code and my bundler have no complaints about that line), but regardless, I'd expect any compilation errors to always make it up to the console.
Environment
System:
OS: Windows 10 10.0.22621
CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
Binaries:
Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD