0

I have an npm script in the package.json:

"test:coverage": "vitest run --coverage",

Also, there is a hello.test.ts test file.

I want:

  1. Vitest to run a single hello.test.ts file
  2. Generate a v8 coverage report for the single corresponding hello.ts file

Unfortunately, I couldn't find anything suitable in the official documentation: https://vitest.dev/config/#coverage

I tried adding an argument --collectCoverageFrom=src/hello.ts, but it was not recognized.

Running npm run test:coverage hello.test.ts narrows the execution of tests to a hello.test.ts file, but the text coverage report includes other files directly not related to hello.ts.

3 Answers 3

1

You might try the --coverage.include <pattern> CLI argument instead.

https://vitest.dev/guide/cli.html#coverage-include

Sign up to request clarification or add additional context in comments.

Comments

0

I think that you might be successful with the command:

npm run test:coverage:file <your_file>

where test:coverage:file is

vitest run --coverage --testNamePattern

Comments

0

I have found this to work:

vitest run <your_test_file> --coverage.enabled true --coverage.include=<your_file_to_be_tested>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.