Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Feb 3, 2024
1 parent 750eaf9 commit c88d8ad
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 7 deletions.
9 changes: 2 additions & 7 deletions crates/migrate-turborepo/src/migrate_turborepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,22 @@ impl TurboMigrator {
for dep in global_deps {
implicit_inputs.push(InputPath::from_str(&dep)?);
}

self.global_config_modified = true;
}

if let Some(global_dot_env) = turbo_json.global_dot_env.take() {
for env_file in global_dot_env {
implicit_inputs.push(InputPath::from_str(&env_file)?);
}

self.global_config_modified = true;
}

if let Some(global_env) = turbo_json.global_env.take() {
for env in global_env {
implicit_inputs.push(InputPath::EnvVar(env.to_owned()));
}

self.global_config_modified = true;
}

if !implicit_inputs.is_empty() {
self.global_config_modified = true;
self.global_config
.implicit_inputs
.get_or_insert(vec![])
Expand Down Expand Up @@ -237,7 +232,7 @@ impl TurboMigrator {
continue;
}

// task
// ~:task
deps.push(Target::parse(dep).map_err(map_miette_error)?);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
projects:
- "packages/*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["client#build"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
projects:
- "packages/*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"client#build": {
"dependsOn": ["^build"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tasks:
lint:
command: "eslint"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
projects:
- "packages/*"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
projects:
- "packages/*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"//#build": {
"cache": true,
"persistent": false
}
}
}
54 changes: 54 additions & 0 deletions crates/migrate-turborepo/tests/migrate_turborepo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,58 @@ mod migrate_turborepo {
assert_snapshot!(fs::read_to_string(sandbox.path().join("client/moon.yml")).unwrap());
assert_snapshot!(fs::read_to_string(sandbox.path().join("server/moon.yml")).unwrap());
}

#[test]
fn converts_to_a_root_project() {
let sandbox = create_sandbox("root-project");
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
});

assert!(!sandbox.path().join("turbo.json").exists());
assert!(!sandbox.path().join(".moon/tasks/node.yml").exists());
assert!(sandbox.path().join("moon.yml").exists());

assert_snapshot!(fs::read_to_string(sandbox.path().join("moon.yml")).unwrap());
}

#[test]
fn merges_with_existing_root_tasks() {
let sandbox = create_sandbox("root-merge-existing");
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
});

assert_snapshot!(fs::read_to_string(sandbox.path().join(".moon/tasks/node.yml")).unwrap());
}

#[test]
#[should_panic(expected = "Unable to migrate task for package client.")]
fn errors_if_a_task_points_to_an_unknown_project() {
let sandbox = create_sandbox("error-missing-project");
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
});
}

#[test]
#[should_panic(expected = "Unable to migrate task for package client.")]
fn errors_if_a_dependson_points_to_an_unknown_project() {
let sandbox = create_sandbox("error-missing-project-deps");
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/migrate-turborepo/tests/migrate_turborepo_test.rs
expression: "fs::read_to_string(sandbox.path().join(\"moon.yml\")).unwrap()"
---
language: javascript
platform: node
tasks:
build:
command: npm run build

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/migrate-turborepo/tests/migrate_turborepo_test.rs
expression: "fs::read_to_string(sandbox.path().join(\".moon/tasks/node.yml\")).unwrap()"
---
tasks:
build:
command: pnpm run build
deps:
- ^:build
outputs:
- dist/**/*
lint:
command: eslint

0 comments on commit c88d8ad

Please sign in to comment.