Skip to content

Commit 0f89748

Browse files
committed
feat(coverage/transpile): compare error message
1 parent ebb6eb8 commit 0f89748

File tree

3 files changed

+377
-147
lines changed

3 files changed

+377
-147
lines changed

tasks/coverage/src/typescript/meta.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl TestCaseContent {
165165
pub struct Baseline {
166166
pub name: String,
167167
pub original: String,
168-
pub original_diagnostic: String,
168+
pub original_diagnostic: Vec<String>,
169169
pub oxc_printed: String,
170170
pub oxc_diagnostics: Vec<OxcDiagnostic>,
171171
}
@@ -218,7 +218,11 @@ impl BaselineFile {
218218
let mut files: Vec<Baseline> = vec![];
219219
let mut is_diagnostic = false;
220220

221-
for line in s.lines() {
221+
let mut lines = s.lines().peekable();
222+
loop {
223+
let Some(line) = lines.next() else {
224+
break;
225+
};
222226
if let Some(remain) = line.strip_prefix("//// [") {
223227
is_diagnostic = remain.starts_with("Diagnostics reported]");
224228
if !is_diagnostic {
@@ -229,8 +233,14 @@ impl BaselineFile {
229233
}
230234
let last = files.last_mut().unwrap();
231235
if is_diagnostic {
232-
last.original_diagnostic.push_str(line);
233-
last.original_diagnostic.push_str("\r\n");
236+
// Skip details of the diagnostic
237+
if line.is_empty() {
238+
while lines.peek().is_some_and(|l| l.strip_prefix("//// [").is_none()) {
239+
lines.next();
240+
}
241+
continue;
242+
}
243+
last.original_diagnostic.push(line.to_string());
234244
} else {
235245
last.original.push_str(line);
236246
last.original.push_str("\r\n");

tasks/coverage/src/typescript/transpile_runner.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,24 @@ impl TypeScriptTranspileCase {
119119
}
120120

121121
for (base, expected) in baseline.files.iter().zip(expected.files) {
122-
if base.oxc_printed != expected.oxc_printed {
123-
return TestResult::Mismatch(base.oxc_printed.clone(), expected.oxc_printed);
122+
if expected.original_diagnostic.is_empty() {
123+
if base.oxc_printed != expected.oxc_printed {
124+
return TestResult::Mismatch(base.oxc_printed.clone(), expected.oxc_printed);
125+
}
126+
} else {
127+
let matched = base.oxc_diagnostics.iter().zip(expected.original_diagnostic).all(
128+
|(base_diagnostic, expected_diagnostic)| {
129+
expected_diagnostic.contains(&base_diagnostic.to_string())
130+
},
131+
);
132+
if !matched {
133+
let snapshot = format!("\n#### {:?} ####\n{}", self.path, baseline.snapshot());
134+
return TestResult::CorrectError(snapshot, false);
135+
}
124136
}
125137
}
126138

127-
let snapshot = format!("\n#### {:?} ####\n{}", self.path, baseline.snapshot());
128-
TestResult::CorrectError(snapshot, false)
139+
TestResult::Passed
129140
}
130141

131142
fn run_kind(&self, _kind: TranspileKind) -> BaselineFile {
@@ -146,7 +157,7 @@ impl TypeScriptTranspileCase {
146157
let baseline = Baseline {
147158
name: change_extension(&unit.name),
148159
original: unit.content.clone(),
149-
original_diagnostic: String::new(),
160+
original_diagnostic: Vec::default(),
150161
oxc_printed: source_text,
151162
oxc_diagnostics: errors,
152163
};

0 commit comments

Comments
 (0)