bgotink / playwright-coverage

Track coverage in playwright tests
MIT License
35 stars 16 forks source link

Get zero coverage in monorepo #5

Open jfulse opened 2 years ago

jfulse commented 2 years ago

Hello! I'm having some issues getting coverage in a monorepo where Playwright runs from a folder root/e2e-tests/ and tests a server located at root/frontend/. I start the server and follow the instructions from the Readme, but end up with:

================ Coverage summary ================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
==================================================

I've tried various fixes, including pointing sourceRoot to the monorepo root and to the server folder.

I've had a similar issue setting trying to set up the coverage myself following https://playwright.dev/docs/api/class-coverage. Maybe I have a step missing? I think I don't need to instrument the server code using babel-plugin-istanbul, due to using v8 directly?

bgotink commented 2 years ago

Did you perhaps use @playwright/test's own test function in your tests? If you don't use a test function created using mixinCoverage, coverage won't be tracked and the reporter won't have anything to report on.

You indeed don't need babel-plugin-istanbul because v8 tracks the coverage natively.

Having the wrong sourceRoot would lead to coverage that points to incorrect files, but it doesn't stop the reporter from computing the correct coverage.

jfulse commented 2 years ago

Thanks for the reply! I'm pretty sure we used test from the mixin but I'll go back and double check.

sfc-gh-dczerski commented 2 years ago

Thanks for the reply! I'm pretty sure we used test from the mixin but I'll go back and double check.

Have you managed to get it to work, we are facing the same problem with unknown

abetaev commented 1 year ago

don't know if it's related, i have similar issue and i was lucky to find workaround, it's very specific though.

i use 2 vite functions programmatically:

source maps are available in both cases

🤯

luixo commented 1 year ago

Got a similar issue while trying to bootstrap coverage in my app.

The solution was to add a proper sourceRoot as everything outside it is ignored (my playwright config is in <root>/apps/next/playwright/playwright.config.ts so I used path.join(__dirname, "../../..") to get to the root) and add rewritePath according to an example from another PR.

There is still an issue of not being able to see coverage for files outside of my playwright dir though.

KernelFolla commented 1 year ago

I have encountered another issue. In my specific scenario (nx + Angular 16), utilizing the following configuration: sourceRoot: path.join(__dirname, '../..') seems to resolve the problem.

However, it functions correctly only when the webserver is running concurrently.

Otherwise, when executing the lib command and attempting to retrieve the source map using getSourceMap, it results in an error (ECONNREFUSED) and returns undefined for the sourceMap.

I guess that the webserver terminates before the call is completed.