-
-
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): v8 to warn instead of crash when conversion fails (#6318)
- Loading branch information
1 parent
0848f23
commit daff16c
Showing
5 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require("./target"); | ||
module.exports = "Entry here" |
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 @@ | ||
{ | ||
"name": "cjs-package", | ||
"main": "./entry.js", | ||
"type": "commonjs" | ||
} |
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 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
debug: 0, | ||
info: 1, | ||
warn: 2, | ||
error: 3, | ||
fatal: 4, | ||
}; |
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,40 @@ | ||
import { createRequire } from 'node:module' | ||
import { expect } from 'vitest' | ||
import { coverageTest, normalizeURL, readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('logs warning but doesn\'t crash when coverage conversion fails', async () => { | ||
const { stderr, exitCode } = await runVitest({ | ||
include: [normalizeURL(import.meta.url)], | ||
coverage: { reporter: 'json', include: ['fixtures/src/**'], all: false }, | ||
}, { throwOnError: false }) | ||
|
||
// Logged warning should not set erroneous exit code | ||
expect(exitCode).toBe(0) | ||
|
||
expect(stderr).toMatch('Failed to convert coverage for file://') | ||
expect(stderr).toMatch('/fixtures/src/cjs-package/target.js.') | ||
expect(stderr).toMatch('TypeError: Cannot read properties of undefined (reading \'endCol\')') | ||
|
||
const coverageMap = await readCoverageMap() | ||
|
||
expect(coverageMap.files()).toMatchInlineSnapshot(` | ||
[ | ||
"<process-cwd>/fixtures/src/cjs-package/entry.js", | ||
"<process-cwd>/fixtures/src/cjs-package/target.js", | ||
] | ||
`) | ||
}) | ||
|
||
coverageTest('load file both from Vite and outside it', async () => { | ||
const entry = createRequire(import.meta.url)('../fixtures/src/cjs-package' as any) | ||
const target = await import('../fixtures/src/cjs-package/target.js' as any) | ||
|
||
expect(entry).toBe('Entry here') | ||
expect(target.default).toStrictEqual({ | ||
debug: 0, | ||
error: 3, | ||
fatal: 4, | ||
info: 1, | ||
warn: 2, | ||
}) | ||
}) |