Skip to content

Commit 235bc7c

Browse files
committed
Start testing TypeScript output on CI
This commit starts to add some simple tests for our TypeScript output of the wasm-bindgen CLI, currently just running `tsc` to make sure syntax looks good and types are emitted as expected. This'll hopefully be able to get expanded over time with bug reports as they come in as well as ensure that we don't regress anything in egregious manners! Closes #922
1 parent f161717 commit 235bc7c

File tree

9 files changed

+96
-2
lines changed

9 files changed

+96
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ wasm-bindgen-test-crate-b = { path = 'tests/crates/b', version = '0.1' }
5353
members = [
5454
"crates/cli",
5555
"crates/js-sys",
56+
"crates/macro/ui-tests",
5657
"crates/test",
5758
"crates/test/sample",
58-
"crates/macro/ui-tests",
59+
"crates/typescript-tests",
5960
"crates/web-sys",
6061
"crates/webidl",
6162
"crates/webidl-tests",
@@ -64,8 +65,8 @@ members = [
6465
"examples/char",
6566
"examples/closures",
6667
"examples/console_log",
67-
"examples/duck-typed-interfaces",
6868
"examples/dom",
69+
"examples/duck-typed-interfaces",
6970
"examples/fetch",
7071
"examples/guide-supported-types-examples",
7172
"examples/hello_world",

azure-pipelines.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ jobs:
119119
echo "##vso[task.setvariable variable=PATH;]$PATH:$PWD"
120120
- script: cargo test -p wasm-bindgen-wasm-interpreter
121121

122+
- job: test_typescript_output
123+
displayName: "Test TypeScript output of wasm-bindgen"
124+
steps:
125+
- template: ci/azure-install-rust.yml
126+
- template: ci/azure-install-sccache.yml
127+
- template: ci/azure-install-node.yml
128+
- script: cd crates/typescript-tests && ./run.sh
129+
122130
- job: build_examples
123131
displayName: "Build almost all examples"
124132
steps:

crates/typescript-tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pkg
2+
dist

crates/typescript-tests/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "typescript-tests"
3+
version = "0.1.0"
4+
authors = ["The wasm-bindgen Developers"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
wasm-bindgen = { path = '../..' }
9+
10+
[lib]
11+
crate-type = ['cdylib']

crates/typescript-tests/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as wbg from './pkg/typescript_tests';
2+
import * as wasm from './pkg/typescript_tests_bg';
3+
4+
const a1: (a: string) => void = wbg.greet;
5+
const a2: (a: number, b: number) => void = wasm.greet;
6+
const a3: WebAssembly.Memory = wasm.memory;
7+
8+
const c = new wbg.A();
9+
wbg.A.other();
10+
c.foo();
11+
c.free();

crates/typescript-tests/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"scripts": {
3+
"tsc": "tsc"
4+
},
5+
"devDependencies": {
6+
"@types/webassembly-js-api": "0.0.2",
7+
"typescript": "^3.3.3333"
8+
}
9+
}

crates/typescript-tests/run.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
cargo build --target wasm32-unknown-unknown
6+
7+
rm -rf pkg
8+
mkdir pkg
9+
cargo run -p wasm-bindgen-cli --bin wasm-bindgen -- \
10+
../../target/wasm32-unknown-unknown/debug/typescript_tests.wasm \
11+
--out-dir pkg \
12+
--typescript
13+
14+
if [ ! -d node_modules ]; then
15+
npm install
16+
fi
17+
18+
npm run tsc

crates/typescript-tests/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen]
4+
pub fn greet(_: &str) {}
5+
6+
#[wasm_bindgen]
7+
struct A {
8+
}
9+
10+
#[wasm_bindgen]
11+
impl A {
12+
#[wasm_bindgen(constructor)]
13+
pub fn new() -> A {
14+
A {}
15+
}
16+
17+
pub fn other() {}
18+
19+
pub fn foo(&self) {}
20+
}

crates/typescript-tests/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"esModuleInterop": true,
5+
"target": "es6",
6+
"noImplicitAny": true,
7+
"sourceMap": true,
8+
"outDir": "dist",
9+
"baseUrl": "."
10+
},
11+
"include": [
12+
"index.ts"
13+
]
14+
}

0 commit comments

Comments
 (0)