nyc icon indicating copy to clipboard operation
nyc copied to clipboard

Monorepo/Lerna cross-package coverage

Open fubar opened this issue 4 years ago • 4 comments

This is a general request for suggestions.

Consider a Lerna monorepo for an npm org called foo with the following packages:

packages/api
packages/api-client

The api package contains integration tests that use the API client which is imported like import { client } from '@foo/api-client';

In this setup, it's very desirable for nyc to instrument the API client. However, as it stands, it is unable to do so. I'm aware of the various discussions around includes and excludes of node_modules and the excludeNodeModules flag, but I was not able to find a combination that gives me the desired coverage.

Generally I would say that each package should confine test coverage to within its own scope; however, given that this is an API which makes its client lib available as a separate package, it is not desirable to create a mock API only to exercise the client lib with tests when it is already 100% exercised in the integration tests on the API side.

Any suggestions or ideas? Thanks!

fubar avatar Oct 09 '20 20:10 fubar

@fubar fyi I had a similar issue (with yarn workspaces rather than lerna), and this fixed it https://github.com/istanbuljs/nyc/issues/1301#issuecomment-610393242. (Though yes a solution without special configuration like that would be nice)

rwalle61 avatar Feb 27 '21 15:02 rwalle61

We got the above setup working. We configure nyc and babel-plugin-instanbul with cwd: '..' leaving jest configuration as is. We then use jq to filter for each monorepo package from all the coverage-final.json produced by various unit and integration tests, and finally nyc merge for each monorepo package.

wholebuzz avatar Apr 07 '21 21:04 wholebuzz

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Apr 16 '22 11:04 stale[bot]

It is still relevant to us. To make this work we still rely on a workaround that cannot be committed, so it would be good to have support for this out of the box.

fubar avatar Apr 17 '22 01:04 fubar