BridgeJS: show unified diff on snapshot mismatch#600
Conversation
There was a problem hiding this comment.
Pull request overview
Improves BridgeJS snapshot test failure diagnostics by emitting an .actual file and including a unified diff in the test failure message to make mismatches easier to inspect.
Changes:
- Write
<snapshot>.actualon mismatch and include adiff -uunified diff in the expectation message. - Add a helper to run
diffviaProcessand capture its output.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let process = Process() | ||
| process.executableURL = URL(fileURLWithPath: "/usr/bin/env") | ||
| process.arguments = ["diff", "-u", expectedPath, actualPath] | ||
| let output = Pipe() | ||
| process.standardOutput = output | ||
| process.standardError = Pipe() | ||
|
|
||
| do { | ||
| try process.run() | ||
| } catch { | ||
| return nil | ||
| } | ||
| process.waitUntilExit() | ||
|
|
||
| let data = output.fileHandleForReading.readDataToEndOfFile() |
There was a problem hiding this comment.
unifiedDiff runs diff with Pipe() output but waits for the process to exit before reading. If the unified diff is large enough to fill the pipe buffer, the child process can block on write and waitUntilExit() can hang the test run. Consider draining stdout/stderr while the process runs (e.g., readabilityHandler like invokeTS2Swift does) or redirecting output to a temporary file and reading it after exit.
| let output = Pipe() | ||
| process.standardOutput = output | ||
| process.standardError = Pipe() | ||
|
|
||
| do { | ||
| try process.run() | ||
| } catch { | ||
| return nil | ||
| } | ||
| process.waitUntilExit() |
There was a problem hiding this comment.
process.standardError is set to a Pipe() but never read. This can both drop useful error output (e.g., diff errors) and has the same pipe-buffer deadlock risk as stdout. Either read stderr as well, or redirect stderr to stdout / a file, and consider checking terminationStatus (0=same, 1=different, 2=error) to decide what to return.
Motivation
Snapshot failures only reported file paths, making it slow to see what changed.
Overview
Enhance BridgeJS snapshot assertion to write the .actual file, run
diff -u, and include the unified diff in the expectation message.