Skip to content

Commit 09e649c

Browse files
committed
WIP 80826
1 parent cedf66f commit 09e649c

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "turbo-root-syntax-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"workspaces": [
6+
"packages/*"
7+
],
8+
"scripts": {
9+
"build": "echo \"building root\"",
10+
"test": "echo \"testing root\""
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "pkg-a",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "echo \"building pkg-a\" && cp ../../shared/util.js ./dist/",
6+
"test": "echo \"testing pkg-a\" && cp ../../test-utils/setup.js ./coverage/"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
add: (a, b) => a + b,
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
setupTest: () => {
3+
console.log("Setting up test environment");
4+
},
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"globalDependencies": ["$TURBO_ROOT$/some/path"],
4+
"tasks": {
5+
"build": {
6+
"outputs": ["dist/**"],
7+
"inputs": ["$TURBO_ROOT$/shared/**"]
8+
},
9+
"test": {
10+
"outputs": ["coverage/**"],
11+
"inputs": ["$TURBO_ROOT$/test-utils/**"]
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)