Skip to content

Commit b6eb78e

Browse files
committed
browser
1 parent e20e043 commit b6eb78e

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

packages/test/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
"main": "index.js",
77
"devDependencies": {
88
"@tybys/wasm-util": "^0.8.3",
9+
"@vitest/browser-playwright": "^4.1.2",
910
"chalk": "^4.1.2",
1011
"cmake-js": "^7.3.0",
1112
"cross-env": "^7.0.3",
1213
"memfs-browser": "^3.5.10302",
1314
"nan": "^2.22.2",
1415
"node-addon-api": "8.6.0",
1516
"tap": "~0.7.1",
17+
"vite-plugin-node-polyfills": "^0.26.0",
18+
"vitest": "^4.1.2",
1619
"why-is-node-running": "^2.3.0"
1720
},
1821
"type": "commonjs",
@@ -36,7 +39,8 @@
3639
"test:wasm32": "cross-env NODE_TEST_KNOWN_GLOBALS=0 EMNAPI_TEST_WASM32=1 UV_THREADPOOL_SIZE=2 node ./script/test.js",
3740
"test:wasm32r": "cross-env NODE_TEST_KNOWN_GLOBALS=0 EMNAPI_TEST_WASM32=1 UV_THREADPOOL_SIZE=2 NODE_ENV=production node ./script/test.js",
3841
"test:n": "cross-env NODE_TEST_KNOWN_GLOBALS=0 EMNAPI_TEST_NATIVE=1 UV_THREADPOOL_SIZE=2 node ./script/test.js",
39-
"test:nr": "cross-env NODE_TEST_KNOWN_GLOBALS=0 EMNAPI_TEST_NATIVE=1 UV_THREADPOOL_SIZE=2 NODE_ENV=production node ./script/test.js"
42+
"test:nr": "cross-env NODE_TEST_KNOWN_GLOBALS=0 EMNAPI_TEST_NATIVE=1 UV_THREADPOOL_SIZE=2 NODE_ENV=production node ./script/test.js",
43+
"test:browser": "vitest run"
4044
},
4145
"repository": {
4246
"type": "git",

packages/test/vitest.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { defineConfig } from 'vitest/config'
2+
import { playwright } from '@vitest/browser-playwright'
3+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
4+
5+
export default defineConfig({
6+
server: {
7+
headers: {
8+
"Cross-Origin-Embedder-Policy": "require-corp",
9+
"Cross-Origin-Opener-Policy": "same-origin"
10+
}
11+
},
12+
plugins: [
13+
nodePolyfills({
14+
include: ['assert'],
15+
globals: {
16+
Buffer: true, // can also be 'build', 'dev', or false
17+
global: true,
18+
process: true,
19+
},
20+
overrides: {
21+
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
22+
fs: 'memfs-browser',
23+
},
24+
protocolImports: true,
25+
}),
26+
],
27+
test: {
28+
include: [
29+
'./**/*.{test,spec}.browser.js',
30+
],
31+
browser: {
32+
enabled: true,
33+
provider: playwright(),
34+
// https://vitest.dev/config/browser/playwright
35+
instances: [
36+
{ browser: 'chromium' }
37+
],
38+
},
39+
},
40+
})

0 commit comments

Comments
 (0)