|
| 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 global-config and header args when no global flags configured", () => { |
| 7 | + const config = { |
| 8 | + get: () => undefined, |
| 9 | + } as unknown as WorkspaceConfiguration; |
| 10 | + |
| 11 | + expect(getGlobalFlags(config, "/config/dir")).toStrictEqual([ |
| 12 | + "--global-config", |
| 13 | + '"/config/dir"', |
| 14 | + ]); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should return global flags from config with global-config appended", () => { |
| 18 | + const config = { |
| 19 | + get: (key: string) => |
| 20 | + key === "coder.globalFlags" |
| 21 | + ? ["--verbose", "--disable-direct-connections"] |
| 22 | + : undefined, |
| 23 | + } as unknown as WorkspaceConfiguration; |
| 24 | + |
| 25 | + expect(getGlobalFlags(config, "/config/dir")).toStrictEqual([ |
| 26 | + "--verbose", |
| 27 | + "--disable-direct-connections", |
| 28 | + "--global-config", |
| 29 | + '"/config/dir"', |
| 30 | + ]); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should not filter duplicate global-config flags, last takes precedence", () => { |
| 34 | + const config = { |
| 35 | + get: (key: string) => |
| 36 | + key === "coder.globalFlags" |
| 37 | + ? [ |
| 38 | + "-v", |
| 39 | + "--global-config /path/to/ignored", |
| 40 | + "--disable-direct-connections", |
| 41 | + ] |
| 42 | + : undefined, |
| 43 | + } as unknown as WorkspaceConfiguration; |
| 44 | + |
| 45 | + expect(getGlobalFlags(config, "/config/dir")).toStrictEqual([ |
| 46 | + "-v", |
| 47 | + "--global-config /path/to/ignored", |
| 48 | + "--disable-direct-connections", |
| 49 | + "--global-config", |
| 50 | + '"/config/dir"', |
| 51 | + ]); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should not filter header-command flags, header args appended at end", () => { |
| 55 | + const config = { |
| 56 | + get: (key: string) => { |
| 57 | + if (key === "coder.headerCommand") { |
| 58 | + return "echo test"; |
| 59 | + } |
| 60 | + if (key === "coder.globalFlags") { |
| 61 | + return ["-v", "--header-command custom", "--no-feature-warning"]; |
| 62 | + } |
| 63 | + return undefined; |
| 64 | + }, |
| 65 | + } as unknown as WorkspaceConfiguration; |
| 66 | + |
| 67 | + const result = getGlobalFlags(config, "/config/dir"); |
| 68 | + expect(result).toStrictEqual([ |
| 69 | + "-v", |
| 70 | + "--header-command custom", // ignored by CLI |
| 71 | + "--no-feature-warning", |
| 72 | + "--global-config", |
| 73 | + '"/config/dir"', |
| 74 | + "--header-command", |
| 75 | + "'echo test'", |
| 76 | + ]); |
| 77 | + }); |
| 78 | +}); |
0 commit comments