-
Notifications
You must be signed in to change notification settings - Fork 105
Checkout swc-plugin test fixture stderr files with Unix newlines for Windows #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: turbo-disable-tests
Are you sure you want to change the base?
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| if let Ok(entries) = fs::read_dir(&test_dir) { | ||
| for entry in entries.flatten() { | ||
| let path = entry.path(); | ||
| if path.is_dir() { | ||
| // Look for .stderr files in subdirectories | ||
| if let Ok(sub_entries) = fs::read_dir(&path) { | ||
| for sub_entry in sub_entries.flatten() { | ||
| let sub_path = sub_entry.path(); | ||
| if sub_path.extension().and_then(|s| s.to_str()) == Some("stderr") { | ||
| if let Ok(mut content) = fs::read_to_string(&sub_path) { | ||
| // On Windows, normalize line endings to LF | ||
| // SWC's error handler outputs LF even on Windows | ||
| // but Git may check out files with CRLF due to autocrlf | ||
| content = content | ||
| .replace("\r\n", "\n") // Normalize CRLF to LF | ||
| .replace("\r", "\n"); // Handle old Mac-style CR | ||
| // Write back with LF line endings | ||
| let _ = fs::write(&sub_path, content); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalize_stderr_files() function only normalizes .stderr files one level deep under tests/errors/, but the fixture pattern allows input files at arbitrary nesting depths (e.g., tests/errors/**/input.js). This means .stderr files in deeply nested directories won't be normalized on Windows, causing test failures.
View Details
📝 Patch Details
diff --git a/packages/swc-plugin-workflow/transform/tests/errors.rs b/packages/swc-plugin-workflow/transform/tests/errors.rs
index 01c42d5..016f186 100644
--- a/packages/swc-plugin-workflow/transform/tests/errors.rs
+++ b/packages/swc-plugin-workflow/transform/tests/errors.rs
@@ -23,31 +23,31 @@ fn normalize_stderr_files() {
// This ensures we have the correct path regardless of where the test runs from
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let test_dir = PathBuf::from(manifest_dir).join("tests/errors");
- if let Ok(entries) = fs::read_dir(&test_dir) {
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- // Look for .stderr files in subdirectories
- if let Ok(sub_entries) = fs::read_dir(&path) {
- for sub_entry in sub_entries.flatten() {
- let sub_path = sub_entry.path();
- if sub_path.extension().and_then(|s| s.to_str()) == Some("stderr") {
- if let Ok(mut content) = fs::read_to_string(&sub_path) {
- // On Windows, normalize line endings to LF
- // SWC's error handler outputs LF even on Windows
- // but Git may check out files with CRLF due to autocrlf
- content = content
- .replace("\r\n", "\n") // Normalize CRLF to LF
- .replace("\r", "\n"); // Handle old Mac-style CR
- // Write back with LF line endings
- let _ = fs::write(&sub_path, content);
- }
- }
+
+ fn normalize_dir_recursive(dir: &PathBuf) {
+ if let Ok(entries) = fs::read_dir(dir) {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if path.is_dir() {
+ // Recursively process subdirectories to handle arbitrary nesting depths
+ normalize_dir_recursive(&path);
+ } else if path.extension().and_then(|s| s.to_str()) == Some("stderr") {
+ if let Ok(mut content) = fs::read_to_string(&path) {
+ // On Windows, normalize line endings to LF
+ // SWC's error handler outputs LF even on Windows
+ // but Git may check out files with CRLF due to autocrlf
+ content = content
+ .replace("\r\n", "\n") // Normalize CRLF to LF
+ .replace("\r", "\n"); // Handle old Mac-style CR
+ // Write back with LF line endings
+ let _ = fs::write(&path, content);
}
}
}
}
}
+
+ normalize_dir_recursive(&test_dir);
});
}
}
Analysis
Recursive .stderr file normalization for Windows test compatibility
What fails: The normalize_stderr_files() function in packages/swc-plugin-workflow/transform/tests/errors.rs uses non-recursive directory traversal and only finds .stderr files one level deep (e.g., tests/errors/<category>/*.stderr), while the fixture pattern tests/errors/**/input.js allows test files at arbitrary nesting depths. This causes deeply nested .stderr files to be missed during normalization.
How to reproduce:
-
Create a deeply nested test structure:
tests/errors/ category/ subcategory/ input.js output-step.stderr -
On Windows with Git's
core.autocrlf=true, the.stderrfile is checked out with CRLF line endings (\r\n) -
Run the tests - the comparison will fail
Result: The unnormalized CRLF line endings in the deeply nested .stderr file don't match SWC's LF output, causing test failures: actual output (LF) != expected file (CRLF). Tests pass on Unix systems because both have LF.
Expected: The normalize_stderr_files() function should recursively traverse all subdirectories under tests/errors/ to normalize line endings in .stderr files at any nesting depth, matching the behavior of the **/ fixture pattern. This ensures consistent test behavior across Windows and Unix systems regardless of Git's core.autocrlf setting.
Fix applied: Refactored normalize_stderr_files() to use a nested recursive helper function normalize_dir_recursive() that walks the entire directory tree instead of stopping after one level. The fix maintains all existing functionality while handling nested test structures.

TL;DR
Added
.gitattributesfile to enforce LF line endings for.stderrtest files.What changed?
Created a new
.gitattributesfile that specifies.stderrfiles should always use LF line endings regardless of the operating system.How to test?
.stderrfileWhy make this change?
This ensures consistent line endings for
.stderrtest files across different operating systems, which prevents test failures that might occur due to line ending differences between platforms (particularly Windows vs Unix-based systems).