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__/getWorkspace.test.ts | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'packages/turbo-ignore/__tests__/getWorkspace.test.ts')
| -rw-r--r-- | packages/turbo-ignore/__tests__/getWorkspace.test.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/packages/turbo-ignore/__tests__/getWorkspace.test.ts b/packages/turbo-ignore/__tests__/getWorkspace.test.ts new file mode 100644 index 0000000..6d97fe2 --- /dev/null +++ b/packages/turbo-ignore/__tests__/getWorkspace.test.ts @@ -0,0 +1,62 @@ +import { getWorkspace } from "../src/getWorkspace"; +import { spyConsole, validateLogs } from "@turbo/test-utils"; + +describe("getWorkspace()", () => { + const mockConsole = spyConsole(); + it("getWorkspace returns workspace from arg", async () => { + expect( + getWorkspace({ + workspace: "test-workspace", + }) + ).toEqual("test-workspace"); + validateLogs( + ['Using "test-workspace" as workspace from arguments'], + mockConsole.log, + { prefix: "≫ " } + ); + }); + + it("getWorkspace returns workspace from package.json", async () => { + expect( + getWorkspace({ + directory: "./__fixtures__/app", + }) + ).toEqual("test-app"); + expect(mockConsole.log).toHaveBeenCalledWith( + "≫ ", + 'Inferred "test-app" as workspace from "package.json"' + ); + }); + + it("getWorkspace used current directory if not specified", async () => { + expect(getWorkspace({})).toEqual("turbo-ignore"); + expect(mockConsole.log).toHaveBeenCalledWith( + "≫ ", + 'Inferred "turbo-ignore" as workspace from "package.json"' + ); + }); + + it("getWorkspace returns null when no arg is provided and package.json is missing name field", async () => { + expect( + getWorkspace({ + directory: "./__fixtures__/invalid-app", + }) + ).toEqual(null); + expect(mockConsole.error).toHaveBeenCalledWith( + "≫ ", + '"__fixtures__/invalid-app/package.json" is missing the "name" field (required).' + ); + }); + + it("getWorkspace returns null when no arg is provided and package.json can be found", async () => { + expect( + getWorkspace({ + directory: "./__fixtures__/no-app", + }) + ).toEqual(null); + expect(mockConsole.error).toHaveBeenCalledWith( + "≫ ", + '"__fixtures__/no-app/package.json" could not be found. turbo-ignore inferencing failed' + ); + }); +}); |