Skip to content

Commit ad8d265

Browse files
authored
chore: fix flaky publish::npm_workspace test (#24511)
1 parent a49d0bd commit ad8d265

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

tests/specs/publish/npm_workspace/publish.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Check file:///[WILDLINE]/npm_workspace/subtract/index.ts
44
Checking for slow types in the public API...
55
Check file:///[WILDLINE]/npm_workspace/add/index.ts
66
Check file:///[WILDLINE]/npm_workspace/subtract/index.ts
7+
[UNORDERED_START]
78
Simulating publish of @scope/[email protected] with files:
89
file:///[WILDLINE]/npm_workspace/add/index.ts ([WILDLINE])
910
file:///[WILDLINE]/npm_workspace/add/jsr.json ([WILDLINE])
@@ -12,4 +13,5 @@ Simulating publish of @scope/[email protected] with files:
1213
file:///[WILDLINE]/npm_workspace/subtract/index.ts ([WILDLINE])
1314
file:///[WILDLINE]/npm_workspace/subtract/jsr.json ([WILDLINE])
1415
file:///[WILDLINE]/npm_workspace/subtract/package.json ([WILDLINE])
16+
[UNORDERED_END]
1517
Warning Aborting due to --dry-run

tests/util/server/src/lib.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -846,25 +846,45 @@ pub fn wildcard_match_detailed(
846846
);
847847
return WildcardMatchResult::Fail(output_lines.join("\n"));
848848
}
849-
for (actual, expected) in actual_lines.iter().zip(expected_lines.iter())
849+
850+
if let Some(invalid_expected) =
851+
expected_lines.iter().find(|e| e.contains("[WILDCARD]"))
850852
{
851-
if actual != expected {
853+
panic!(
854+
concat!(
855+
"Cannot use [WILDCARD] inside [UNORDERED_START]. Use [WILDLINE] instead.\n",
856+
" Invalid expected line: {}"
857+
),
858+
invalid_expected
859+
);
860+
}
861+
862+
for actual_line in actual_lines {
863+
let maybe_found_index =
864+
expected_lines.iter().position(|expected_line| {
865+
actual_line == *expected_line
866+
|| wildcard_match(expected_line, actual_line)
867+
});
868+
if let Some(found_index) = maybe_found_index {
869+
let expected = expected_lines.remove(found_index);
870+
output_lines.push(format!(
871+
"<FOUND>{}</FOUND>",
872+
colors::gray(annotate_whitespace(expected))
873+
));
874+
} else {
852875
output_lines
853876
.push("==== UNORDERED LINE DID NOT MATCH ====".to_string());
854877
output_lines.push(format!(
855878
" ACTUAL: {}",
856-
colors::red(annotate_whitespace(actual))
857-
));
858-
output_lines.push(format!(
859-
"EXPECTED: {}",
860-
colors::green(annotate_whitespace(expected))
879+
colors::red(annotate_whitespace(actual_line))
861880
));
881+
for expected in expected_lines {
882+
output_lines.push(format!(
883+
" EXPECTED ANY: {}",
884+
colors::green(annotate_whitespace(expected))
885+
));
886+
}
862887
return WildcardMatchResult::Fail(output_lines.join("\n"));
863-
} else {
864-
output_lines.push(format!(
865-
"<FOUND>{}</FOUND>",
866-
colors::gray(annotate_whitespace(expected))
867-
));
868888
}
869889
}
870890
}

0 commit comments

Comments
 (0)