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

feat: find local files better #197

Merged
merged 6 commits into from
Apr 17, 2020
Merged

feat: find local files better #197

merged 6 commits into from
Apr 17, 2020

Conversation

bahmutov
Copy link
Contributor

@bahmutov bahmutov commented Apr 17, 2020

If the application is instrumented inside a Docker container, all paths have different prefix. For example, local paths could be

root/
  app/
    src/
      main.js

But when you run app in Docker container the coverage will be in some local path, so that file main.js will produce in .nyc_output/out.json file

{
  "/var/www/site/main.js": {
    "path": "/var/www/site/main.js"
  }
}

Then local Cypress running outside the container tries to generate the report - and produces an empty report, since there is no file "/var/www/site/main.js"

In this PR, if ALL files are missing, we try to find common prefix in paths, such that IF this prefix is replaced with process.cwd() then all files are found.

So if you run in /root/app, then before generating the report, this plugin will say: "Ohh, if I replace /var/www/site with /root/app/src then main.js is found!" And if the same prefix works for all files, then it updates the prefix and generates the reports.

Note: it could check the hash as well to make sure the files are exactly what we expect to find.

@bahmutov bahmutov merged commit dfaed9b into master Apr 17, 2020
@bahmutov
Copy link
Contributor Author

🎉 This PR is included in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@bahmutov
Copy link
Contributor Author

rndmerle pushed a commit to rndmerle/code-coverage that referenced this pull request Apr 25, 2020
* chore: refactor

* adding detecting folder that matches current folder root

* move utility functions

* feat: find matching folder example

* add docker paths example to circleci

* exclude utils file from coverage
@emilyrohrbough emilyrohrbough deleted the find-local-files-better branch March 22, 2023 17:58
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 this pull request may close these issues.

Unable to look up source error
1 participant