-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
- Loading branch information
1 parent
42bd4a2
commit fbea520
Showing
8 changed files
with
113 additions
and
5 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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
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) { | ||
const filename = id.split("?")[0] | ||
|
||
if(filename.endsWith(".custom")) { | ||
const content = readFileSync(filename, 'utf8') | ||
|
||
const s = new MagicString(content) | ||
s.replaceAll('<function covered>', ` | ||
function covered() { | ||
return "Custom file loaded!" | ||
}`.trim()); | ||
|
||
s.replaceAll('<function uncovered>', ` | ||
function uncovered() { | ||
return "This should be uncovered!" | ||
}`.trim()); | ||
|
||
s.replaceAll('<default export covered>', 'export default covered()'); | ||
s.replaceAll('<default export uncovered>', 'export default uncovered()'); | ||
|
||
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,3 @@ | ||
<function uncovered> | ||
|
||
<default export uncovered> |
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/covered.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
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,25 @@ | ||
import { expect } from 'vitest' | ||
import { readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('{ all: true } includes uncovered files that require custom transform', async () => { | ||
await runVitest({ | ||
workspace: 'fixtures/configs/vitest.workspace.multi-transforms.ts', | ||
coverage: { | ||
all: true, | ||
extension: ['.ts', '.custom'], | ||
reporter: 'json', | ||
include: ['**/*.custom', '**/math.ts'], | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
const files = coverageMap.files() | ||
|
||
expect(files).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/src/covered.custom", | ||
"<process-cwd>/fixtures/src/math.ts", | ||
"<process-cwd>/fixtures/src/uncovered.custom", | ||
] | ||
`) | ||
}) |