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
This commit is contained in:
Alex Crichton
2019-03-05 08:33:27 -08:00
parent f161717afe
commit 235bc7c889
9 changed files with 96 additions and 2 deletions

View File

@ -53,9 +53,10 @@ wasm-bindgen-test-crate-b = { path = 'tests/crates/b', version = '0.1' }
members = [
"crates/cli",
"crates/js-sys",
"crates/macro/ui-tests",
"crates/test",
"crates/test/sample",
"crates/macro/ui-tests",
"crates/typescript-tests",
"crates/web-sys",
"crates/webidl",
"crates/webidl-tests",
@ -64,8 +65,8 @@ members = [
"examples/char",
"examples/closures",
"examples/console_log",
"examples/duck-typed-interfaces",
"examples/dom",
"examples/duck-typed-interfaces",
"examples/fetch",
"examples/guide-supported-types-examples",
"examples/hello_world",

View File

@ -119,6 +119,14 @@ jobs:
echo "##vso[task.setvariable variable=PATH;]$PATH:$PWD"
- script: cargo test -p wasm-bindgen-wasm-interpreter
- job: test_typescript_output
displayName: "Test TypeScript output of wasm-bindgen"
steps:
- template: ci/azure-install-rust.yml
- template: ci/azure-install-sccache.yml
- template: ci/azure-install-node.yml
- script: cd crates/typescript-tests && ./run.sh
- job: build_examples
displayName: "Build almost all examples"
steps:

2
crates/typescript-tests/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
pkg
dist

View File

@ -0,0 +1,11 @@
[package]
name = "typescript-tests"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
[dependencies]
wasm-bindgen = { path = '../..' }
[lib]
crate-type = ['cdylib']

View File

@ -0,0 +1,11 @@
import * as wbg from './pkg/typescript_tests';
import * as wasm from './pkg/typescript_tests_bg';
const a1: (a: string) => void = wbg.greet;
const a2: (a: number, b: number) => void = wasm.greet;
const a3: WebAssembly.Memory = wasm.memory;
const c = new wbg.A();
wbg.A.other();
c.foo();
c.free();

View File

@ -0,0 +1,9 @@
{
"scripts": {
"tsc": "tsc"
},
"devDependencies": {
"@types/webassembly-js-api": "0.0.2",
"typescript": "^3.3.3333"
}
}

18
crates/typescript-tests/run.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
set -ex
cargo build --target wasm32-unknown-unknown
rm -rf pkg
mkdir pkg
cargo run -p wasm-bindgen-cli --bin wasm-bindgen -- \
../../target/wasm32-unknown-unknown/debug/typescript_tests.wasm \
--out-dir pkg \
--typescript
if [ ! -d node_modules ]; then
npm install
fi
npm run tsc

View File

@ -0,0 +1,20 @@
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn greet(_: &str) {}
#[wasm_bindgen]
struct A {
}
#[wasm_bindgen]
impl A {
#[wasm_bindgen(constructor)]
pub fn new() -> A {
A {}
}
pub fn other() {}
pub fn foo(&self) {}
}

View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": "."
},
"include": [
"index.ts"
]
}