jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.24k stars 508 forks source link

ts-jest cache issue #919

Closed PurpleBooth closed 3 years ago

PurpleBooth commented 3 years ago

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 commented 3 years ago

Possibly same as #908?

PurpleBooth commented 3 years ago
    "test": "tsdx test --no-cache",

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

agilgur5 commented 3 years ago

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 https://github.com/formium/tsdx/issues/681#issuecomment-612929386. 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 commented 3 years ago

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