Changesets · Branches · Tags · Compare
| Changeset | 60acd6c5ca132bab7f1de25f8789fa5f7d0eb2d2c9ccb06080b79c76ebcd173f |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-24 18:51 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-24 18:51 -07:00 |
| Parents | c4ec337463d8 |
4 files changed
modified extensions/cli/src/auth/workos-org.test.ts +8 −3
| @@ -13,6 +13,10 @@ | ||
| 13 | 13 | })), |
| 14 | 14 | })); |
| 15 | 15 | |
| 16 | +vi.mock("../init.js", () => ({ | |
| 17 | + safeStderr: vi.fn(), | |
| 18 | +})); | |
| 19 | + | |
| 16 | 20 | vi.mock("fs", () => ({ |
| 17 | 21 | default: { |
| 18 | 22 | existsSync: vi.fn(() => false), |
| @@ -91,7 +95,8 @@ | ||
| 91 | 95 | |
| 92 | 96 | describe("Mode restriction", () => { |
| 93 | 97 | test("should reject --org flag in interactive mode", async () => { |
| 94 | - const consoleErrorSpy = vi.spyOn(console, "error"); | |
| 98 | + const { safeStderr } = await import("../init.js"); | |
| 99 | + const safeStderrSpy = vi.mocked(safeStderr); | |
| 95 | 100 | const processExitSpy = vi |
| 96 | 101 | .spyOn(process, "exit") |
| 97 | 102 | .mockImplementation(() => { |
| @@ -102,9 +107,9 @@ | ||
| 102 | 107 | ensureOrganization(mockAuthConfig, false, "org-one"), |
| 103 | 108 | ).rejects.toThrow("Process exit"); |
| 104 | 109 | |
| 105 | - expect(consoleErrorSpy).toHaveBeenCalledWith( | |
| 110 | + expect(safeStderrSpy).toHaveBeenCalledWith( | |
| 106 | 111 | chalk.red( |
| 107 | - "The --org flag is only supported in headless mode (with -p/--print flag)", | |
| 112 | + "The --org flag is only supported in headless mode (with -p/--print flag)\n", | |
| 108 | 113 | ), |
| 109 | 114 | ); |
| 110 | 115 | expect(processExitSpy).toHaveBeenCalledWith(1); |
modified extensions/cli/src/hubLoader.test.ts +0 −2
| @@ -71,7 +71,6 @@ | ||
| 71 | 71 | })); |
| 72 | 72 | } else { |
| 73 | 73 | // If mock doesn't work, skip this test |
| 74 | - console.log("JSZip mock not working, skipping test"); | |
| 75 | 74 | return; |
| 76 | 75 | } |
| 77 | 76 | |
| @@ -121,7 +120,6 @@ | ||
| 121 | 120 | })); |
| 122 | 121 | } else { |
| 123 | 122 | // If mock doesn't work, skip this test |
| 124 | - console.log("JSZip mock not working, skipping test"); | |
| 125 | 123 | return; |
| 126 | 124 | } |
| 127 | 125 |
modified extensions/cli/src/hubLoader.ts +4 −2
| @@ -231,9 +231,11 @@ | ||
| 231 | 231 | |
| 232 | 232 | // If it looks like a file path |
| 233 | 233 | if ( |
| 234 | - ruleSpec.includes(".") || | |
| 234 | + ruleSpec.startsWith(".") || | |
| 235 | + ruleSpec.startsWith("/") || | |
| 235 | 236 | ruleSpec.includes("/") || |
| 236 | - ruleSpec.includes("\\") | |
| 237 | + ruleSpec.includes("\\") || | |
| 238 | + /\.[a-zA-Z]+$/.test(ruleSpec) // Has file extension at the end | |
| 237 | 239 | ) { |
| 238 | 240 | const fs = await import("fs"); |
| 239 | 241 | const path = await import("path"); |
modified extensions/cli/src/loadMcpFromHub.test.ts +10 −3
| @@ -1,10 +1,10 @@ | ||
| 1 | -import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | 2 | |
| 3 | 3 | import { loadMcpFromHub } from "./args.js"; |
| 4 | 4 | |
| 5 | -// Mock fetch globally | |
| 5 | +// Store original fetch to restore later | |
| 6 | +const originalFetch = global.fetch; | |
| 6 | 7 | const mockFetch = vi.fn(); |
| 7 | -global.fetch = mockFetch; | |
| 8 | 8 | |
| 9 | 9 | // Mock JSZip |
| 10 | 10 | vi.mock("jszip", () => { |
| @@ -18,12 +18,19 @@ | ||
| 18 | 18 | |
| 19 | 19 | beforeEach(async () => { |
| 20 | 20 | vi.clearAllMocks(); |
| 21 | + // Set mock fetch for each test | |
| 22 | + global.fetch = mockFetch; | |
| 21 | 23 | |
| 22 | 24 | // Get the mocked JSZip constructor |
| 23 | 25 | const JSZip = (await import("jszip")).default; |
| 24 | 26 | mockJSZip = new JSZip(); |
| 25 | 27 | }); |
| 26 | 28 | |
| 29 | + afterEach(() => { | |
| 30 | + // Restore original fetch after each test | |
| 31 | + global.fetch = originalFetch; | |
| 32 | + }); | |
| 33 | + | |
| 27 | 34 | it("should validate slug format", async () => { |
| 28 | 35 | await expect(loadMcpFromHub("invalid-slug")).rejects.toThrow( |
| 29 | 36 | 'Invalid hub slug format. Expected "owner/package", got: invalid-slug', |