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.

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:

  1. checkout https://github.com/4ekki/jest-globalSetup-import-bug. Note that first line of scripts/globalSetup.ts file is : import { sleep } from "../tests/src"
  2. run yarn test smoke
  3. change first line of scripts/globalSetup.ts file to: import { sleep } from "src"
  4. 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. image image

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

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:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, May 13, 2019

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)

0reactions
4ekkicommented, May 23, 2019

I’ve duplicated this to ts-jest tracker as well - https://github.com/kulshekhar/ts-jest/issues/1107

Read more comments on GitHub >

github_iconTop 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 >

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