-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vitest: Detect whether coverage is enabled in npm scripts (#378)
* vitest: Detect whether coverage is enabled in npm scripts * use regular expression for detecting coverage cli flag
- Loading branch information
Showing
5 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
packages/knip/fixtures/plugins/vitest-npm-script/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@fixtures/vitest-npm-script", | ||
"scripts": { | ||
"test:coverage": "vitest --coverage" | ||
}, | ||
"devDependencies": { | ||
"vitest": "^0.34.6" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/knip/fixtures/plugins/vitest-npm-script/vitest.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
test: { | ||
coverage: { | ||
enabled: false, | ||
provider: 'v8', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import assert from 'node:assert/strict'; | ||
import test from 'node:test'; | ||
import * as vitest from '../../src/plugins/vitest/index.js'; | ||
import { resolve, join } from '../../src/util/path.js'; | ||
import { getManifest, pluginConfig as config } from '../helpers/index.js'; | ||
|
||
const cwd = resolve('fixtures/plugins/vitest-npm-script'); | ||
const manifest = getManifest(cwd); | ||
|
||
test('detects the coverage dependency when a npm script activates coverage', async () => { | ||
const configFilePath = join(cwd, 'vitest.config.ts'); | ||
const dependencies = await vitest.findDependencies(configFilePath, { cwd, manifest, config }); | ||
assert.deepEqual(dependencies, ['entry:**/*.{test,spec}.?(c|m)[jt]s?(x)', '@vitest/coverage-v8']); | ||
}); |