forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage): use project specific vitenode (vitest-dev#5856)
- Loading branch information
1 parent
42bd4a2
commit e7ad735
Showing
6 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
test/coverage-test/fixtures/configs/vitest.workspace.multi-transforms.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,45 @@ | ||
import { Plugin, defineWorkspace } from "vitest/config"; | ||
import MagicString from "magic-string"; | ||
import { readFileSync } from "fs"; | ||
|
||
export default defineWorkspace([ | ||
{ | ||
test: { | ||
name: 'normal', | ||
include: ['fixtures/test/math.test.ts'] | ||
}, | ||
}, | ||
{ | ||
test: { | ||
name: 'special', | ||
include: ['fixtures/test/custom-syntax.test.ts'] | ||
}, | ||
plugins: [customFilePlugin()] | ||
} | ||
]) | ||
|
||
function customFilePlugin(): Plugin { | ||
return { | ||
name: 'load-custom-files', | ||
load(id) { | ||
if(id.endsWith(".custom")) { | ||
const content = readFileSync(id, 'utf8') | ||
|
||
const s = new MagicString(content) | ||
s.replace('<function covered>', ` | ||
function covered() { | ||
return "Custom file loaded!" | ||
}`.trim()); | ||
|
||
s.replace('<function uncovered>', ` | ||
function uncovered() { | ||
return "This should be uncovered!" | ||
}`.trim()); | ||
|
||
s.replace('<default export covered>', 'export default covered()'); | ||
|
||
return { code: s.toString(), map: s.generateMap({ hires: 'boundary'})} | ||
} | ||
}, | ||
} | ||
} |
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,5 @@ | ||
<function covered> | ||
|
||
<function uncovered> | ||
|
||
<default export covered> |
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 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
// @ts-expect-error -- untyped | ||
import output from '../src/file.custom' | ||
|
||
test('custom file loads fine', () => { | ||
expect(output).toMatch('Custom file loaded!') | ||
}) |
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,23 @@ | ||
import { expect } from 'vitest' | ||
import { readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('{ all: true } includes uncovered files', async () => { | ||
await runVitest({ | ||
workspace: 'fixtures/configs/vitest.workspace.multi-transforms.ts', | ||
coverage: { | ||
all: false, | ||
extension: ['.ts', '.custom'], | ||
reporter: ['json', 'html'], | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
const files = coverageMap.files() | ||
|
||
expect(files).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/src/file.custom", | ||
"<process-cwd>/fixtures/src/math.ts", | ||
] | ||
`) | ||
}) |