|
| 1 | +use std::fs; |
| 2 | + |
| 3 | +use turborepo_tests::{ |
| 4 | + get_fixture_dir, get_fixture_out_dir, run_fixture_test, run_fixture_test_with_opts, TestFixture, |
| 5 | +}; |
| 6 | + |
| 7 | +#[test] |
| 8 | +fn test_turbo_root_syntax() { |
| 9 | + let fixture = TestFixture::new("turbo_root_syntax", "./fixtures/turbo_root_syntax", None); |
| 10 | + let out_dir = get_fixture_out_dir("turbo_root_syntax"); |
| 11 | + let fixture_dir = get_fixture_dir("turbo_root_syntax"); |
| 12 | + |
| 13 | + // First run - should execute and cache |
| 14 | + run_fixture_test( |
| 15 | + &fixture, |
| 16 | + &["build", "test"], |
| 17 | + &[ |
| 18 | + "build: cache miss, executing", |
| 19 | + "test: cache miss, executing", |
| 20 | + ], |
| 21 | + ); |
| 22 | + |
| 23 | + // Verify files were copied |
| 24 | + assert!(out_dir.join("packages/pkg-a/dist/util.js").exists()); |
| 25 | + assert!(out_dir.join("packages/pkg-a/coverage/setup.js").exists()); |
| 26 | + |
| 27 | + // Delete the output files to test cache restoration |
| 28 | + fs::remove_file(out_dir.join("packages/pkg-a/dist/util.js")).unwrap(); |
| 29 | + fs::remove_file(out_dir.join("packages/pkg-a/coverage/setup.js")).unwrap(); |
| 30 | + |
| 31 | + // Second run - should restore from cache |
| 32 | + run_fixture_test( |
| 33 | + &fixture, |
| 34 | + &["build", "test"], |
| 35 | + &[ |
| 36 | + "build: cache hit, replaying output", |
| 37 | + "test: cache hit, replaying output", |
| 38 | + ], |
| 39 | + ); |
| 40 | + |
| 41 | + // Verify files were restored from cache |
| 42 | + assert!(out_dir.join("packages/pkg-a/dist/util.js").exists()); |
| 43 | + assert!(out_dir.join("packages/pkg-a/coverage/setup.js").exists()); |
| 44 | + |
| 45 | + // Modify a root file |
| 46 | + fs::write( |
| 47 | + fixture_dir.join("shared/util.js"), |
| 48 | + "module.exports = { add: (a, b) => a + b + 1 };", |
| 49 | + ) |
| 50 | + .unwrap(); |
| 51 | + |
| 52 | + // Third run - should execute again due to root file change |
| 53 | + run_fixture_test(&fixture, &["build"], &["build: cache miss, executing"]); |
| 54 | + |
| 55 | + // Verify the new file was copied |
| 56 | + let util_contents = fs::read_to_string(out_dir.join("packages/pkg-a/dist/util.js")).unwrap(); |
| 57 | + assert!(util_contents.contains("a + b + 1")); |
| 58 | +} |
| 59 | + |
| 60 | +#[test] |
| 61 | +fn test_turbo_root_syntax_in_global_deps() { |
| 62 | + let fixture = TestFixture::new("turbo_root_syntax", "./fixtures/turbo_root_syntax", None); |
| 63 | + let fixture_dir = get_fixture_dir("turbo_root_syntax"); |
| 64 | + |
| 65 | + // First run - should execute and cache |
| 66 | + run_fixture_test(&fixture, &["build"], &["build: cache miss, executing"]); |
| 67 | + |
| 68 | + // Create the file referenced in globalDependencies |
| 69 | + fs::create_dir_all(fixture_dir.join("some")).unwrap(); |
| 70 | + fs::write(fixture_dir.join("some/path"), "some content").unwrap(); |
| 71 | + |
| 72 | + // Second run - should execute again due to global dependency change |
| 73 | + run_fixture_test(&fixture, &["build"], &["build: cache miss, executing"]); |
| 74 | +} |
0 commit comments