-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use Vitest public API to work with tests
- Loading branch information
1 parent
f3c3678
commit 989b940
Showing
5 changed files
with
70 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { resolve } from 'pathe' | ||
|
||
export const distDir = resolve(__filename) | ||
export const workerPath = resolve(__dirname, 'worker.mjs') |
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,21 @@ | ||
import { parentPort, workerData } from 'node:worker_threads' | ||
|
||
(async () => { | ||
parentPort!.postMessage({ msg: 'hello from worker', p: workerData.vitestPath }) | ||
try { | ||
const vitestMode = await import(workerData.vitestPath) as typeof import('vitest/node') | ||
const vitest = await vitestMode.createVitest('test', { | ||
watch: false, | ||
root: workerData.root, | ||
}) | ||
parentPort!.postMessage({ msg: 'vitest created' }) | ||
const files = await vitest.globTestFiles() | ||
parentPort!.postMessage({ | ||
files: files.map(([_, spec]) => spec), | ||
}) | ||
await vitest.close() | ||
} | ||
catch (err) { | ||
parentPort!.postMessage({ error: err.message, stack: String(err.stack) }) | ||
Check failure on line 19 in src/worker/worker.ts GitHub Actions / build (20.x)
|
||
} | ||
})() |
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,16 @@ | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig([ | ||
{ | ||
entry: ['./src/extension.ts'], | ||
minify: true, | ||
external: ['vscode'], | ||
format: 'cjs', | ||
}, | ||
{ | ||
entry: ['./src/worker/worker.ts'], | ||
minify: true, | ||
external: ['vitest/node'], | ||
format: 'esm', | ||
}, | ||
]) |