-
-
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
99a12ae
commit ae226bd
Showing
14 changed files
with
546 additions
and
11 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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
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()], | ||
}, | ||
]) | ||
|
||
/** | ||
* Plugin for transforming `.custom` files to Javascript | ||
*/ | ||
function customFilePlugin(): Plugin { | ||
return { | ||
name: "custom-file-plugin", | ||
transform(_, id) { | ||
const filename = id.split("?")[0] | ||
|
||
if (filename.endsWith(".custom")) { | ||
const content = readFileSync(filename, "utf8") | ||
|
||
const s = new MagicString(content) | ||
transformCustomLang(s) | ||
|
||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: "boundary" }), | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
|
||
// Syntax of custom-language | ||
function transformCustomLang(code: MagicString) { | ||
code.replaceAll( | ||
"<function covered>", | ||
` | ||
function covered() { | ||
return "Custom 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()") | ||
} |
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!') | ||
}) |
83 changes: 83 additions & 0 deletions
83
test/coverage-test/test/__snapshots__/custom-file-covered-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", | ||
"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.