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.
test: failing test for vitest-dev#7379
- Loading branch information
1 parent
12eaf3e
commit ac25a5e
Showing
8 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
export async function sumInBackground(a: number, b: number) { | ||
const worker = new Worker(new URL('./worker', import.meta.url), { | ||
type: 'module', | ||
}); | ||
|
||
|
||
const promise = new Promise<MessageEvent>(resolve => { | ||
worker.onmessage = resolve; | ||
}); | ||
|
||
function uncovered() { | ||
return "This is uncovered" | ||
} | ||
|
||
worker.postMessage({ a, b }); | ||
|
||
const result = await promise; | ||
covered(); | ||
worker.terminate(); | ||
|
||
return result.data; | ||
} | ||
|
||
|
||
function covered() { | ||
return "This is covered" | ||
} | ||
|
||
export function uncovered() { | ||
return "This is 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,25 @@ | ||
self.onmessage = (ev: MessageEvent) => { | ||
const {a, b} = ev.data; | ||
|
||
if (a === 5) { | ||
uncovered() | ||
throw new Error("uncovered"); | ||
} | ||
|
||
if(b === 6) { | ||
uncovered() | ||
throw new Error("uncovered"); | ||
|
||
} | ||
|
||
covered(); | ||
postMessage(a + b); | ||
}; | ||
|
||
export function uncovered() { | ||
return "This is uncovered" | ||
} | ||
|
||
function covered() { | ||
return "This is 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'; | ||
import { sumInBackground } from '../src/worker-wrapper'; | ||
|
||
test('run a Worker', async () => { | ||
const result = await sumInBackground(15, 7); | ||
|
||
expect(result).toBe(22); | ||
}); |
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,67 @@ | ||
import { expect } from 'vitest' | ||
import { formatSummary, isV8Provider, readCoverageMap, runVitest, test } from '../utils' | ||
|
||
test('web worker coverage is correct', async () => { | ||
await runVitest({ | ||
setupFiles: ['@vitest/web-worker'], | ||
include: ['fixtures/test/web-worker.test.ts'], | ||
environment: 'jsdom', | ||
coverage: { | ||
include: [ | ||
// Runs in web-worker's runner with custom context -> execution wrapper ~430 chars | ||
'fixtures/src/worker.ts', | ||
|
||
// Runs in default runner -> execution wrapper ~185 chars | ||
'fixtures/src/worker-wrapper.ts', | ||
], | ||
reporter: 'json', | ||
}, | ||
}) | ||
|
||
const coverageMap = await readCoverageMap() | ||
const worker = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/worker.ts') | ||
const wrapper = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/worker-wrapper.ts') | ||
|
||
const summary = { | ||
[worker.path]: formatSummary(worker.toSummary()), | ||
[wrapper.path]: formatSummary(wrapper.toSummary()), | ||
} | ||
|
||
// Check HTML report if these change unexpectedly | ||
if (isV8Provider()) { | ||
expect(summary).toMatchInlineSnapshot(` | ||
{ | ||
"<process-cwd>/fixtures/src/worker-wrapper.ts": { | ||
"branches": "3/3 (100%)", | ||
"functions": "2/4 (50%)", | ||
"lines": "18/22 (81.81%)", | ||
"statements": "18/22 (81.81%)", | ||
}, | ||
"<process-cwd>/fixtures/src/worker.ts": { | ||
"branches": "2/4 (50%)", | ||
"functions": "2/3 (66.66%)", | ||
"lines": "11/19 (57.89%)", | ||
"statements": "11/19 (57.89%)", | ||
}, | ||
} | ||
`) | ||
} | ||
else { | ||
expect(summary).toMatchInlineSnapshot(` | ||
{ | ||
"<process-cwd>/fixtures/src/worker-wrapper.ts": { | ||
"branches": "0/0 (100%)", | ||
"functions": "3/5 (60%)", | ||
"lines": "9/11 (81.81%)", | ||
"statements": "9/11 (81.81%)", | ||
}, | ||
"<process-cwd>/fixtures/src/worker.ts": { | ||
"branches": "2/4 (50%)", | ||
"functions": "2/3 (66.66%)", | ||
"lines": "7/12 (58.33%)", | ||
"statements": "7/12 (58.33%)", | ||
}, | ||
} | ||
`) | ||
} | ||
}) |
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