Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-jest cache issue #919

Closed
PurpleBooth opened this issue Oct 31, 2020 · 4 comments
Closed

ts-jest cache issue #919

PurpleBooth opened this issue Oct 31, 2020 · 4 comments
Labels
scope: upstream Issue in upstream dependency solution: workaround available There is a workaround available for this issue

Comments

@PurpleBooth
Copy link

PurpleBooth commented Oct 31, 2020

Current Behavior

Jest runs tests in the node_modules directory (maybe), or it's somehow caching old ts files somewhere?

$ yarn test
yarn run v1.22.10
$ tsdx test
 FAIL  test/reader.test.ts
  ● Test suite failed to run

    test/blah.test.ts:1:10 - error TS2305: Module '"../src"' has no exported member 'sum'.

    1 import { sum } from '../src';
               ~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.264s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ ls test
reader.test.ts
$ find . -name "blah.test.ts"
./node_modules/tsdx/templates/basic/test/blah.test.ts

Expected behavior

Tests not to be run in the node_modules directory

Suggested solution(s)

I'm not actually sure what's causing this, so it's hard to say. The jest config looks ok to me

Additional context

This is a pretty new project, so it's not customised. I also had a play with manually adding node_modules to the file ignore list in the jest config, just to check that the default was working as expected, and that didn't seem to make a difference.

Your environment


  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 4.86 GB / 32.00 GB
    Shell: 3.1.2 - /usr/local/bin/fish
  Binaries:
    Node: 15.0.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 86.0.4240.111
    Firefox: 82.0.1
    Safari: 14.0
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1 
    typescript: ^4.0.5 => 4.0.5 


@PurpleBooth PurpleBooth changed the title Jest running files in node_modules Jest running files in node_modules or caching old files Oct 31, 2020
@PurpleBooth
Copy link
Author

Possibly same as #908?

@PurpleBooth
Copy link
Author

    "test": "tsdx test --no-cache",

It was definately the caching. This fixed it. So this makes it a dupe of the above. Closing.

@PurpleBooth PurpleBooth changed the title Jest running files in node_modules or caching old files Jest caching old files Oct 31, 2020
@agilgur5 agilgur5 changed the title Jest caching old files ts-jest cache issue Oct 31, 2020
@agilgur5 agilgur5 added solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue scope: upstream Issue in upstream dependency and removed solution: duplicate This issue or pull request already exists labels Oct 31, 2020
@agilgur5
Copy link
Collaborator

agilgur5 commented Nov 2, 2020

Yea TSDX does not read node_modules by default. TSDX does not specify a testPathIgnorePatterns in its default config, meaning it uses Jest's default, which is "/node_modules/". So by default anything in node_modules is ignored.

TSDX also dogfoods tsdx test and this issue does not occur in internal tests or in CI runs.

You may have misread the test output too, because it doesn't show it reading a file from node_modules:

 FAIL  test/reader.test.ts

It does show the output for that file to be from a different file though, which, yes does sound like an upstream cache issue.

 test/blah.test.ts:1:10 - error TS2305: Module '"../src"' has no exported member 'sum'.

Specifically, that output is not from Jest, but from ts-jest's diagnostics / type-checking. It's worthwhile to note that this can be turned off per #681 (comment). You can also turn off ts-jest itself (and just use babel-jest) for testing as some users do.

Possibly same as #908?
So this makes it a dupe of the above.

#908 is also a cache problem, but it's quite a different one. That one is a TypeError inside of ts-jest itself, this is a stale cache. So they're not duplicates.

But in any case, this issue is upstream in ts-jest and not in TSDX, so I would recommend searching there for similar errors and filing an issue there. We don't have any control over cache issues with ts-jest and I can't reproduce this (cache errors are quite difficult to repro as they are stateful).

@PurpleBooth
Copy link
Author

PurpleBooth commented Nov 2, 2020

Thanks for the detailed response. I disabled caching for ts-jest, the problem has vanished.

lourot added a commit to Frameright/image-display-control-metadata-parser that referenced this issue Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: upstream Issue in upstream dependency solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

No branches or pull requests

2 participants