Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions crates/swc_cli_impl/tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,55 @@ fn issue_4017_watch_out_file_rebuilds_single_output() -> Result<()> {
Ok(())
}

#[test]
fn issue_10524_watch_out_file_overwrites_rebuilt_output() -> Result<()> {
let sandbox = TempDir::new()?;
let source_path = sandbox.path().join("simple.js");
let output_path = sandbox.path().join("output.js");

fs::write(&source_path, "console.log(\"Hello, world!!\");\n")?;

let mut cmd = cli()?;
cmd.current_dir(&sandbox)
.arg("compile")
.arg("--watch")
.arg("--out-file")
.arg("output.js")
.arg("simple.js");

let mut child = spawn_watch_command(&mut cmd)?;

wait_for("initial out-file watch output", || {
Ok(fs::read_to_string(&output_path)
.map(|content| content.contains("Hello, world!!"))
.unwrap_or(false))
})?;
wait_for("watch process to stay alive", || {
Ok(child.try_wait()?.is_none())
})?;

fs::write(&source_path, "console.log(\"Hello, world 2!!\");\n")?;

wait_for("rebuilt out-file output", || {
Ok(fs::read_to_string(&output_path)
.map(|content| content.contains("Hello, world 2!!"))
.unwrap_or(false))
})?;

let output = fs::read_to_string(&output_path)?;
assert!(
!output.contains("Hello, world!!"),
"Expected rebuilt out-file output to drop stale content. Got: {output}"
);
assert_eq!(
output.matches("console.log").count(),
1,
"Expected rebuilt out-file output to be overwritten, not appended. Got: {output}"
);

Ok(())
}

#[test]
fn issue_4017_watch_out_file_drops_deleted_explicit_inputs() -> Result<()> {
let sandbox = TempDir::new()?;
Expand Down
Loading