diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-ignore/__tests__/getComparison.test.ts | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'packages/turbo-ignore/__tests__/getComparison.test.ts')
| -rw-r--r-- | packages/turbo-ignore/__tests__/getComparison.test.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/packages/turbo-ignore/__tests__/getComparison.test.ts b/packages/turbo-ignore/__tests__/getComparison.test.ts new file mode 100644 index 0000000..b5c74c7 --- /dev/null +++ b/packages/turbo-ignore/__tests__/getComparison.test.ts @@ -0,0 +1,61 @@ +import { getComparison } from "../src/getComparison"; +import { spyConsole, mockEnv } from "@turbo/test-utils"; + +describe("getComparison()", () => { + mockEnv(); + const mockConsole = spyConsole(); + it("uses headRelative comparison when not running Vercel CI", async () => { + expect(getComparison({ workspace: "test-workspace" })) + .toMatchInlineSnapshot(` + Object { + "ref": "HEAD^", + "type": "headRelative", + } + `); + }); + + it("returns null when running in Vercel CI with no VERCEL_GIT_PREVIOUS_SHA", async () => { + process.env.VERCEL = "1"; + process.env.VERCEL_GIT_COMMIT_REF = "my-branch"; + expect(getComparison({ workspace: "test-workspace" })).toBeNull(); + expect(mockConsole.log).toHaveBeenCalledWith( + "≫ ", + 'No previous deployments found for "test-workspace" on branch "my-branch".' + ); + }); + + it("uses custom fallback when running in Vercel CI with no VERCEL_GIT_PREVIOUS_SHA", async () => { + process.env.VERCEL = "1"; + process.env.VERCEL_GIT_COMMIT_REF = "my-branch"; + expect(getComparison({ workspace: "test-workspace", fallback: "HEAD^2" })) + .toMatchInlineSnapshot(` + Object { + "ref": "HEAD^2", + "type": "customFallback", + } + `); + expect(mockConsole.log).toHaveBeenNthCalledWith( + 1, + "≫ ", + 'No previous deployments found for "test-workspace" on branch "my-branch".' + ); + expect(mockConsole.log).toHaveBeenNthCalledWith( + 2, + "≫ ", + "Falling back to ref HEAD^2" + ); + }); + + it("uses previousDeploy when running in Vercel CI with VERCEL_GIT_PREVIOUS_SHA", async () => { + process.env.VERCEL = "1"; + process.env.VERCEL_GIT_PREVIOUS_SHA = "mygitsha"; + process.env.VERCEL_GIT_COMMIT_REF = "my-branch"; + expect(getComparison({ workspace: "test-workspace" })) + .toMatchInlineSnapshot(` + Object { + "ref": "mygitsha", + "type": "previousDeploy", + } + `); + }); +}); |