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

badge script fails to run after tests #255

Closed
jameschensmith opened this issue Dec 7, 2020 · 3 comments
Closed

badge script fails to run after tests #255

jameschensmith opened this issue Dec 7, 2020 · 3 comments

Comments

@jameschensmith
Copy link

jameschensmith commented Dec 7, 2020

When running tests in the v2 branch the output below is noticed.

$ make-coverage-badge --output-path ./coverage.svg
./zod/node_modules/make-coverage-badge/cli.js:64
  if (err) throw err
           ^

[Error: ENOENT: no such file or directory, open './coverage/coverage-summary.json'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: './coverage/coverage-summary.json'
}
error Command failed with exit code 1.

This is due to the rootDir key in jest.config.json pointing to src, which then generates coverage/ under said directory. Two solutions are noted below, along with a recommendation.

  1. Change badge script to make-coverage-badge --report-path ./src/coverage/coverage-summary.json --output-path ./coverage.svg in package.json
  2. (recommended) Change rootDir to . in jest.config.json
@colinhacks
Copy link
Owner

colinhacks commented Dec 7, 2020

You have to run the tests first. I never call yarn badge directly, it gets called as part of yarn test so I don't have to worry about whether the coverage.json has been generated.

[EDIT] Okay I replicated it! Dumb mistake on my part. Fixed with solution 1. When you change rootDir to ., Jest starts trying to run all the compiled versions of the tests from lib which is why I set rootDir: src. I suppose you could fix this by playing with testRegex but since the result is the same I haven't bothered. If you think there are other reasons for changing rootDir to . feel free to submit a PR 👍

@jameschensmith
Copy link
Author

@colinhacks, by removing the tests from lib/ in #254, so that's not a problem 🙂 Also, having generated directories in src/ is not a common practice. That's why the default location make-coverage-badge looks for coverage is in ..

This is your repository, though, so take this with a grain of salt 😊 Appreciate you reviewing my reported issues/PRs!

@colinhacks
Copy link
Owner

Okay I switched rootDir to .

Thanks for your PRs — great work!

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

No branches or pull requests

2 participants