Skip to content

feat: support .vue files coverage #17

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

Merged
merged 3 commits into from
Jun 21, 2019
Merged

Conversation

rndmerle
Copy link
Contributor

Hi. I managed to make .vue files coverage appear in report.

The issue is the sourcemap resource path for .vue file is a crappy Webpack loaders string from vue-loader, like "cache-loader!vue-loader!file.vue?type=script,lang=ts&".
So it's needed to clean up that path before storing the coverage report.

I've been inspired by an option on karma-coverage-istanbul-reporter doing exactly this.

@bahmutov
Copy link
Contributor

@rndmerle thank you, could you sign CLA please before we can accept this PR

Also, hmm, it would be nice to test this

@bahmutov
Copy link
Contributor

nice, thank you @rndmerle I really appreciate this. I will merge this feature and will create another repo with Vue example

@bahmutov bahmutov merged commit dccb126 into cypress-io:master Jun 21, 2019
@bahmutov
Copy link
Contributor

🎉 This PR is included in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@bahmutov
Copy link
Contributor

trying to get coverage for Vue components in https://github.com/bahmutov/code-coverage-vue-example - so far the reports have the wrong path, "src/components/src/components" even if the .nyc_output/out.json seems correct

@rndmerle
Copy link
Contributor Author

@bahmutov I'll check it out. Pathes are fine on our project.
I was thinking it would be a good idea to base the example repo on a minimal vue-cli3 project maybe ? It would be more familiar to most user I think.

@rndmerle
Copy link
Contributor Author

rndmerle commented Jun 22, 2019

Ok I got it now. The current fix of this PR is not enough to support the sourcemaps generated by vue-loader an other loaders.
On our project the pathes are all absolute and thus it was working right away (maybe because it goes through ts-loader first). But on your repo, in out.json, inputSourceMap.sources and inputSourceMap.sourceRoot contain relative pathes.

To get a final working report we need:

path: '/absolute-path/src/component.vue',
inputSourceMap: {
  sources: ['/absolute-path/src/component.vue'],
  sourceRoot: '', // or undefined
}

But vue-loader (I guess) outputs this for regular components (non-Typescript classes like ours) and functional components:

path: '/absolute-path/src/component.vue',
inputSourceMap: {
  sources: ['component.vue'], // actually it's 'cache-loader!vue-loader!component.vue?vue&type=script&lang=js&'
  sourceRoot: 'src',
}

Unless you have a better idea we'd need to clear sourceRoot and replace sources with path's value?

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.

2 participants