aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-utils/__tests__
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-utils/__tests__
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'packages/turbo-utils/__tests__')
-rw-r--r--packages/turbo-utils/__tests__/getTurboConfigs.test.ts112
-rw-r--r--packages/turbo-utils/__tests__/getTurboRoot.test.ts33
2 files changed, 145 insertions, 0 deletions
diff --git a/packages/turbo-utils/__tests__/getTurboConfigs.test.ts b/packages/turbo-utils/__tests__/getTurboConfigs.test.ts
new file mode 100644
index 0000000..e61e630
--- /dev/null
+++ b/packages/turbo-utils/__tests__/getTurboConfigs.test.ts
@@ -0,0 +1,112 @@
+import path from "path";
+import getTurboConfigs from "../src/getTurboConfigs";
+import { setupTestFixtures } from "@turbo/test-utils";
+
+describe("getTurboConfigs", () => {
+ const { useFixture } = setupTestFixtures({
+ directory: path.join(__dirname, "../"),
+ test: "common",
+ });
+
+ it("single-package", async () => {
+ const { root } = useFixture({ fixture: `single-package` });
+ const configs = getTurboConfigs(root);
+ expect(configs).toHaveLength(1);
+ expect(configs[0].isRootConfig).toBe(true);
+ expect(configs[0].config).toMatchInlineSnapshot(`
+ Object {
+ "$schema": "https://turbo.build/schema.json",
+ "globalEnv": Array [
+ "UNORDERED",
+ "CI",
+ ],
+ "pipeline": Object {
+ "build": Object {
+ "dependsOn": Array [
+ "^build",
+ ],
+ },
+ "deploy": Object {
+ "dependsOn": Array [
+ "build",
+ "test",
+ "lint",
+ ],
+ "outputs": Array [],
+ },
+ "lint": Object {
+ "outputs": Array [],
+ },
+ "test": Object {
+ "dependsOn": Array [
+ "build",
+ ],
+ "inputs": Array [
+ "src/**/*.tsx",
+ "src/**/*.ts",
+ "test/**/*.ts",
+ "test/**/*.tsx",
+ ],
+ "outputs": Array [],
+ },
+ },
+ }
+ `);
+ });
+
+ it("workspace-configs", async () => {
+ const { root } = useFixture({ fixture: `workspace-configs` });
+ const configs = getTurboConfigs(root);
+
+ expect(configs).toHaveLength(3);
+ expect(configs[0].isRootConfig).toBe(true);
+ expect(configs[0].config).toMatchInlineSnapshot(`
+ Object {
+ "$schema": "https://turbo.build/schema.json",
+ "globalEnv": Array [
+ "CI",
+ ],
+ "pipeline": Object {
+ "build": Object {
+ "env": Array [
+ "ENV_1",
+ ],
+ },
+ },
+ }
+ `);
+ expect(configs[1].isRootConfig).toBe(false);
+ expect(configs[1].config).toMatchInlineSnapshot(`
+ Object {
+ "$schema": "https://turbo.build/schema.json",
+ "extends": Array [
+ "//",
+ ],
+ "pipeline": Object {
+ "build": Object {
+ "env": Array [
+ "ENV_2",
+ ],
+ },
+ },
+ }
+ `);
+
+ expect(configs[2].isRootConfig).toBe(false);
+ expect(configs[2].config).toMatchInlineSnapshot(`
+ Object {
+ "$schema": "https://turbo.build/schema.json",
+ "extends": Array [
+ "//",
+ ],
+ "pipeline": Object {
+ "build": Object {
+ "env": Array [
+ "IS_SERVER",
+ ],
+ },
+ },
+ }
+ `);
+ });
+});
diff --git a/packages/turbo-utils/__tests__/getTurboRoot.test.ts b/packages/turbo-utils/__tests__/getTurboRoot.test.ts
new file mode 100644
index 0000000..acfb0ce
--- /dev/null
+++ b/packages/turbo-utils/__tests__/getTurboRoot.test.ts
@@ -0,0 +1,33 @@
+import path from "path";
+import getTurboRoot from "../src/getTurboRoot";
+import { setupTestFixtures } from "@turbo/test-utils";
+
+describe("getTurboConfigs", () => {
+ const { useFixture } = setupTestFixtures({
+ directory: path.join(__dirname, "../"),
+ test: "common",
+ });
+
+ test.each([[""], ["child"]])(
+ "finds the root in a non-monorepo (%s)",
+ (repoPath) => {
+ const { root } = useFixture({ fixture: `single-package` });
+ const turboRoot = getTurboRoot(path.join(root, repoPath));
+ expect(turboRoot).toEqual(root);
+ }
+ );
+
+ test.each([
+ [""],
+ ["apps"],
+ ["apps/docs"],
+ ["apps/web"],
+ ["packages"],
+ ["packages/ui"],
+ ["not-a-real/path"],
+ ])("finds the root in a monorepo with workspace configs (%s)", (repoPath) => {
+ const { root } = useFixture({ fixture: `workspace-configs` });
+ const turboRoot = getTurboRoot(path.join(root, repoPath));
+ expect(turboRoot).toEqual(root);
+ });
+});