From dd84b9d64fb98746a230cd24233ff50a562c39c9 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 28 Apr 2023 01:36:44 +0800 Subject: --- .../turbo-ignore/__tests__/getWorkspace.test.ts | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 packages/turbo-ignore/__tests__/getWorkspace.test.ts (limited to 'packages/turbo-ignore/__tests__/getWorkspace.test.ts') 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' + ); + }); +}); -- cgit v1.2.3-70-g09d2