globalSetup.ts script ignores tsconfig.json
See original GitHub issue🐛 Bug Report
When tsconfig.json has defined compilerOptions.baseUrl, absolute paths can be used within test files for importing items. However, same TS code placed in globalSetup script handles only relative paths. Looks like tsconfig is simply ignored while running globalSetup.
To Reproduce
Steps to reproduce the behavior:
- checkout https://github.com/4ekki/jest-globalSetup-import-bug. Note that first line of scripts/globalSetup.ts file is :
import { sleep } from "../tests/src" - run
yarn test smoke - change first line of scripts/globalSetup.ts file to:
import { sleep } from "src" - run
yarn test smoke
As a result:
On 2, globalSetup script is run successfully with relative path. Also, import with absolute path is successfully handled in test file.

On 4, globalSetup script fails to import sleep from src, using absolute path:

Expected behavior
On 4, absolute paths in globalSetup.ts are resolved using compilerOptions.baseUrl property from tsconfig.json
Link to repl or repo (highly encouraged)
https://github.com/4ekki/jest-globalSetup-import-bug
Run npx envinfo --preset jest
$ npx envinfo --preset jest
npx: installed 1 in 1.962s
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
Binaries:
Node: 10.5.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.7.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
globalSetup.ts script ignores tsconfig.json · Issue #1107
Issue When tsconfig.json has defined compilerOptions.baseUrl, absolute paths can be used within test files for importing items.
Read more >Why is the TypeScript compiler ignoring tsconfig.json?
I am really to new to Gulp, but the Gulp task looks OK to me: var tsProject = ts.createProject('scripts/tsconfig.json'); gulp.task( ...
Read more >How to configure Jest with TypeScript
Tell TypeScript to ignore Jest files. Jest encourages you to put test files next to the code you're testing. Makes tests easier to...
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 >Setup | Testing Library
json . If you're using Create React App without TypeScript, save this to jsconfig.json instead. tsconfig.json.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Not yet. Note that this is very unlikely to be a bug in jest as we do not support tsconfig at all out of the box (we use babel), most likely your issue is with ts-jest. However, I’d like to verify (although I haven’t found the time yet)
I’ve duplicated this to ts-jest tracker as well - https://github.com/kulshekhar/ts-jest/issues/1107