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 not created when it does not exist and then coverage crash #138

Closed
tebeco opened this issue Mar 23, 2017 · 21 comments · Fixed by #144
Closed

ts-jest not created when it does not exist and then coverage crash #138

tebeco opened this issue Mar 23, 2017 · 21 comments · Fixed by #144
Labels

Comments

@tebeco
Copy link

tebeco commented Mar 23, 2017

  • Issue

test run & pass but i've got an error (probably when coverage is ran)
"No such file or directory" when running jest

  • Expected behavior

ts-jest should create a folder ts-jest in cacheDirectory if it does not exists

i think i'm expriencing the same issue

node v7.7.3
npm  v4.1.2

script:{
    "test": "jest --config jestconfig.json --runInBand",
    "test:watch": "npm test -- --watch",
    "test:cover": "npm test -- --coverage --no-cache"
}
>npm test

> [email protected] test C:\Workspace\GitHub\TeBeCo\webpack-seeds\react-typescript2-jest
> jest --config jestconfig.json --runInBand

 PASS  src\somePath\xx.spec.ts
  given xxxxx
    √ should be true (16ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.766s, estimated 1s
Ran all test suites.
Error: ENOENT: no such file or directory, scandir 'C:\Users\xxx\AppData\Local\Temp\jest\ts-jest'
    at Object.fs.readdirSync (fs.js:913:18)
    at processResult (C:\Workspace\GitHub\TeBeCo\Webpack-seeds\react-typescript2-jest\node_modules\ts-jest\dist\coverageprocessor.js:20:26)
    at module.exports (C:\Workspace\GitHub\TeBeCo\Webpack-seeds\react-typescript2-jest\jestTestResultsProcessor.js:4:12)
    at source.getTestPaths.then.then.then.runResults (C:\Workspace\GitHub\TeBeCo\Webpack-seeds\react-typescript2-jest\node_modules\jest\node_modules\jest-cli\b
uild\runJest.js:110:58)
npm ERR! Test failed.  See above for more details.

the folder C:\Users\xxx\AppData\Local\Temp\jest\ exist but not the subfolder ts-jest
if i create it manually the error disapear

I've change the cacheDirectory to point to a non existing folder inside the repository

{
    "cacheDirectory": ".ts-jest-cache"
}

the folder is well create but again it DOES NOT create the sub folder ts-jest inside and print the same stacktrace

@kulshekhar
Copy link
Owner

please create a minimal repo which reproduces this issue

@tebeco
Copy link
Author

tebeco commented Mar 24, 2017

I cannot push the repo like that
I hope I'll try to create a small one

Also when I try to run --coverage --no-cache it seems that typescript is not transpilled but not sure of that last one

@jonaskello
Copy link

I have the same issue and I made a minimal repo to reproduce.

@kulshekhar
Copy link
Owner

@jonaskello I did npm install and npm test -- --no-cache --coverage and got the following result:

 PASS  lib-cjs/link.test.js
 PASS  lib-cjs/sum.test.js
 PASS  test/sum.test.ts
 PASS  test/link.test.tsx
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

Test Suites: 4 passed, 4 total
Tests:       4 passed, 4 total
Snapshots:   2 passed, 2 total
Time:        3.685s
Ran all test suites.

@jonaskello
Copy link

jonaskello commented Mar 25, 2017

Hmm.. strange, here is what I get if I start fresh and re-clone the repo:

$ git clone https://github.com/jonaskello/ts-jest-coverage-repro.git
Cloning into 'ts-jest-coverage-repro'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 14 (delta 0), reused 14 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
$ cd ts-jest-coverage-repro/
$ yarn install
yarn install v0.21.3
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
✨  Done in 5.12s.
$ yarn test -- --no-cache
yarn test v0.21.3
$ jest --config=test/jest.config.json --no-cache
 PASS  test/sum.test.ts
 PASS  test/link.test.tsx

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        1.74s
Ran all test suites.
Error: ENOENT: no such file or directory, scandir '/var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest/ts-jest/'
    at Object.fs.readdirSync (fs.js:913:18)
    at processResult (/Users/JonKel/code/github/jonaskello/ts-jest-coverage-repro/node_modules/ts-jest/dist/coverageprocessor.js:20:26)
    at source.getTestPaths.then.then.then.runResults (/Users/JonKel/code/github/jonaskello/ts-jest-coverage-repro/node_modules/jest-cli/build/runJest.js:110:58)
    at process._tickCallback (internal/process/next_tick.js:109:7)
error Command failed with exit code 1.

I'm doing this on macOS. I also get the same error on my CI server that is running ubuntu.

EDIT: Also tried the above with npm instead of yarn but same result.

EDIT2: I'm using node v7.7.1.

EDIT3: Also tried it on my Windows 10 machine with node v7.4.0, same result as above.

@jonaskello
Copy link

If I manually create the missing dir I don't get the error.

@kulshekhar Perhaps you already have this dir from some earlier versions where it worked and the dir was created. Could you try to remove your jest temp dir and try again? (I am new to jest so I am not sure how you can find where your temp dir is though but I guess you know how to find it?).

Here are my results if I manually create the dir, and if I then remove it again. From what I understand in the docs, jest should not use the cache dir if --no-cache is specified, however it seems that ts-jest is still looking for the dir even with --no-cache.

$ mkdir /var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest/ts-jest/
$ yarn test -- --no-cache
yarn test v0.21.3
$ jest --config=test/jest.config.json --no-cache
 PASS  test/sum.test.ts
 PASS  test/link.test.tsx

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        1.563s
Ran all test suites.
✨  Done in 2.74s.
$ rm -rf /var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest/ts-jest/
$ yarn test -- --no-cache
yarn test v0.21.3
$ jest --config=test/jest.config.json --no-cache
 PASS  test/sum.test.ts
 PASS  test/link.test.tsx

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        1.57s
Ran all test suites.
Error: ENOENT: no such file or directory, scandir '/var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest/ts-jest/'
    at Object.fs.readdirSync (fs.js:913:18)
    at processResult (/Users/JonKel/code/github/jonaskello/ts-jest-coverage-repro/node_modules/ts-jest/dist/coverageprocessor.js:20:26)
    at source.getTestPaths.then.then.then.runResults (/Users/JonKel/code/github/jonaskello/ts-jest-coverage-repro/node_modules/jest/node_modules/jest-cli/build/runJest.js:110:58)
    at process._tickCallback (internal/process/next_tick.js:109:7)
error Command failed with exit code 1.

@tebeco
Copy link
Author

tebeco commented Mar 25, 2017

@kulshekhar can you please describe :
Your OS
Node version
Npm version
Remove the ts-jest folder that is inside the cache Directory

@jonaskello
Copy link

I pushed some changes to my reproduction repo in order to make it produce coverage reports. I also deleted my full jest cache dir rm -rf /var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest/. Now it does not throw the error anymore but coverage is unkown.

@kulshekhar
Copy link
Owner

@tebeco Mint (~Ubuntu 16.04), v6.10.1, 3.10.10

Which cache directory are you referring to?

@jonaskello
Copy link

I think @tebeco is refering to the cache directory used by this line. It is set on config.cacheDirectory in there. Not sure how to find it in another way.

@kulshekhar
Copy link
Owner

Here's a suggestion - if you have the code that reproduces this issue in a repo, add travis to it. We'll then have a common reference point using which we can take this forward.

@jonaskello
Copy link

@kulshekhar I made some changes to my repo in order to make it easier to reproduce. Now it shows you the cache dir and you can copy a command and run it to remove it. If you pull my repo and run this I think you will see the issue:

yarn install
# Run this command to find your cache dir
yarn run rm-cache
# Make note of the command to remove your cache dir and run it
rm -rf /var/folders/x9/80kcdvw148n5glkvr51w7fm80000gn/T/jest
# Now run the test
yarn run test

@jonaskello
Copy link

@kulshekhar And also added travis as requested :-).

@tebeco
Copy link
Author

tebeco commented Mar 25, 2017

@kulshekhar please upgrade your node and npm version
It might be related
The use of 'fs' and bugs often comes in pair with node/ npm

@tebeco
Copy link
Author

tebeco commented Mar 25, 2017

I do understand you use LTS even thought it should be clarified

@kulshekhar
Copy link
Owner

kulshekhar commented Mar 25, 2017

@jonaskello thanks! I've sent a PR to add more versions of node to travis to identify whether this is a version specific issue.

@tebeco I prefer keeping the latest LTS version on my dev machine.

edit: it doesn't look to be a version specific problem anyway

@tebeco
Copy link
Author

tebeco commented Mar 25, 2017

Can you try with updated version of node and npm ?
You'll rollback to LTS
Maybe we'll be fixed also you might be able to reproduce

@jonaskello
Copy link

@tebeco The travis tests are now running multiple versions of node and they all fail.

@jonaskello
Copy link

@kulshekhar Thanks, now the error is gone in my repo!

Though I still get "Unknown" for all the coverage. I think the config should be correct according to the readme. Would appreciate if you could take a look and see if it is something with the config or if I should look elsewhere.

@Tismas
Copy link

Tismas commented Sep 18, 2018

@jonaskello I've the same problem with Unknown coverage :/

@huafu
Copy link
Collaborator

huafu commented Sep 18, 2018

@Tismas I'll advise you to test latest beta (about to be released btw), see #697 for instructions. Also you can join ts-jest new slack community for more help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants