Eric Burel
Eric Burel

Reputation: 4954

Jest coverage should not include rootDir in path, create mismatch with Cypress coverage

I need to merge Cypress coverage report and Jest coverage report, in the context of Next.js application.

Jest will list files as my-app/src/whatever. Cypress only shows src/whatever.

Cypress won't include my-app and Jest does, which raises issue when trying to merge coverage using recommended method from Cypress examples. The alternative would be to have Cypress to display the folder too.

Solution 1: Jest matches Cypress?

I'd like Jest to compute covered files path relative to the rootDir, without displaying it.

For example, the coverage report will show my-app/src/whatever. It should only show src/whatever, without my-app.

Is that doable?

Solution 2: Cypress matches Jest?

The alternative is to have Cypress considering another root dir, but I haven't found such options. It's the least promising option imo. Is there a relevant option for this?

Subsidiary question: both tools have a different line count, probably due to TypeScript + Babel + Webpack interactions with the code. How can I debug this issue?

Thanks

Edit for clarity

Upvotes: 5

Views: 1595

Answers (1)

Eric Burel
Eric Burel

Reputation: 4954

As a quickfix specific to Next, using an src folder is now doable in Next. So putting all testable code in an isolated folder can be a quickfix.

In your Jest config:

  collectCoverageFrom: [
    "src/**/*.{js,jsx,ts,tsx}"
    ...

(not sure why but Cypress do not seem to need aditional config when adding an src folder)

Upvotes: 2

Related Questions