From df5a54277b89ce27d0fe06c7c6dec15f8e563e0c Mon Sep 17 00:00:00 2001 From: nicholaslyang Date: Tue, 30 Jul 2024 17:06:40 -0400 Subject: [PATCH] Added tests --- turborepo-tests/integration/tests/affected.t | 63 +++++++++++++++++++ turborepo-tests/integration/tests/no-args.t | 2 + .../integration/tests/turbo-help.t | 5 ++ 3 files changed, 70 insertions(+) create mode 100644 turborepo-tests/integration/tests/affected.t diff --git a/turborepo-tests/integration/tests/affected.t b/turborepo-tests/integration/tests/affected.t new file mode 100644 index 00000000000000..6652d087cad489 --- /dev/null +++ b/turborepo-tests/integration/tests/affected.t @@ -0,0 +1,63 @@ +Setup + $ . ${TESTDIR}/../../helpers/setup_integration_test.sh + +Create a new branch + $ git checkout -b my-branch + Switched to a new branch 'my-branch' + +Edit and commit a file that affects `my-app` + $ echo "foo" >> apps/my-app/index.js + $ git add . + $ git commit -m "add foo" --quiet + +Validate that we only run `my-app#build` + $ ${TURBO} run build --affected + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache miss, executing 97b34acb6e848096 + my-app:build: + my-app:build: > build + my-app:build: > echo building + my-app:build: + my-app:build: building + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + + + +Now do some magic to change the repo to be shallow + $ SHALLOW=$(git rev-parse --show-toplevel)/.git/shallow + $ git rev-parse HEAD > "$SHALLOW" + $ git reflog expire --expire=0 + $ git prune + $ git prune-packed + +Now try running `--affected` again, we should run all tasks + $ ${TURBO} run build --affected + WARNING unable to detect git range, assuming all files have changed: git error: fatal: main...HEAD: no merge base + + \xe2\x80\xa2 Packages in scope: //, another, my-app, util (esc) + \xe2\x80\xa2 Running build in 4 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + util:build: cache miss, executing bf1798d3e46e1b48 + my-app:build: cache hit, replaying logs 97b34acb6e848096 + my-app:build: + my-app:build: > build + my-app:build: > echo building + my-app:build: + my-app:build: building + util:build: + util:build: > build + util:build: > echo building + util:build: + util:build: building + + Tasks: 2 successful, 2 total + Cached: 1 cached, 2 total + Time:\s*[\.0-9]+m?s (re) + + + diff --git a/turborepo-tests/integration/tests/no-args.t b/turborepo-tests/integration/tests/no-args.t index 0d74331d3fdeee..c61a5560c0f02e 100644 --- a/turborepo-tests/integration/tests/no-args.t +++ b/turborepo-tests/integration/tests/no-args.t @@ -100,6 +100,8 @@ Make sure exit code is 2 when no args are passed Environment variable mode. Use "loose" to pass the entire existing environment. Use "strict" to use an allowlist specified in turbo.json [possible values: loose, strict] -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference/run#--filter + --affected + Run only tasks that are affected by changes between the current branch and `main` --output-logs Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full) [possible values: full, none, hash-only, new-only, errors-only] --log-order diff --git a/turborepo-tests/integration/tests/turbo-help.t b/turborepo-tests/integration/tests/turbo-help.t index ef6fdc5d3c4dee..ad648a6d66f53e 100644 --- a/turborepo-tests/integration/tests/turbo-help.t +++ b/turborepo-tests/integration/tests/turbo-help.t @@ -100,6 +100,8 @@ Test help flag Environment variable mode. Use "loose" to pass the entire existing environment. Use "strict" to use an allowlist specified in turbo.json [possible values: loose, strict] -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference/run#--filter + --affected + Run only tasks that are affected by changes between the current branch and `main` --output-logs Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full) [possible values: full, none, hash-only, new-only, errors-only] --log-order @@ -275,6 +277,9 @@ Test help flag -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference/run#--filter + --affected + Run only tasks that are affected by changes between the current branch and `main` + --output-logs Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full)