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.

ts-jest does not support new Babel 7 Project-wide config file

See original GitHub issue

Issue :

Babel 7’s Project-wide config file is named babel.config.js, implying it is a JavaScript file, but ts-jest uses json5.parse(readFileSync(babelConfig.value, 'utf8')) to parse the config. This results in an error, because our JavaScript configuration cannot be parsed as JSON.

Expected behavior :

The JavaScript file would be able to be parsed as a babel project-wide configuration. ts-jest’s docs also suggest that JS files are acceptable.

Debug log:

log file content
# content of ts-jest.log :

{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.5"},"message":"creating Importer singleton","sequence":1,"time":"2019-01-04T22:19:32.262Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"23.10.5"},"message":"creating jest presets not handling JavaScript files","sequence":2,"time":"2019-01-04T22:19:32.268Z"}
{"context":{"actualVersion":"23.6.0","expectedVersion":">=22 <24","logLevel":20,"namespace":"versions","package":"ts-jest","version":"23.10.5"},"message":"checking version of jest: OK","sequence":3,"time":"2019-01-04T22:19:32.271Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"created new transformer","sequence":4,"time":"2019-01-04T22:19:32.272Z"}
{"context":{"fileName":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/src/dummy.tests.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false,"rootDir":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo"},"transformerId":1,"version":"23.10.5"},"message":"computing cache key for /Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/src/dummy.tests.ts","sequence":5,"time":"2019-01-04T22:19:32.273Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"no matching config-set found, creating a new one","sequence":6,"time":"2019-01-04T22:19:32.273Z"}
{"context":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/var/folders/31/qs9vmhyd09g85lkk1ktcz5tw0000gn/T/jest_dx","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{"ts-jest":{"babelConfig":"babel.config.js"}},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","jsx","json","ts","tsx","d.ts"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"6ed986b4806ca7fc593176c5d57d2dee","prettierPath":null,"resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo","roots":["/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"jest-environment-jsdom","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.js?(x)","**/?(*.)(spec|test).js?(x)","**/tests.(js|jsx|ts|tsx)","**/*.tests.(js|jsx|ts|tsx)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"","testRunner":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[[".(js|jsx|ts|tsx)","/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"backporting config","sequence":7,"time":"2019-01-04T22:19:32.273Z"}
{"context":{"jestConfig":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/var/folders/31/qs9vmhyd09g85lkk1ktcz5tw0000gn/T/jest_dx","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{"ts-jest":{"babelConfig":"babel.config.js"}},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","jsx","json","ts","tsx","d.ts"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"6ed986b4806ca7fc593176c5d57d2dee","prettierPath":null,"resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo","roots":["/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"jest-environment-jsdom","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.js?(x)","**/?(*.)(spec|test).js?(x)","**/tests.(js|jsx|ts|tsx)","**/*.tests.(js|jsx|ts|tsx)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"","testRunner":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[[".(js|jsx|ts|tsx)","/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"normalized jest config","sequence":8,"time":"2019-01-04T22:19:32.273Z"}
{"context":{"fromPath":"babel.config.js","logLevel":20,"namespace":"config","package":"ts-jest","toPath":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/babel.config.js","transformerId":1,"version":"23.10.5"},"message":"resolved path from babel.config.js to /Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/babel.config.js","sequence":9,"time":"2019-01-04T22:19:32.274Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"babelConfig":{"kind":"file","value":"/Users/rehkugler/Documents/Development/ts-jest-babel-7-project-wide-config-repro-repo/babel.config.js"},"compiler":"typescript","diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"isolatedModules":false,"transformers":[],"tsConfig":{"kind":"file"}},"version":"23.10.5"},"message":"normalized ts-jest config","sequence":10,"time":"2019-01-04T22:19:32.275Z"}

Minimal repo :

https://github.com/paulrehkugler/ts-jest-babel-7-project-wide-config-repro-repo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:5

github_iconTop GitHub Comments

10reactions
liamjonescommented, Apr 4, 2019

The way I’ve been working around this for now is by using the new jest.config.js format and inlining the babel.config.js via a require:

// jest.config.js
module.exports = {
    globals: {
        'ts-jest': {
            babelConfig: require('./babel.config.js')
        }
    }
}
4reactions
ntuckercommented, Jan 1, 2020

Please release a new version

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel@7 and jest configuration - Stack Overflow
I believe I have found a working solution (no thanks to the Jest team providing broken documentation and evading GitHub issues around this ......
Read more >
Switching a Jest Project from Babel to SWC - Goldblog
I don't use ts-jest because I've found it simpler to use Jest's Babel support instead. I also don't want tests to be slowed...
Read more >
Setting up Jest unit tests in a React + Typescript project
ts -jest is a transform for jest which compiles typescript files. If you're using babel to compile your typescript files, you can skip...
Read more >
Untitled
Baruch-lang speaker, Tp4 policy settings, Eastleys solicitors uk, Twitter bootstrap 3 cdn. Zain bhikha zamilooni no music lyrics, Trametal s.p.a, ...
Read more >
Need some help setting up Jest - Framework7 Forum
Hey there, I have Jest working for the most part - however when I try to import my ... My jest.config.ts has the...
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