File tree Expand file tree Collapse file tree 6 files changed +623
-101
lines changed
Expand file tree Collapse file tree 6 files changed +623
-101
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,13 @@ jobs:
115115 - run : node napi/parser/scripts/fix-wasm-dts.mjs
116116 - run : cargo test --target wasm32-wasip1-threads ${TEST_FLAGS}
117117 - run : git diff --exit-code # Must commit everything
118+ - name : Test wasi in browser
119+ working-directory : napi/parser
120+ run : |
121+ pnpm run exec playwright install chromium
122+ pnpm run build-wasi
123+ pnpm run build-npm-dir
124+ pnpm run test-browser
118125
119126 typos :
120127 name : Spell Check
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ target/
1414/tasks /compat_data /node_modules /
1515/tasks /e2e /node_modules /
1616/npm /* /node_modules
17+ /napi /* /npm-dir
1718
1819# vscode
1920/editors /vscode /.vscode-test /
Original file line number Diff line number Diff line change 66 "scripts" : {
77 "build-dev" : " napi build --no-dts-cache --platform --js bindings.js" ,
88 "build" : " pnpm run build-dev --release" ,
9- "test" : " vitest --typecheck run ./test && tsc" ,
9+ "build-wasi" : " pnpm run build-dev --release --target wasm32-wasip1-threads" ,
10+ "build-npm-dir" : " rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir ." ,
11+ "test" : " vitest --typecheck run ./test/ && tsc" ,
12+ "test-browser" : " vitest -c vitest.config.browser.mts" ,
1013 "bench" : " vitest bench --run ./bench.bench.mjs"
1114 },
1215 "engines" : {
4851 },
4952 "devDependencies" : {
5053 "@codspeed/vitest-plugin" : " ^4.0.0" ,
54+ "@napi-rs/wasm-runtime" : " ^0.2.7" ,
55+ "@vitest/browser" : " 3.0.7" ,
56+ "playwright" : " ^1.51.0" ,
5157 "vitest" : " catalog:"
5258 },
5359 "napi" : {
Original file line number Diff line number Diff line change 1+ import { expect , test } from 'vitest' ;
2+ import { parseAsync , parseSync } from '../wasm.mjs' ;
3+
4+ test ( 'parseSync' , ( ) => {
5+ const result = parseSync ( 'test.js' , 'ok' ) ;
6+ expect ( result . program ) . toMatchInlineSnapshot ( `
7+ {
8+ "body": [
9+ {
10+ "end": 2,
11+ "expression": {
12+ "end": 2,
13+ "name": "ok",
14+ "start": 0,
15+ "type": "Identifier",
16+ },
17+ "start": 0,
18+ "type": "ExpressionStatement",
19+ },
20+ ],
21+ "end": 2,
22+ "hashbang": null,
23+ "sourceType": "module",
24+ "start": 0,
25+ "type": "Program",
26+ }
27+ ` ) ;
28+ } ) ;
29+
30+ test ( 'parseAsync' , async ( ) => {
31+ const result = await parseAsync ( 'test.js' , 'ok' ) ;
32+ expect ( result . program ) . toMatchInlineSnapshot ( `
33+ {
34+ "body": [
35+ {
36+ "end": 2,
37+ "expression": {
38+ "end": 2,
39+ "name": "ok",
40+ "start": 0,
41+ "type": "Identifier",
42+ },
43+ "start": 0,
44+ "type": "ExpressionStatement",
45+ },
46+ ],
47+ "end": 2,
48+ "hashbang": null,
49+ "sourceType": "module",
50+ "start": 0,
51+ "type": "Program",
52+ }
53+ ` ) ;
54+ } ) ;
Original file line number Diff line number Diff line change 1+ import path from 'node:path' ;
2+ import { defineConfig } from 'vitest/config' ;
3+
4+ export default defineConfig ( {
5+ test : {
6+ dir : 'test-browser' ,
7+ browser : {
8+ enabled : true ,
9+ provider : 'playwright' ,
10+ instances : [
11+ {
12+ browser : 'chromium' ,
13+ } ,
14+ ] ,
15+ } ,
16+ } ,
17+ resolve : {
18+ alias : {
19+ '@oxc-parser/binding-wasm32-wasi' : path . resolve ( 'npm-dir/wasm32-wasi' ) ,
20+ } ,
21+ } ,
22+ server : {
23+ headers : {
24+ 'Cross-Origin-Embedder-Policy' : 'require-corp' ,
25+ 'Cross-Origin-Opener-Policy' : 'same-origin' ,
26+ } ,
27+ } ,
28+ } ) ;
You can’t perform that action at this time.
0 commit comments