Skip to content

Commit

Permalink
Merge pull request #4052 from wasmerio/selenium-tests
Browse files Browse the repository at this point in the history
Selenium-style tests for wasmer.sh
  • Loading branch information
Michael Bryan authored Jul 10, 2023
2 parents 07198b9 + f9d4f16 commit 8f02600
Show file tree
Hide file tree
Showing 8 changed files with 1,811 additions and 8 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:

working-directory: lib/wasi-web
steps:
- name: Checkout code
Expand All @@ -37,6 +36,14 @@ jobs:
with:
toolchain: nightly-2023-05-25

- name: Install wasm-pack
uses: taiki-e/install-action@v2
with:
tool: wasm-pack

- name: Setup Chromedriver
uses: nanasess/setup-chromedriver@v2

- name: Show Rust version
run: rustc --version --verbose

Expand All @@ -46,3 +53,16 @@ jobs:

- name: Check
run: cargo check --verbose --locked

- name: Browser Integration Tests
run: |
set -xe
npm install
npm run build
npm run dev &
NPM_PID=$!
# Give the webpack dev server time to start
sleep 10
cd ../../tests/wasmer-web
cargo test --verbose --locked -- --test-threads=1
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/wasi-web/src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ pub fn start() -> Result<(), JsValue> {
);

let window = web_sys::window().unwrap();

// HACK: Make the xterm terminal publicly accessible so integration tests
// can tap into it
js_sys::Reflect::set(&window, &JsValue::from_str("xterm"), &terminal)?;

let location = window.location().href().unwrap();

let user_agent = USER_AGENT.clone();
Expand Down
36 changes: 35 additions & 1 deletion lib/wasix/src/runtime/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ fn resolve_package(dependency_graph: &DependencyGraph) -> Result<ResolvedPackage
}
}

if entrypoint.is_none() {
// We *still* haven't been able to figure out what the entrypoint for the
// resolved package should be. If there is only one command in the main
// package, let's assume they want to use that.
//
// This works around packages like saghul/quickjs and syrusakbary/cowsay
// which don't specify their entrypoints explicitly.
if let [cmd] = dependency_graph.root_info().commands.as_slice() {
tracing::debug!(
command = cmd.name.as_str(),
"No entrypoint specified. Falling back to the root package's only command.",
);
entrypoint = Some(cmd.name.clone());
}
}

// Note: when resolving filesystem mappings, the first mapping will come
// from the root package and its dependencies will be following. However, we
// actually want things closer to the root package in the dependency tree to
Expand Down Expand Up @@ -699,7 +715,7 @@ mod tests {
package: root.package_id(),
},
},
entrypoint: None,
entrypoint: Some("asdf".to_string()),
filesystem: Vec::new(),
}
);
Expand Down Expand Up @@ -1041,6 +1057,24 @@ mod tests {
);
}

#[tokio::test]
async fn infer_entrypoint_if_unspecified_and_only_one_command_in_root_package() {
let mut builder = RegistryBuilder::new();
builder
.register("root", "1.0.0")
.with_command("root-cmd")
.with_dependency("dep", "=1.0.0");
builder.register("dep", "1.0.0").with_command("entry");
let registry = builder.finish();
let root = builder.get("root", "1.0.0");

let resolution = resolve(&root.package_id(), &root.pkg, &registry)
.await
.unwrap();

assert_eq!(resolution.package.entrypoint.as_deref(), Some("root-cmd"));
}

#[test]
fn cyclic_error_message() {
let cycle = [
Expand Down
Loading

0 comments on commit 8f02600

Please sign in to comment.