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

No such file or directory for coverage files #4943

Closed
6 tasks done
C0ZEN opened this issue Jan 12, 2024 · 3 comments · Fixed by #5022
Closed
6 tasks done

No such file or directory for coverage files #4943

C0ZEN opened this issue Jan 12, 2024 · 3 comments · Fixed by #5022
Labels
feat: coverage Issues and PRs related to the coverage feature

Comments

@C0ZEN
Copy link

C0ZEN commented Jan 12, 2024

Describe the bug

After the migration to Vite 5, I started having flaky failing tests due to unfound coverage files, but only on the CI (GitHub actions).

Error:  
⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
Error:  Error: ENOENT: no such file or directory, open '/home/runner/actions-runner/_work/x/.tmp/coverage-9.json'
Error:  ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error:  Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/actions-runner/_work/x/.tmp/coverage-9.json' }
Error:  

Note that I use Nx to run the tests.

Reproduction

N/A

System Info

GitHub Actions
Vitest 1
Vite 5

Used Package Manager

npm

Validations

Copy link

Hello @C0ZEN. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
@AriPerkkio
Copy link
Member

I can reproduce this on watch mode. If test re-run is triggered while current run is looping through coverage results, the next run will remove the files and earlier run will cause this error.

In browser mode this is easily reproducible by opening Vitest UI in multiple tabs.

@AriPerkkio AriPerkkio reopened this Jan 19, 2024
@AriPerkkio AriPerkkio added bug feat: coverage Issues and PRs related to the coverage feature and removed needs reproduction pending triage labels Jan 19, 2024
@AriPerkkio
Copy link
Member

After testing multiple different solutions for this, I think the best option is to make coverage providers aware of earlier runs. They should keep similar runningPromise reference as Vitest's core.ts does. In CoverageProvider.clean() we would check if runningPromise is still defined, await it if it is, and only after that allow clean() to continue. In CoverageProvider.reportCoverage() the runningPromise would be resolved at the end. After some testing this solution seems to work the best.

In clean() there could even be a warning logged if runningPromise is defined. Something like 'Warning: Trying to start new coverage collection before earlier run ended. Waiting for earlier run to finish before starting.'.

I've also tried to implement some kind of cancelling mechanism to abort earlier runs. Not sure if that's needed.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: coverage Issues and PRs related to the coverage feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants