当我尝试收集笑话测试的覆盖范围时,出现错误“_genMapping.maybeAddMapping 不是函数”

Gus*_*rio 18 typescript reactjs jestjs ts-jest

几天前我能够运行我的测试并收集它的覆盖范围。(0 , _genMapping.maybeAddMapping) is not a function但是当我今天尝试运行它时,每次测试都会出现错误。仅当我使用覆盖率标志运行时才会发生该错误。

\n

如果我在没有覆盖的情况下跑步,它会按预期工作。

\n
PS C:\\projetos> yarn jest\nyarn run v1.22.17\n$ C:\\projetos\\node_modules\\.bin\\jest\n PASS  src/shared/utils/__tests__/geralUtils.test.ts (14.834 s)\n PASS  src/shared/utils/__tests__/dateUtils.test.ts (15.253 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoUtils.test.ts (5.905 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoParametrosUtils.test.ts (5.19 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoTabelaUtils.test.ts (28.38 s)\n\nTest Suites: 6 passed, 6 total\nTests:       25 passed, 25 total\nSnapshots:   0 total\nTime:        32.256 s\nRan all test suites.\nDone in 40.73s.\n
Run Code Online (Sandbox Code Playgroud)\n

如果我尝试使用“yarn jest --coverage”或“yarn jest --collectCoverage”收集覆盖率,则会收到以下错误:

\n
PS C:\\projetos> yarn jest --collectCoverage\nyarn run v1.22.17\n$ C:\\projetos\\node_modules\\.bin\\jest --collectCoverage\n FAIL  src/shared/utils/__tests__/dateUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\shared\\utils\\dataUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n FAIL  src/shared/utils/__tests__/geralUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\shared\\utils\\geralUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n FAIL  src/features/motorCalculo/__tests__/motorCalculoUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\features\\motorCalculo\\motorCalculoUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n FAIL  src/shared/utils/__tests__/arrayUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\shared\\utils\\arrayUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n FAIL  src/features/motorCalculo/__tests__/motorCalculoParametrosUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\features\\motorCalculo\\parametros\\motorCalculoParametrosUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n FAIL  src/features/motorCalculo/__tests__/motorCalculoTabelaUtils.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    TypeError: C:\\projetos\\src\\features\\motorCalculo\\tabela\\motorCalculoTabelaUtils.tsx: (0 , _genMapping.maybeAddMapping) is not a function\n\n      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)\n\n----------|---------|----------|---------|---------|-------------------\nFile      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n----------|---------|----------|---------|---------|-------------------\nAll files |       0 |        0 |       0 |       0 |\n----------|---------|----------|---------|---------|-------------------\nTest Suites: 6 failed, 6 total\nTests:       0 total\nSnapshots:   0 total\nTime:        27.526 s, estimated 29 s\nRan all test suites.\nerror Command failed with exit code 1.\ninfo Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的 jest.config.ts:

\n
PS C:\\projetos> yarn jest\nyarn run v1.22.17\n$ C:\\projetos\\node_modules\\.bin\\jest\n PASS  src/shared/utils/__tests__/geralUtils.test.ts (14.834 s)\n PASS  src/shared/utils/__tests__/dateUtils.test.ts (15.253 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoUtils.test.ts (5.905 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoParametrosUtils.test.ts (5.19 s)\n PASS  src/features/motorCalculo/__tests__/motorCalculoTabelaUtils.test.ts (28.38 s)\n\nTest Suites: 6 passed, 6 total\nTests:       25 passed, 25 total\nSnapshots:   0 total\nTime:        32.256 s\nRan all test suites.\nDone in 40.73s.\n
Run Code Online (Sandbox Code Playgroud)\n

我在任何地方都找不到有关此错误的任何信息,有人知道会发生什么吗?

\n

Gus*_*rio 33

我不知道为什么会发生这种情况。但删除node_modules和yarn.lock,并再次运行“yarn”解决了问题。