-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directory Provided by -r
Flag Not Used as Coverage Root
#1902
Comments
I think support from Istanbul provider is already passing the vitest/packages/coverage-istanbul/src/provider.ts Lines 61 to 67 in 88d5764
|
A quick solution for Vitest is that scan |
Looks like @alexlafroscia I've tried to reproduce this issue using the reproduction repository. However I'm not seeing the expected erroneous results in the "Error case". In my tests the files of LogsBase case: $ pwd
/workspaces/__vitest-monorepo-coverage/packages/b
$ npm test
> [email protected] test
> vitest run --coverage
RUN v0.22.1 /workspaces/__vitest-monorepo-coverage/packages/b
Coverage enabled with c8
✓ src/add-and-double.test.js (1)
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 06:35:48
Duration 1.29s (transform 652ms, setup 0ms, collect 20ms, tests 3ms)
% Coverage report from c8
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
add-and-double.js | 100 | 100 | 100 | 100 |
-------------------|---------|----------|---------|---------|------------------- $ pwd
/workspaces/__vitest-monorepo-coverage
$ npm test
> [email protected] test
> vitest run --coverage -r packages/b
RUN v0.22.1 /workspaces/__vitest-monorepo-coverage/packages/b
Coverage enabled with c8
✓ src/add-and-double.test.js (1)
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 06:34:55
Duration 1.28s (transform 644ms, setup 0ms, collect 20ms, tests 2ms)
% Coverage report from c8
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
add-and-double.js | 100 | 100 | 100 | 100 |
-------------------|---------|----------|---------|---------|-------------------
|
Hey @AriPerkkio -- sorry about that! It seems I had checked in the "fix" that I found by mistake (which is documented at the end of the repo's README), which certainly makes reproducing this issue confusing! I've removed that "fix" from the reproduction repo now alexlafroscia/__vitest-monorepo-coverage@a985394 now running the tests at the workspace root should show the
|
Thanks @alexlafroscia, I'm able to reproduce the issue now. We should really wait for support from Ideally |
I also have a mono-repo setup. To generate the coverage report, I run
"coverage-collect": "globcat packages/*/coverage/lcov.info > lcov.info", The aggregate file is sent to Coveralls or CodeCov. This works fine with Jest, using:
coverageReporters: ['html', 'json', ['lcov', { projectRoot: __dirname }], 'text'], But with For example:
I would rather have the ability to tell |
@Jason3S If you can share a minimal reproduction repository for the
The vitest/packages/coverage-istanbul/src/provider.ts Lines 124 to 126 in 1997767
It was added in #2051.
|
I think it's also worth to add some kind of "Coverage in monorepositories" section to documentation, https://vitest.dev/guide/coverage.html. |
Thank you for the quick response. I'll see if I can setup a sample repo. But, you don't need a mono repo to test it out. The generated Here is a package import { defineConfig } from 'vitest/config';
import * as path from 'path';
export default defineConfig({
test: {
// reporters: 'verbose',
coverage: {
// enabled: true,
provider: 'istanbul',
clean: true,
all: false, // should be true.
reporter: ['html', 'json', 'lcov', 'text'],
exclude: [
'**/*.test.*',
],
},
include: ['src/**/*.test.{ts,mts}'],
exclude: ['content/**', 'fixtures/**', 'bin.mjs', '_snapshots_'],
root: path.join(__dirname, '../..'),
typecheck: {},
},
}); run It generates the report, but the I tried changing Note: it is possible to use cd package/client
nyc report --temp-dir "$(pwd)/coverage" --reporter lcov --report-dir "$(pwd)/cov" --cwd ../.. |
I see the problem now. Using Vitest's I've started working on a feature that will expose reporter configuration options in reporter: [
["text", { "projectRoot": "../../" }],
["json", { "file": "renamed-report.json" }],
], This can already be implemented for |
Thank you. |
@alexlafroscia now that the new |
Closing as there has been no activity since last request. Both coverage providers should be able to provide this functionality now. |
It is now working for me. |
Describe the bug
When running
vitest
from a directory that is not the one that contains the config file, and using the-r
flag to point to another directory that should be treated as the "project root",c8
uses the current working directory as the "root" to gather coverage from instead of the actual project root.The result of this is that, depending on which directory you run the command from, your coverage report can include a bunch of files that it shouldn't!
This is impacting my team because of the way we're running our tests in CI, due to the lack of "projects" support in Vitest (that could test multiple packages all at once). We're running Vitest from the workspace root using the
-r
flag, but our coverage reports now include the files from the mono-repo siblings of the package actually under test.Reproduction
This repository demonstrates the bug, as well as describing one (awkward) fix that I came across
https://github.com/alexlafroscia/__vitest-monorepo-coverage
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: