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.

`jest --watch` doesn't pick up changes in source-mapped files

See original GitHub issue

🐛 Bug Report

We’re having a TypeScript project that stores intermediate JS files on disk as they’re being used by multiple tools.

(Inline) Source maps in general work fine with Jest, but it doesn’t pick up file changes when I save a .ts file which then gets transpiled to its respective .js file.

No tests found related to files changed since last commit.

To Reproduce

Have a TypeScript project that transpiles JS into a folder that is ignored by .gitignore.

Update a TS file while haven tsc and jest both running in watch mode.

Expected behavior

jest should pick up the file change for the transpiled JS file and figure out that it corresponds to the source TS file which is tracked and modified in Git. It then should run the tests for that file.

Link to repl or repo (highly encouraged)

If you need a reproduction case for this I will happily provide one. But I thought I wait for the initial answer, which might be a definitive “should work” or “work work because X”.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Binaries:
    Node: 8.9.1 - /usr/local/bin/node
    Yarn: 1.6.0 - ~/Sources/web/node_modules/.bin/yarn
    npm: 5.5.1 - /usr/local/bin/npm
  npmPackages:
    @types/jest: ^22.2.3 => 22.2.3
    jest: ^23.0.1 => 23.0.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:10

github_iconTop GitHub Comments

5reactions
lenkancommented, Sep 26, 2018

@SimenB

Jest should run on source code, not transpiled output.

I have seen this comment before on a similar issue. I must say I don’t really understand why? All this does is introduce a dependency of some sort of inline transformation step which must be kept maintained and up to date with both jest and the chosen transpiler. At the moment this is a pain because of the incompatibilities between jest and babel 7 (correct me if I’m wrong).

I’d much prefer to simply have one transpilation step, and then just run jest against that output. This is very common procedure on many other platforms where you execute your testrunner against a compiled binary. I can to this now, but the problems are that I have to manually “deconfigure” the transform option, as well as missing out on this very helpful watch option because file changes in .gitignored files are simply ignored.

I’d be happy to take a stab at this and submit a PR. But this seems to be an intentional feature (?)

1reaction
iwnnaycommented, Apr 23, 2019

I actually came to this page in search of an answer and the discussion made me think about my settings and I realized that I had basically excluded my source code with this setting:

       rootDir: './specs',

I chanced it to the following and it worked great after that:

       rootDir: './',
Read more comments on GitHub >

github_iconTop Results From Across the Web

ts-jest --watch doesn't detect changes to imported class ...
I am creating a class and running ts-jest to check for the properties. The issue is when I run "jest --watch" or "jest...
Read more >
Configuring Jest
A list of paths to modules that run some code to configure or set up the testing environment. Each setupFile will be run...
Read more >
TSConfig Reference - Docs on every TSConfig option
# Declaration Map - declarationMap. Generates a source map for .d.ts files which map back to the original .ts source file.
Read more >
Running Tests | Create React App
Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press...
Read more >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
This likely means that your source map doesn't contain or link to your original source files. Without your original source files, you're still ......
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