Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectScripts.test.ts

73 lines2.0 KB

1import { describe, expect, it } from "vitest";
2​
3import {
4 commandForProjectScript,
5 nextProjectScriptId,
6 primaryProjectScript,
7 projectScriptRuntimeEnv,
8 projectScriptIdFromCommand,
9 setupProjectScript,
10} from "./projectScripts";
11​
12describe("projectScripts helpers", () => {
13 it("builds and parses script run commands", () => {
14 const command = commandForProjectScript("lint");
15 expect(command).toBe("script.lint.run");
16 expect(projectScriptIdFromCommand(command)).toBe("lint");
17 expect(projectScriptIdFromCommand("terminal.toggle")).toBeNull();
18 });
19​
20 it("slugifies and dedupes project script ids", () => {
21 expect(nextProjectScriptId("Run Tests", [])).toBe("run-tests");
22 expect(nextProjectScriptId("Run Tests", ["run-tests"])).toBe("run-tests-2");
23 expect(nextProjectScriptId("!!!", [])).toBe("script");
24 });
25​
26 it("resolves primary and setup scripts", () => {
27 const scripts = [
28 {
29 id: "setup",
30 name: "Setup",
31 command: "bun install",
32 icon: "configure" as const,
33 runOnWorktreeCreate: true,
34 },
35 {
36 id: "test",
37 name: "Test",
38 command: "bun test",
39 icon: "test" as const,
40 runOnWorktreeCreate: false,
41 },
42 ];
43​
44 expect(primaryProjectScript(scripts)?.id).toBe("test");
45 expect(setupProjectScript(scripts)?.id).toBe("setup");
46 });
47​
48 it("builds default runtime env for scripts", () => {
49 const env = projectScriptRuntimeEnv({
50 project: { cwd: "/repo" },
51 worktreePath: "/repo/worktree-a",
52 });
53​
54 expect(env).toMatchObject({
55 T3CODE_PROJECT_ROOT: "/repo",
56 T3CODE_WORKTREE_PATH: "/repo/worktree-a",
57 });
58 });
59​
60 it("allows overriding runtime env values", () => {
61 const env = projectScriptRuntimeEnv({
62 project: { cwd: "/repo" },
63 extraEnv: {
64 T3CODE_PROJECT_ROOT: "/custom-root",
65 CUSTOM_FLAG: "1",
66 },
67 });
68​
69 expect(env.T3CODE_PROJECT_ROOT).toBe("/custom-root");
70 expect(env.CUSTOM_FLAG).toBe("1");
71 expect(env.T3CODE_WORKTREE_PATH).toBeUndefined();
72 });
73});