-
-
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
for uncovered files
- Loading branch information
1 parent
e9f9adc
commit f5e1827
Showing
22 changed files
with
970 additions
and
12 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
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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
import { Plugin, defineWorkspace } from "vitest/config"; | ||
import MagicString from "magic-string"; | ||
import { readFileSync } from "fs"; | ||
|
||
export default defineWorkspace([ | ||
// Project that uses its own "root" and custom transform plugin | ||
{ | ||
test: { | ||
name: "custom-with-root", | ||
root: "fixtures/workspaces/custom-2", | ||
}, | ||
plugins: [customFilePlugin("2")], | ||
}, | ||
|
||
// Project that cannot transform "*.custom-x" files | ||
{ | ||
test: { | ||
name: "normal", | ||
include: ["fixtures/test/math.test.ts"], | ||
}, | ||
}, | ||
|
||
// Project that uses default "root" and has custom transform plugin | ||
{ | ||
test: { | ||
name: "custom", | ||
include: ["fixtures/test/custom-1-syntax.test.ts"], | ||
}, | ||
plugins: [customFilePlugin("1")], | ||
}, | ||
]); | ||
|
||
/** | ||
* Plugin for transforming `.custom-1` and/or `.custom-2` files to Javascript | ||
*/ | ||
function customFilePlugin(postfix: "1" | "2"): Plugin { | ||
function transform(code: MagicString) { | ||
code.replaceAll( | ||
"<function covered>", | ||
` | ||
function covered() { | ||
return "Custom-${postfix} file loaded!" | ||
} | ||
`.trim() | ||
); | ||
|
||
code.replaceAll( | ||
"<function uncovered>", | ||
` | ||
function uncovered() { | ||
return "This should be uncovered!" | ||
} | ||
`.trim() | ||
); | ||
|
||
code.replaceAll("<default export covered>", "export default covered()"); | ||
code.replaceAll("<default export uncovered>", "export default uncovered()"); | ||
} | ||
|
||
return { | ||
name: `custom-${postfix}-file-plugin`, | ||
transform(_, id) { | ||
const filename = id.split("?")[0]; | ||
|
||
if (filename.endsWith(`.custom-${postfix}`)) { | ||
const content = readFileSync(filename, "utf8"); | ||
|
||
const s = new MagicString(content); | ||
transform(s); | ||
|
||
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-1' | ||
|
||
test('custom file loads fine', () => { | ||
expect(output).toMatch('Custom-1 file loaded!') | ||
}) |
5 changes: 5 additions & 0 deletions
5
test/coverage-test/fixtures/workspaces/custom-2/src/covered.custom-2
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> |
3 changes: 3 additions & 0 deletions
3
test/coverage-test/fixtures/workspaces/custom-2/src/uncovered.custom-2
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> |
8 changes: 8 additions & 0 deletions
8
test/coverage-test/fixtures/workspaces/custom-2/test/custom-2-syntax.test.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 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
// @ts-expect-error -- untyped | ||
import output from '../src/covered.custom-2' | ||
|
||
test('custom-2 file loads fine', () => { | ||
expect(output).toMatch('Custom-2 file loaded!') | ||
}) |
83 changes: 83 additions & 0 deletions
83
test/coverage-test/test/__snapshots__/custom-file-covered-1-istanbul.snapshot.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,83 @@ | ||
{ | ||
"path": "<process-cwd>/fixtures/src/covered.custom-1", | ||
"statementMap": { | ||
"0": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 18 | ||
} | ||
}, | ||
"1": { | ||
"start": { | ||
"line": 3, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 20 | ||
} | ||
} | ||
}, | ||
"fnMap": { | ||
"0": { | ||
"name": "covered", | ||
"decl": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 18 | ||
} | ||
}, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 18 | ||
} | ||
} | ||
}, | ||
"1": { | ||
"name": "uncovered", | ||
"decl": { | ||
"start": { | ||
"line": 3, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 20 | ||
} | ||
}, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 20 | ||
} | ||
} | ||
} | ||
}, | ||
"branchMap": {}, | ||
"s": { | ||
"0": 1, | ||
"1": 0 | ||
}, | ||
"f": { | ||
"0": 1, | ||
"1": 0 | ||
}, | ||
"b": {} | ||
} |
Oops, something went wrong.