gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

No such file or directory (istanbul-reports/lib/html/assets) #743

Open loick opened 7 years ago

loick commented 7 years ago

[Bug]

Hi there, when I'm using the test-coverage of Jest (so basically Istanbul), I get this error stack:

Failed to write coverage reports:
        ERROR: Error: ENOENT: no such file or directory, scandir '{path}/node_modules/istanbul-reports/lib/html/assets'
        STACK: Error: ENOENT: no such file or directory, scandir '{path}/node_modules/istanbul-reports/lib/html/assets'
    at Object.fs.readdirSync (fs.js:870:18)
    at copyAssets ({path}/node_modules/istanbul-reports/lib/html/index.js:156:16)
    at {path}/node_modules/istanbul-reports/lib/html/index.js:173:9
    at Array.forEach (native)
    at HtmlReport.onStart ({path}/node_modules/istanbul-reports/lib/html/index.js:172:21)
    at LcovReport.(anonymous function) [as onStart] ({path}/node_modules/istanbul-reports/lib/lcov/index.js:24:24)
    at Visitor.(anonymous function) [as onStart] ({path}/node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at Tree.visit ({path}/node_modules/istanbul-lib-report/lib/tree.js:157:13)
    at {path}/node_modules/istanbul-api/lib/reporter.js:84:18
    at Array.forEach (native)

I can see there are no file or directory named assets in the html folder, do you know why ?

I'm using Jest v18.1.0. (and I can see in the changelog, Updated istanbul-api., maybe it's related ? Since I don't have the issue with Jest v18.0.0)

Uepsilon commented 7 years ago

I've got the same issue when using karma instead of jest.

Stack: webpack@2.2.0.rc-3 karma@1.3.0 babel-istanbul@0.6.1

martijnsenden commented 7 years ago

Same here.

Stack: webpack@2.2.0-rc.3 jest@17.0.2 istanbul@0.4.5 istanbul-reports@1.0.0 istanbul-api@1.1.0 babel-plugin-istanbul@2.0.3

noxxious commented 7 years ago

Had the same issue, but only after I ran the yarn clean. Removing .yarnclean file and reinstalling all modules fixed the issue.

rstuven commented 7 years ago

Yes, that worked! rm -rf node_modules .yarnclean && yarn

pelle commented 7 years ago

Why would istanbul need to write in the node_modules directory? That seems wrong.

rstuven commented 7 years ago

@pelle It's trying to read the templates in node_modules. Maybe a better message would be "Failed to create coverage reports", because at that point it is not writing anything.

rlecaro2 commented 7 years ago

As referenced here and here yarn is cleaning the assets folders in node_modules.

I just ignored the necessary folders inside the .yarnclean file (so it still cleans everything else).

# asset directories
docs
doc
website
images
assets
!istanbul-reports/lib/html/assets

Note the ! sign

morphatic commented 7 years ago

I like the solution @rlecaro2 suggested. FYI, his pattern didn't work for me. Instead I had to use:

# asset directories
!nyc/node_modules/istanbul-reports/lib/html/assets

Thanks!

jmjpro commented 7 years ago

Thanks @rlecaro2. For me the pattern was !istanbul/lib/assets

danieltwork commented 5 years ago

At the moment, an exception to two places should be added.

.yarnclean file:

# asset directories
docs
doc
website
images
assets
!istanbul-reports/lib/html/assets
!istanbul-api/node_modules/istanbul-reports/lib/html/assets

Remember to remove .yarnlock after this operation and reinstall dependencies.

rm -rf node_modules
yarn install 

Yes, that worked! rm -rf node_modules .yarnclean && yarn

The .yarnclean file is used to clean folders depending on the files you do not need, it is better is to control what should be removed, if you use istanbul-reports, you should add an exception to the .yarnclean file so that you do not delete the assets folder in this dependence.