Skip to content

Commit

Permalink
Add type-only testing
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Nov 13, 2024
1 parent baedfaf commit af0950b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/cli/tests/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
//! // FLAGS: --target=web
//! // FLAGS: --target=nodejs
//! ```
//!
//! ## Testing only types
//!
//! In some cases, we are only interested in testing the generated `.d.ts` file.
//! In this case, add a comment at the top of the test file:
//!
//! ```rust
//! // TYPES ONLY
//! ```
use anyhow::{bail, Result};
use assert_cmd::prelude::*;
Expand Down Expand Up @@ -119,6 +128,8 @@ fn runtest(test: &Path) -> Result<()> {
let root = repo_root();
let root = root.display();

let types_only = contents.contains("// TYPES ONLY");

// parse target declarations
let mut all_flags: Vec<_> = contents
.lines()
Expand Down Expand Up @@ -215,7 +226,7 @@ fn runtest(test: &Path) -> Result<()> {
_ => "reference_test.js",
};

if !contents.contains("async") {
if !types_only {
let js = fs::read_to_string(out_dir.join(main_js_file))?;
assert_same(&js, &test.with_extension("js"))?;
let wat = sanitize_wasm(&out_dir.join("reference_test_bg.wasm"))?;
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/tests/reference/async-number.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TYPES ONLY

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/tests/reference/async-void.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TYPES ONLY

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand Down

0 comments on commit af0950b

Please sign in to comment.