Skip to content

Commit be58d6d

Browse files
committed
test(language_server): fix test for ServerFormatter in windows (#14210)
The language server formatter tests were failing on Windows due to line ending differences between platforms. This caused snapshot test mismatches, leading to the test being disabled on Windows. The fix ensures that during tests on Windows, source files are normalized to use LF line endings, making the formatting results consistent with Linux snapshots and allowing the test to run successfully on all platforms. `FormatOptions::line_ending` default value is LF ending, changing it only for windows will still result into snapshot changes.
1 parent 39a171e commit be58d6d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/oxc_language_server/src/formatter/server_formatter.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ impl ServerFormatter {
2121
let source_text = if let Some(content) = content {
2222
content
2323
} else {
24-
std::fs::read_to_string(&path).ok()?
24+
#[cfg(not(all(test, windows)))]
25+
let source_text = std::fs::read_to_string(&path).ok()?;
26+
#[cfg(all(test, windows))]
27+
#[expect(clippy::disallowed_methods)] // no `cow_replace` in tests are fine
28+
// On Windows, convert CRLF to LF for consistent formatting results
29+
let source_text = std::fs::read_to_string(&path).ok()?.replace("\r\n", "\n");
30+
source_text
2531
};
2632

2733
let allocator = Allocator::new();
@@ -191,7 +197,6 @@ mod tests {
191197
}
192198

193199
#[test]
194-
#[cfg(not(windows))] // FIXME: snapshot differs on Windows. Possible newline issue?
195200
fn test_formatter() {
196201
Tester::new("fixtures/formatter/basic", Some(FormatOptions { experimental: true }))
197202
.format_and_snapshot_single_file("basic.ts");

0 commit comments

Comments
 (0)