|
| 1 | +import { it, expect, describe } from "vitest"; |
| 2 | +import { WorkspaceConfiguration } from "vscode"; |
| 3 | +import { getGlobalFlags } from "./globalFlags"; |
| 4 | + |
| 5 | +describe("Global flags suite", () => { |
| 6 | + it("should return empty array when no global flags configured", () => { |
| 7 | + const config = { |
| 8 | + get: () => undefined, |
| 9 | + } as unknown as WorkspaceConfiguration; |
| 10 | + |
| 11 | + expect(getGlobalFlags(config, "")).toStrictEqual([]); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should return global flags from config", () => { |
| 15 | + const config = { |
| 16 | + get: (key: string) => |
| 17 | + key === "coder.globalFlags" |
| 18 | + ? ["--verbose", "--disable-direct-connections"] |
| 19 | + : undefined, |
| 20 | + } as unknown as WorkspaceConfiguration; |
| 21 | + |
| 22 | + expect(getGlobalFlags(config, "")).toStrictEqual([ |
| 23 | + "--verbose", |
| 24 | + "--disable-direct-connections", |
| 25 | + ]); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should filter out '--global-config' flags", () => { |
| 29 | + const config = { |
| 30 | + get: (key: string) => |
| 31 | + key === "coder.globalFlags" |
| 32 | + ? [ |
| 33 | + "-v", |
| 34 | + "--global-config=/path/to/config", |
| 35 | + "--disable-direct-connections", |
| 36 | + ] |
| 37 | + : undefined, |
| 38 | + } as unknown as WorkspaceConfiguration; |
| 39 | + |
| 40 | + expect(getGlobalFlags(config, "")).toStrictEqual([ |
| 41 | + "-v", |
| 42 | + "--disable-direct-connections", |
| 43 | + ]); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should add '--global-config' args when configDir provided", () => { |
| 47 | + const config = { |
| 48 | + get: (key: string) => |
| 49 | + key === "coder.globalFlags" |
| 50 | + ? ["-v", '--global-config "/ignored/path"'] |
| 51 | + : undefined, |
| 52 | + } as unknown as WorkspaceConfiguration; |
| 53 | + |
| 54 | + expect(getGlobalFlags(config, "/path/to/config")).toStrictEqual([ |
| 55 | + "-v", |
| 56 | + "--global-config", |
| 57 | + '"/path/to/config"', |
| 58 | + ]); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should filter out '--header-command' when header args present", () => { |
| 62 | + const config = { |
| 63 | + get: (key: string) => { |
| 64 | + if (key === "coder.headerCommand") { |
| 65 | + return "echo test"; |
| 66 | + } |
| 67 | + if (key === "coder.globalFlags") { |
| 68 | + return ["-v", "--header-command=custom", "--no-feature-warning"]; |
| 69 | + } |
| 70 | + return undefined; |
| 71 | + }, |
| 72 | + } as unknown as WorkspaceConfiguration; |
| 73 | + |
| 74 | + const result = getGlobalFlags(config, ""); |
| 75 | + expect(result).toStrictEqual([ |
| 76 | + "-v", |
| 77 | + "--no-feature-warning", |
| 78 | + "--header-command", |
| 79 | + "'echo test'", |
| 80 | + ]); |
| 81 | + }); |
| 82 | +}); |
0 commit comments