Skip to content

Commit 40f9325

Browse files
author
Jerry Green
committed
Add integrated tests for wasm imports and newly generated .d.ts
1 parent dcbc597 commit 40f9325

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@
7676
"check:config": "tsc --noEmit -p src --diagnostics --listFiles",
7777
"check:require": "tsc --noEmit --target ESNEXT --module commonjs --experimentalDecorators tests/require/index",
7878
"check:lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .",
79-
"test": "npm run test:parser && npm run test:compiler && npm run test:packages && npm run test:extension && npm run test:asconfig",
79+
"test": "npm run test:parser && npm run test:compiler && npm run test:packages && npm run test:extension && npm run test:asconfig && npm run test:imports",
8080
"test:parser": "node tests/parser",
8181
"test:compiler": "node --experimental-wasi-unstable-preview1 tests/compiler",
8282
"test:packages": "cd tests/packages && npm run test",
8383
"test:extension": "cd tests/extension && npm run test",
8484
"test:asconfig": "cd tests/asconfig && npm run test",
85+
"test:imports": "cd tests/imports && npm run test",
8586
"make": "npm run clean && npm test && npm run build && npm test",
8687
"all": "npm run check && npm run make",
8788
"docs": "typedoc --tsconfig tsconfig-docs.json --mode modules --name \"AssemblyScript Compiler API\" --out ./docs/api --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeExternals --exclude **/std/** --includeDeclarations --readme src/README.md",

src/asconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@
1414
"untouched": {
1515
"binaryFile": "../out/assemblyscript.untouched.wasm",
1616
"textFile": "../out/assemblyscript.untouched.wast",
17-
"tsdFile": "../out/assemblyscript.d.ts",
17+
"tsdFile": "../out/assemblyscript.untouched.wasm.d.ts",
1818
"debug": true
1919
},
2020
"optimized": {
2121
"binaryFile": "../out/assemblyscript.optimized.wasm",
2222
"textFile": "../out/assemblyscript.optimized.wast",
23-
"tsdFile": "../out/assemblyscript.d.ts",
23+
"tsdFile": "../out/assemblyscript.optimized.wasm.d.ts",
2424
"optimizeLevel": 3,
2525
"shrinkLevel": 0
2626
},
2727
"rtraced": {
2828
"binaryFile": "../out/assemblyscript.rtraced.wasm",
2929
"textFile": "../out/assemblyscript.rtraced.wast",
30-
"tsdFile": "../out/assemblyscript.d.ts",
30+
"tsdFile": "../out/assemblyscript.rtraced.wasm.d.ts",
3131
"debug": true,
3232
"use": "ASC_RTRACE=1",
3333
"runPasses": []
3434
},
3535
"untouched-bootstrap": {
3636
"binaryFile": "../out/assemblyscript.untouched-bootstrap.wasm",
3737
"textFile": "../out/assemblyscript.untouched-bootstrap.wast",
38-
"tsdFile": "../out/assemblyscript.d.ts",
38+
"tsdFile": "../out/assemblyscript.untouched-bootstrap.wasm.d.ts",
3939
"debug": true
4040
},
4141
"optimized-bootstrap": {
4242
"binaryFile": "../out/assemblyscript.optimized-bootstrap.wasm",
4343
"textFile": "../out/assemblyscript.optimized-bootstrap.wast",
44-
"tsdFile": "../out/assemblyscript.d.ts",
44+
"tsdFile": "../out/assemblyscript.optimized-bootstrap.wasm.d.ts",
4545
"optimizeLevel": 3,
4646
"shrinkLevel": 0
4747
}

tests/imports/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js
2+
*.wasm*

tests/imports/add.as

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function add(a: i32, b: i32): i32 {
2+
return a + b
3+
}

tests/imports/dynamic-import.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
;(async () => {
2+
const wasm = await import('./module.wasm')
3+
4+
const res = wasm.add(1, 2)
5+
if (res !== 3) {
6+
console.error('❌ WASM dynamic import does not work as expected')
7+
process.exit(1)
8+
}
9+
console.log('✔️ Can dynamically import wasm module with experimental flag')
10+
})()

tests/imports/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"build": "node ../../bin/asc --extension .as add.as -o module.wasm -d module.wasm.d.ts",
5+
"test": "npm run build && npm run test:static && npm run test:dynamic",
6+
"test:static": "tsc -m es2020 static-import.test.ts && node --experimental-wasm-modules static-import.test.js",
7+
"test:dynamic": "tsc -m es2020 dynamic-import.test.ts && node --experimental-wasm-modules dynamic-import.test.js"
8+
}
9+
}

tests/imports/static-import.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as wasm from './module.wasm'
2+
3+
const res = wasm.add(1, 2)
4+
if (res !== 3) {
5+
console.error('❌ WASM static import does not work as expected')
6+
process.exit(1)
7+
}
8+
9+
console.log('✔️ Can statically import wasm module with experimental flag')

0 commit comments

Comments
 (0)