playwright-coverage icon indicating copy to clipboard operation
playwright-coverage copied to clipboard

Get zero coverage in monorepo

Open jfulse opened this issue 3 years ago • 6 comments

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?

jfulse avatar Feb 15 '22 16:02 jfulse

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.

bgotink avatar Mar 11 '22 23:03 bgotink

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

jfulse avatar Mar 23 '22 15:03 jfulse

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

sfc-gh-dczerski avatar Mar 29 '22 09:03 sfc-gh-dczerski

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:

  • preview works like regular https file server where you specify which directory to serve,
  • coverage works only when i serve code via devServer: it serves whole bundle from memory with some websocket hmr magic i know vaguely about

source maps are available in both cases

🤯

abetaev avatar Nov 03 '22 02:11 abetaev

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.

luixo avatar Sep 20 '23 00:09 luixo

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.

KernelFolla avatar Oct 05 '23 20:10 KernelFolla