15

I was able to run my tests and collect it's coverage just fine a couple days ago. But when I tried to run it today I got the error (0 , _genMapping.maybeAddMapping) is not a function for every test. The error only happens when I run with coverage flag.

If I run without coverage it work as expected.

PS C:\projetos> yarn jest
yarn run v1.22.17
$ C:\projetos\node_modules\.bin\jest
 PASS  src/shared/utils/__tests__/geralUtils.test.ts (14.834 s)
 PASS  src/shared/utils/__tests__/dateUtils.test.ts (15.253 s)
 PASS  src/features/motorCalculo/__tests__/motorCalculoUtils.test.ts (5.905 s)
 PASS  src/features/motorCalculo/__tests__/motorCalculoParametrosUtils.test.ts (5.19 s)
 PASS  src/features/motorCalculo/__tests__/motorCalculoTabelaUtils.test.ts (28.38 s)

Test Suites: 6 passed, 6 total
Tests:       25 passed, 25 total
Snapshots:   0 total
Time:        32.256 s
Ran all test suites.
Done in 40.73s.

If I try to collect coverage using "yarn jest --coverage" or "yarn jest --collectCoverage" I get the following error:

PS C:\projetos> yarn jest --collectCoverage
yarn run v1.22.17
$ C:\projetos\node_modules\.bin\jest --collectCoverage
 FAIL  src/shared/utils/__tests__/dateUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\shared\utils\dataUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

 FAIL  src/shared/utils/__tests__/geralUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\shared\utils\geralUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

 FAIL  src/features/motorCalculo/__tests__/motorCalculoUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\features\motorCalculo\motorCalculoUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

 FAIL  src/shared/utils/__tests__/arrayUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\shared\utils\arrayUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

 FAIL  src/features/motorCalculo/__tests__/motorCalculoParametrosUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\features\motorCalculo\parametros\motorCalculoParametrosUtils.ts: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

 FAIL  src/features/motorCalculo/__tests__/motorCalculoTabelaUtils.test.ts
  ● Test suite failed to run

    TypeError: C:\projetos\src\features\motorCalculo\tabela\motorCalculoTabelaUtils.tsx: (0 , _genMapping.maybeAddMapping) is not a function

      at SourceMap.mark (node_modules/jest-cli/node_modules/@babel/generator/lib/source-map.js:49:37)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 6 failed, 6 total
Tests:       0 total
Snapshots:   0 total
Time:        27.526 s, estimated 29 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is my jest.config.ts:

import { pathsToModuleNameMapper } from "ts-jest";
import { compilerOptions } from "./tsconfig.paths.json";

export default {
  coverageDirectory: "coverage/jest",
  testEnvironment: "jest-environment-jsdom",
  testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
  testPathIgnorePatterns: ["\\\\node_modules\\\\", "<rootDir>/cypress/"],
  moduleNameMapper: {
    ...pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/" }),
    "\\.(css)$": "<rootDir>/src/shared/mocks/styleMock.ts",
  },
  transform: {
    "^.+\\.(ts|js)x?$": "ts-jest",
  },
};

I couldn't find any information about this error anywhere, does anyone know what could be happening?

Gustavo Cesário
  • 1,310
  • 1
  • 12
  • 23

1 Answers1

27

I have no idea of why this happened. But deleting node_modules and yarn.lock, and running "yarn" again solved the issue.

Gustavo Cesário
  • 1,310
  • 1
  • 12
  • 23