Add wasm-pack test to github workflows (https://github.com/enso-org/ide/pull/49)

To the test workflow added a step where wasm-pack test is run for each crate in workspace.

A script was added, which runs wasm-pack test for each workspace members, because The wasm-pack itself cannot read workspaces. The script was written in rust, therefore a special crate for build-and-utility-scripts in rust was created.


Original commit: 51d3eaec7e
This commit is contained in:
Adam Obuchowicz 2019-11-25 11:52:51 +01:00 committed by GitHub
parent 846cd870a2
commit a07ad85444
6 changed files with 90 additions and 16 deletions

View File

@ -33,24 +33,42 @@ jobs:
with:
toolchain: nightly-2019-11-04
override: true
- uses: actions-rs/cargo@v1
- uses: nanasess/setup-chromedriver@master
with:
chromedriver-version: '78.0.3904.105'
- name: Install wasm-pack
uses: actions-rs/cargo@v1
with:
command: install
args: wasm-pack
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
- name: Run wasm-pack tests
uses: actions-rs/cargo@v1
with:
command: run
args: >
--manifest-path=script/rust/Cargo.toml
--bin test-all
-- --node --chrome --headless
# fmt:
# name: Formatter
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: nightly-2019-11-04
# override: true
# - run: rustup component add rustfmt
# - uses: actions-rs/cargo@v1
# with:
# command: fmt
# args: --all -- --check
# TODO[AO] formatter does not work
# fmt:
# name: Formatter
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: nightly-2019-11-04
# override: true
# - run: rustup component add rustfmt
# - uses: actions-rs/cargo@v1
# with:
# command: fmt
# args: --all -- --check
clippy:
name: Linter

2
gui/.gitignore vendored
View File

@ -1,8 +1,8 @@
# Rust
/target
/script/rust/target/
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log

View File

@ -21,7 +21,11 @@ console_error_panic_hook = { version = "0.1.1", optional = true }
version = "0.3.4"
features = [
'Document',
'Node',
'Element',
'HtmlElement',
'HtmlCollection',
'CssStyleDeclaration',
'HtmlCanvasElement',
'WebGlBuffer',
'WebGlRenderingContext',

View File

@ -0,0 +1,10 @@
[package]
name = "build-scripts"
version = "0.1.0"
authors = ["Adam Obuchowicz <adam.obuchowicz@luna-lang.org>"]
edition = "2018"
[workspace]
[dependencies]
toml="0.5.5"

View File

@ -0,0 +1,39 @@
fn get_workspace_members(cargo_toml_root : toml::Value) -> Vec<String> {
match &cargo_toml_root["workspace"]["members"] {
toml::Value::Array(list) => list.iter().map(|val| {
match val {
toml::Value::String(s) => s.clone(),
_ => panic!("Workspace member is not a string"),
}
}).collect(),
_ => panic!("Invalid workspace element")
}
}
/// Call wasm-pack test for each workspace member
///
/// This function reads workspace members list from `Cargo.toml` in current
/// directory, and call `wasm-pack test` each member. All script arguments
/// are passed to `wasm-pack` process.
fn main() {
let wasm_pack_args : Vec<String> = std::env::args().skip(1).collect();
let cargo_toml_root = std::fs::read_to_string("Cargo.toml").unwrap()
.parse::<toml::Value>().unwrap();
for member in get_workspace_members(cargo_toml_root) {
println!("Running tests for {}:", member);
let status = std::process::Command::new("wasm-pack")
.arg("test")
.arg(&member)
.args(&wasm_pack_args)
.status()
.unwrap();
if !status.success() {
panic!("Process for {} failed!{}", member, match status.code() {
Some(code) => format!(" Code: {}", code),
None => String::new()
});
}
}
}

3
gui/script/test.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
cargo run --manifest-path=script/rust/Cargo.toml --bin test-all -- \
--node --firefox --chrome --headless