mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-16 14:31:22 +00:00
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:
@ -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",
|
||||
|
@ -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
2
crates/typescript-tests/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
pkg
|
||||
dist
|
11
crates/typescript-tests/Cargo.toml
Normal file
11
crates/typescript-tests/Cargo.toml
Normal 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']
|
11
crates/typescript-tests/index.ts
Normal file
11
crates/typescript-tests/index.ts
Normal 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();
|
9
crates/typescript-tests/package.json
Normal file
9
crates/typescript-tests/package.json
Normal 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
18
crates/typescript-tests/run.sh
Executable 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
|
20
crates/typescript-tests/src/lib.rs
Normal file
20
crates/typescript-tests/src/lib.rs
Normal 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) {}
|
||||
}
|
14
crates/typescript-tests/tsconfig.json
Normal file
14
crates/typescript-tests/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user