|
| 1 | +import { exposeSourceMapsForDebugging } from "../sourceMapInitializer" |
| 2 | + |
| 3 | +describe("sourceMapInitializer", () => { |
| 4 | + describe("exposeSourceMapsForDebugging", () => { |
| 5 | + let originalNodeEnv: string | undefined |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + originalNodeEnv = process.env.NODE_ENV |
| 9 | + // Clear any existing debugging functions |
| 10 | + delete (window as any).__testSourceMaps |
| 11 | + delete (window as any).__applySourceMaps |
| 12 | + delete (window as any).__checkSourceMap |
| 13 | + }) |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + process.env.NODE_ENV = originalNodeEnv |
| 17 | + // Clean up any debugging functions |
| 18 | + delete (window as any).__testSourceMaps |
| 19 | + delete (window as any).__applySourceMaps |
| 20 | + delete (window as any).__checkSourceMap |
| 21 | + }) |
| 22 | + |
| 23 | + it("should not expose debugging functions in production mode", () => { |
| 24 | + // Set production mode |
| 25 | + process.env.NODE_ENV = "production" |
| 26 | + |
| 27 | + // Call the function |
| 28 | + exposeSourceMapsForDebugging() |
| 29 | + |
| 30 | + // Verify that debugging functions are NOT exposed |
| 31 | + expect((window as any).__testSourceMaps).toBeUndefined() |
| 32 | + expect((window as any).__applySourceMaps).toBeUndefined() |
| 33 | + expect((window as any).__checkSourceMap).toBeUndefined() |
| 34 | + }) |
| 35 | + |
| 36 | + it("should expose debugging functions in development mode", () => { |
| 37 | + // Set development mode |
| 38 | + process.env.NODE_ENV = "development" |
| 39 | + |
| 40 | + // Call the function |
| 41 | + exposeSourceMapsForDebugging() |
| 42 | + |
| 43 | + // Verify that debugging functions ARE exposed |
| 44 | + expect((window as any).__testSourceMaps).toBeDefined() |
| 45 | + expect((window as any).__applySourceMaps).toBeDefined() |
| 46 | + expect((window as any).__checkSourceMap).toBeDefined() |
| 47 | + expect(typeof (window as any).__testSourceMaps).toBe("function") |
| 48 | + expect(typeof (window as any).__applySourceMaps).toBe("function") |
| 49 | + expect(typeof (window as any).__checkSourceMap).toBe("function") |
| 50 | + }) |
| 51 | + |
| 52 | + it("should expose debugging functions in test mode", () => { |
| 53 | + // Set test mode |
| 54 | + process.env.NODE_ENV = "test" |
| 55 | + |
| 56 | + // Call the function |
| 57 | + exposeSourceMapsForDebugging() |
| 58 | + |
| 59 | + // Verify that debugging functions ARE exposed |
| 60 | + expect((window as any).__testSourceMaps).toBeDefined() |
| 61 | + expect((window as any).__applySourceMaps).toBeDefined() |
| 62 | + expect((window as any).__checkSourceMap).toBeDefined() |
| 63 | + }) |
| 64 | + |
| 65 | + it("should not throw errors when called multiple times in production", () => { |
| 66 | + // Set production mode |
| 67 | + process.env.NODE_ENV = "production" |
| 68 | + |
| 69 | + // Should not throw when called multiple times |
| 70 | + expect(() => { |
| 71 | + exposeSourceMapsForDebugging() |
| 72 | + exposeSourceMapsForDebugging() |
| 73 | + exposeSourceMapsForDebugging() |
| 74 | + }).not.toThrow() |
| 75 | + |
| 76 | + // Functions should still not be exposed |
| 77 | + expect((window as any).__testSourceMaps).toBeUndefined() |
| 78 | + expect((window as any).__applySourceMaps).toBeUndefined() |
| 79 | + expect((window as any).__checkSourceMap).toBeUndefined() |
| 80 | + }) |
| 81 | + }) |
| 82 | +}) |
0 commit comments