globalSetup.ts script ignores tsconfig.json
See original GitHub issueIssue
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
Actual behavior
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
Minimal repo
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:18
Top Results From Across the Web
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 | Swizec Teller
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 ...
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 >Advanced: configuration | Playwright - CukeTest
Specify globalSetup , baseURL and storageState in the configuration file. TypeScript; JavaScript. // playwright.config.tsimport ...
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 FreeTop 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
Top GitHub Comments
Adding
require("tsconfig-paths/register");
at the top ofglobalSetup
seems to fix it. This works for meglobalSetup.ts
:Hmm look like moduleNameMapper only works in test files and doesn’t seem to work with globalSetup.