Skip to content

Commit

Permalink
fix update expect test (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash authored Sep 26, 2024
1 parent 9e76256 commit b214601
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6306,7 +6306,7 @@ fn test_snapshot_test_target_js() {
test "test inspect 2" {
inspect!("c", content="c")
inspect!("d")
inspect!("d", content="d")
}
test "test snapshot 2" (it : @test.T) {
Expand Down
31 changes: 11 additions & 20 deletions crates/moonbuild/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,6 @@ pub fn run_test(
.replace(
"origin_js_path",
&artifact_path.display().to_string().replace("\\", "/"),
)
.replace(
"const testParams = []",
&format!("const testParams = {}", test_args.to_args()),
)
.replace(
"const packageName = \"\"",
&format!("const packageName = {:?}", test_args.package),
);

std::fs::write(&wrapper_js_driver_path, js_driver)?;
Expand Down Expand Up @@ -745,24 +737,13 @@ pub fn run_test(
Ok(r)
}

#[derive(serde::Serialize, Clone)]
#[derive(serde::Serialize, Clone, Debug)]
pub struct TestArgs {
pub package: String,
pub file_and_index: Vec<(String, std::ops::Range<u32>)>,
}

impl TestArgs {
fn to_args(&self) -> String {
let file_and_index = &self.file_and_index;
let mut test_params: Vec<[String; 2]> = vec![];
for (file, index) in file_and_index {
for i in index.clone() {
test_params.push([file.clone(), i.to_string()]);
}
}
format!("{:?}", test_params)
}

fn get_test_cnt(&self) -> u32 {
self.file_and_index
.iter()
Expand Down Expand Up @@ -868,6 +849,11 @@ async fn handle_test_result(
.clone();

let update_msg = match rerun {
// if rerun test success, update the previous test result and continue
Ok(_) => {
*item = rerun;
continue;
}
Err(TestFailedStatus::SnapshotPending(cur_err)) => &[cur_err.message],
_ => &[stat.message.clone()],
};
Expand Down Expand Up @@ -958,6 +944,11 @@ async fn handle_test_result(
.unwrap()
.clone();
let update_msg = match rerun {
// if rerun test success, update the previous test result and continue
Ok(_) => {
*item = rerun;
continue;
}
Err(TestFailedStatus::ExpectTestFailed(cur_err)) => &[cur_err.message],
_ => &[origin_err.message.clone()],
};
Expand Down
14 changes: 12 additions & 2 deletions crates/moonbuild/template/js_driver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const { moonbit_test_driver_internal_execute } = require("origin_js_path");

const packageName = "";
const testParams = [];
let testArgs;
try {
testArgs = JSON.parse(process.argv[2]);
} catch (error) {
console.error("failed to parse args:", error.message);
process.exit(1);
}

const packageName = testArgs.package;
const testParams = testArgs.file_and_index.flatMap(([file, range]) =>
Array.from({length: range.end - range.start}, (_, i) => [file, (range.start + i).toString()])
);

for (param of testParams) {
try {
Expand Down

0 comments on commit b214601

Please sign in to comment.