Skip to content

Commit

Permalink
complete with the ci
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjj27 committed Jan 15, 2021
1 parent 7c61799 commit d05bff1
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/ci.yml
Expand Up @@ -113,15 +113,9 @@ jobs:
command: run
args: --example default

wasm-test:
name: Test wasm support
wasm-prepare:
name: prepare wasm-pack environment
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
browser:
- firefox
- chrome
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -133,5 +127,24 @@ jobs:
version: latest
use-tool-cache: true

- name: Test with browser
run: wasm-pack test --${{ matrix.browser }}
wasm-browser-test:
name: test wasm support for browser
runs-on: ubuntu-latest
needs: wasm-prepare
strategy:
matrix:
browser:
- firefox
- chrome
- safari
steps:
- name: test on browser
run: wasm-pack test --headless --${{ matrix.browser }} -- --test web

wasm-node-test:
name: test wasm support for node
runs-on: ubuntu-latest
needs: wasm-prepare
steps:
- name: test on browser
run: wasm-pack test --node -- --test web
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -49,7 +49,11 @@ name = "init-twice-retains-filter"
harness = false

[[test]]
name = "basic-wasm"
name = "web"
harness = false

[[test]]
name = "node"
harness = false

[features]
Expand Down
41 changes: 41 additions & 0 deletions tests/node.rs
@@ -0,0 +1,41 @@
/*!
Using `env_logger`.
Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`:
```no_run,shell
$ export MY_LOG_LEVEL='info'
```
Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors
or `auto` to enable them:
```no_run,shell
$ export MY_LOG_STYLE=never
```
*/
#![cfg(test)]

use log::{trace, debug, info, warn, error};
use env_logger::Env;

#[cfg(all(target_arch = "wasm32", target_vendor = "unknown"))]
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
fn main() {
// The `Env` lets us tweak what the environment
// variables to read are and what the default
// value is if they're missing
let env = Env::default()
.filter_or("MY_LOG_LEVEL", "trace")
.write_style_or("MY_LOG_STYLE", "always");

env_logger::init_from_env(env);

trace!("some trace log");
debug!("some debug log");
info!("some information log");
warn!("some warning log");
error!("some error log");
}
18 changes: 6 additions & 12 deletions tests/basic-wasm.rs → tests/web.rs
Expand Up @@ -14,15 +14,17 @@ or `auto` to enable them:
$ export MY_LOG_STYLE=never
```
*/
#![cfg(test)]

#[macro_use]
extern crate log;

use log::{trace, debug, info, warn, error};
use env_logger::Env;

#[cfg(all(target_arch = "wasm32", target_vendor = "unknown"))]
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn main() {
// The `Env` lets us tweak what the environment
// variables to read are and what the default
Expand All @@ -39,11 +41,3 @@ fn main() {
warn!("some warning log");
error!("some error log");
}

#[cfg_attr(
all(target_arch = "wasm32", target_vendor = "unknown"),
wasm_bindgen(start)
)]
pub fn start() {
main();
}

0 comments on commit d05bff1

Please sign in to comment.