fix: remove window.location mocking to fix CI test failures
Remove all window.location mocking from AuthDebugger tests as it was causing "Cannot redefine property" errors in CI. The tests work correctly with JSDOM's default window.location implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1fd190fbb7
commit
b08827d94d
1 changed files with 45 additions and 67 deletions
|
|
@ -84,21 +84,6 @@ Object.defineProperty(window, "sessionStorage", {
|
||||||
value: sessionStorageMock,
|
value: sessionStorageMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Try to mock window.location, but don't fail if it doesn't work (e.g., in CI)
|
|
||||||
try {
|
|
||||||
Object.defineProperty(window, "location", {
|
|
||||||
value: {
|
|
||||||
origin: "http://localhost:3000",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// Ignore error - tests that depend on this will be skipped
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip location-dependent tests in CI where window.location mocking fails
|
|
||||||
const isCI = process.env.CI === "true";
|
|
||||||
const skipIfCI = isCI ? it.skip : it;
|
|
||||||
|
|
||||||
describe("AuthDebugger", () => {
|
describe("AuthDebugger", () => {
|
||||||
const defaultAuthState = EMPTY_DEBUGGER_STATE;
|
const defaultAuthState = EMPTY_DEBUGGER_STATE;
|
||||||
|
|
||||||
|
|
@ -113,7 +98,7 @@ describe("AuthDebugger", () => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
sessionStorageMock.getItem.mockReturnValue(null);
|
sessionStorageMock.getItem.mockReturnValue(null);
|
||||||
|
|
||||||
// Supress
|
// Suppress console errors in tests to avoid JSDOM navigation noise
|
||||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||||
|
|
||||||
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
|
||||||
|
|
@ -453,13 +438,9 @@ describe("AuthDebugger", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("OAuth State Persistence", () => {
|
describe("OAuth State Persistence", () => {
|
||||||
skipIfCI(
|
it("should store auth state to sessionStorage before redirect in Quick OAuth Flow", async () => {
|
||||||
"should store auth state to sessionStorage before redirect in Quick OAuth Flow",
|
|
||||||
async () => {
|
|
||||||
const updateAuthState = jest.fn();
|
const updateAuthState = jest.fn();
|
||||||
|
|
||||||
// This test depends on window.location being mocked at the top of the file
|
|
||||||
|
|
||||||
// Setup mocks for OAuth flow
|
// Setup mocks for OAuth flow
|
||||||
mockStartAuthorization.mockResolvedValue({
|
mockStartAuthorization.mockResolvedValue({
|
||||||
authorizationUrl: new URL(
|
authorizationUrl: new URL(
|
||||||
|
|
@ -491,9 +472,7 @@ describe("AuthDebugger", () => {
|
||||||
// Verify the stored state includes all the accumulated data
|
// Verify the stored state includes all the accumulated data
|
||||||
const storedStateCall = (
|
const storedStateCall = (
|
||||||
sessionStorage.setItem as jest.Mock
|
sessionStorage.setItem as jest.Mock
|
||||||
).mock.calls.find(
|
).mock.calls.find((call) => call[0] === SESSION_KEYS.AUTH_DEBUGGER_STATE);
|
||||||
(call) => call[0] === SESSION_KEYS.AUTH_DEBUGGER_STATE,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(storedStateCall).toBeDefined();
|
expect(storedStateCall).toBeDefined();
|
||||||
const storedState = JSON.parse(storedStateCall![1] as string);
|
const storedState = JSON.parse(storedStateCall![1] as string);
|
||||||
|
|
@ -510,8 +489,7 @@ describe("AuthDebugger", () => {
|
||||||
client_id: "test_client_id",
|
client_id: "test_client_id",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("OAuth Protected Resource Metadata", () => {
|
describe("OAuth Protected Resource Metadata", () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue