Skip to content

Start testing TypeScript output on CI #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions crates/typescript-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pkg
dist
11 changes: 11 additions & 0 deletions crates/typescript-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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']
11 changes: 11 additions & 0 deletions crates/typescript-tests/index.ts
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 9 additions & 0 deletions crates/typescript-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"tsc": "tsc"
},
"devDependencies": {
"@types/webassembly-js-api": "0.0.2",
"typescript": "^3.3.3333"
}
}
18 changes: 18 additions & 0 deletions crates/typescript-tests/run.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions crates/typescript-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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) {}
}
14 changes: 14 additions & 0 deletions crates/typescript-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": "."
},
"include": [
"index.ts"
]
}