question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to disable ts-jest process my .js files

See original GitHub issue

Issue :

I place in jest.conf.js such code:

module.exports = {
    ....
    testMatch: ['**/__tests__/**/*.spec.ts'],
    transform: {
        '^.+\\.ts$': 'ts-jest',
    },
    ...
}

Expected behavior :

I want to disable ts-jest process my .js files. It found tests that is .spec.ts, but if test have an import from some package (.js), then ts-jest started to process that import. How can I configure such behavior to disable ts-jest[jest-transformer] for imported modules inside tests? I also tryed to do as warning told me. I tried to add allowJs: false in my tsconfig - but has no effect. How can I fix that on jest.conf.js level?

Debug log:

I always see this in log and tests pass much slower than it was since there was jest/ts-jest23.


ts-jest[jest-transformer] (WARN) Got a `.js` file to compile while `allowJs` option is not set to `true` (file: ....js). To fix this:
  - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)
  - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
medinskycommented, May 22, 2019

solved by adding transformIgnorePatterns: ['^.+\\.js$'], in jest.config.js

15reactions
trivikrcommented, May 17, 2019

Use testMatch instead

The default in Jest 24 is [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ] (docs)

To disable JS files, use [ "**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)" ]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop Jest from running tests on TS files and only on JS files
I can't get Jest, using the command npm test in my program to stop running tests on my TS files. I only want...
Read more >
Diagnostics option | ts-jest - GitHub Pages
By default all diagnostics are enabled. This is the same as setting the diagnostics option to true . To disable all diagnostics, set...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project. The configuration also can be stored ......
Read more >
How to configure Jest with TypeScript | Swizec Teller
yarn add -D jest typescript ts-jest @types/jest ts-node ... jest.config.js ... add this to your package.json file or build process:.
Read more >
Speed ​​up TypeScript with Jest | miyauci.me
Stop to use jest.config.ts. The above result used jest.config.js as the jest config file. However, the .ts ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found