解決策
- tsconfig.jsonの
noEmitOrError
をfalseにする - 参考1:https://github.com/kulshekhar/ts-jest/issues/4246
- 参考2:https://github.com/kulshekhar/ts-jest/issues/4207
背景
jestを実行したら以下のエラーが出力された
> src@1.0.0 test
> jest ./tests/sample.test.ts
FAIL tests/sample.test.ts
● Test suite failed to run
Unable to process '/home/dev1/src/backEnd/tests/sample.test.ts', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform /home/dev1/src/backEnd/tests/sample.test.ts
at TsCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:170:27)
at TsJestCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:14:39)
at TsJestTransformer.processWithTs (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:255:37)
at TsJestTransformer.process (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:184:24)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)
~ 省略 ~
エラーメッセージは
1. プロセスが使えない
Unable to process '/home/dev1/src/backEnd/tests/sample.test.ts',
2. tsconfig.jsonのoutDirに問題あり
please make sure that
outDir
in your tsconfig is neither''
or'.'
.
3. transformIgnorePatternsを設定して
You can also configure Jest config option
transformIgnorePatterns
to informts-jest
to transform /home/dev1/src/backEnd/tests/sample.test.ts
の3点
しかし、tsconfig.jsonのoutdirは./dist
、transformIgnorePatternsにはnode_modules
をそれぞれ記載済みだった。そのため、メッセージ以外の箇所にエラー原因があると推察し調査を実施した
調査結果
https://github.com/kulshekhar/ts-jest/issues/2407
様々なサイトを確認し、このissueの通りtsconfig.jsonのnoEmitOrErrorをfalseにしたらjestが実行できた
> src@1.0.0 test
> jest ./tests/sample.test.ts
PASS tests/sample.test.ts (7.583 s)
✓ test (5 ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 8.747 s
Ran all test suites matching /.\/tests\/sample.test.ts/i.
//動けばいい
it('test', () => {
expect(1).toBe(1);
});
最後に
備忘録として残すのが優先のため、原因調査は気が向いたら行う