-
Notifications
You must be signed in to change notification settings - Fork 109
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
[ViteJS] Empty coverage for all files not covered by tests #539
Comments
Thanks for the bug report - this should be enough to reproduce and work on this issue. |
@Sytten did it work ? or the bug is fixed ? |
It doesnt work but we worked around it by forcing it to load/import all files, I don't exactly remember how. |
any update on this? |
Basically create a dummy test for your main entrypoint: import "./main";
describe("Main", () => {
it("Main loads", () => {
expect(true).equal(true);
});
}); That will load all the files of your app (unless you do some dynamic importing stuff) and it will correct your coverage. |
@lmiller1990 Is there any update on this issue? Thanks for any info you can provide 👍🏻 |
Hello, we are working with the Vite team to make it easier for people to build on top of Vite (including us) which should make things like code coverage plugins much easier to author. I don't have an update right now, but I'd expect to have something in the next month or so. @JessicaSachs is working on this primarily, maybe she can chime in if her work will help with code coverage? I didn't get to try fixing it with your current example, I figured if Vite is making big internal changes, it's better to wait. |
There was an open issue in the Istanbul plugin that was recently fixed for this... can you give this a try @lucaspeterson22 iFaxity/vite-plugin-istanbul#13? |
Unfortunately, ´all: true’ option for nyc - as described in your code coverage doc - is not working with this vite plugin, causing issues for merging parallel tests code coverage results. Any progress with Vite team, by any chance? |
My workaround is to disable chunk-splitting in Vite using:
Otherwise with code splitting, Vite only parses the code files loaded by the tests. |
I tried this in my project. But still i can see 0 lines for the files to which no test cases are available. I can see some coverage lines in all the files only if i mount all the components with dummy configuration. Is there any other work around? |
I'm sorry this issue flew under my radar. I have not had a chance to look into Vite code coverage, but this is something I'd really like to do soon. We are using Vite for the front-end at Cypress, so it would be hugely beneficial for us, too. I'm not sure what the general situation is for Vite code coverage (even outside of Cypress). If anyone has more info, please share it here, so when we do work on this, we will have lots of useful information to go on. |
Any update on this? The workarounds presented (chunking, dummy entry point file) didn't work for me to get non-visited vue files to show up in the code coverage report. |
I believe this is the same issue as #552 I have a rough fix working: using Istanbul and Babel to read initial coverage data |
after integrate cypress code coverage in nuxt , Though I'm getting options.ssr value as both true & false for different files, I got this error on my console , |
^ That happens when the SSR'd DOM doesn't match the front-end. You'll need to share a minimal reproduction, I can't do much more than guess without one. Thanks! |
@lmiller1990 Thanks for the response. Here are my steps. I was trying to instrument the project code using the vite-plugin-istanbul npm package. Inside the package.json, here are my package dependencies.
Here's my nuxt.config.ts after installing the vite-plugin-Istanbul package:
Here is my cypress/support/e2e.ts file.
Here is my cypress.config.ts file.
After running npm run dev, my UI interface crashed and was not getting complied properly. and an error message appears on the console, as shown in the screenshot below. However, when I run npx Cypress open, it displays my Cypress code coverage report after the test is completed, but the main issue is that my UI is not functioning and is not being compiled properly. |
Can you please upload your entire GH repo, so I can clone and reproduce? It looks like Nuxt has a bunch of different config options when you make a new project. Thanks! |
hey @lmiller1990 this above code is part of a private repo, but I have another public repo, here same code was implemented for code coverage in nuxt3 and same error occurs in console, please have a look https://github.com/belwalshubham/twitter-clone-cypress-code-coverage |
hello @lmiller1990 Please let me know if you find anything related to this issue on the above repo. |
I am looking into code coverage for Vite. |
I have an example working on my work codebase. Do you need a hand? Poke me
on Discord.
…On Tue, Dec 27, 2022 at 8:03 PM Lachlan Miller ***@***.***> wrote:
I am looking into code coverage for Vite.
—
Reply to this email directly, view it on GitHub
<#539 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVL4BHQY474EHKSKY6AGEDWPOGVHANCNFSM5JPRVOSA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@lmiller1990 thanks |
hello @lmiller1990 thank you, the problem has been resolved |
So it looks like you can get coverage just fine with In the meantime, I think we need 1) better docs 2) example repo 3) ideally ship this out of the box in some fashion. For now, I'd recommend we focus on 1) and 2) so people can get started, and look at a more "batteries included" solution down the track. |
The same issue is still persistent in |
I continued upon the quoted solution. To make sure that coverage is created for every Typescript file in my application directory I create a glob pattern and then execute it for every file in the glob. This implicitly imports the file. Now my code coverage report is complete. // @ts-ignore
const allFilesGlobExcludingCypress: Record<string, () => Promise<unknown>> = import.meta.glob([
'./**/*.{tsx,ts}',
'!./**/*.cy.tsx',
]);
describe('CoverageWorkaround', () => {
it('should import all files to make coverage report complete', { defaultCommandTimeout: 60000 }, async () => {
const isCoverageEnabled = Cypress.env('coverage');
if (!isCoverageEnabled) {
return;
}
for (const file in allFilesGlobExcludingCypress) {
await allFilesGlobExcludingCypress[file]();
}
});
}); |
Versions
.nyc_output
folder? Yes, not emptyall
Describe the bug
Despite using the
all
setting of NYC, it seems like only files touched by tests have their line numbers included in the report.The other files are present but show 0 lines thus are ignored in the final computation of the code coverage.
Using the debug flag, I see them added:
But I would expect them to get line numbers at some point. But they only get:
I use ViteJS and my plugins looks like:
Support contains:
The coverage for files under test works fine.
Link to the repo
This is not an open-source project, but happy to provide a reproduction if that can help debug it.
The text was updated successfully, but these errors were encountered: