-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I'm working on a Next.js app where we've just started adding tests with Cypress. Because there's a lot of pre-existing code, I want to use the coverage reports as a progress report to see how we're progressing... but I'm getting a very limited view from the lcov-report
.
Pages in the Next.js app that aren't visited in tests do not appear in the report, so I'm getting inflated coverage numbers. Instead of "what percentage of the total statements in the app are covered?", the report gives me "what percentage of the total statements in pages that the tests visited are covered?"
I took a look at https://github.com/kylemh/next-ts-with-cypress-coverage, which led me to adding the all
option to the nyc
config. Now pages
that haven't been touched show up in the lcov-report
... but with all zeros.
I've reproduced at https://github.com/cherewaty/next-and-cypress-example/tree/uncovered-page
uncovered.js should instead show 0/1 statements covered
My hypothesis is that Next.js's dev server isn't even attempting to build pages
until they're visited, so babel-plugin-istanbul
isn't instrumenting them.
Some paths to explore I've been thinking about:
- Am I missing some configuration parameter that would make this easy?
- Maybe I could hack up the
next/babel
preset a little bit whenNODE_ENV==="test"
so all sources get built and instrumented? - Do I need to run
cypress
against a "production" artifact fromnext build
instead of thedev
server? - Could I set up a spot where I import everything just for
cypress
runs?
Happy to make a PR to this example repo if I get this figured out!