Skip to content

Commit 0e607dd

Browse files
authored
fix: updates jest in deploy-web to 30.x (#2179)
1 parent 95fc847 commit 0e607dd

File tree

6 files changed

+2469
-208
lines changed

6 files changed

+2469
-208
lines changed

apps/deploy-web/jest.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const createJestConfig = nextJest({
66
dir: "./"
77
});
88

9-
const common: Config.InitialOptions = {
9+
const common = {
1010
moduleNameMapper: {
1111
"^@src(.*)$": "<rootDir>/src/$1",
1212
"^@tests(.*)$": "<rootDir>/tests/$1"
1313
},
1414
transform: {
15-
"\\.tsx?$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
15+
"\\.tsx?$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }] as Config.TransformerConfig
1616
}
17-
};
17+
} satisfies Config.InitialProjectOptions;
1818

1919
const styleMockPath = "<rootDir>/../../node_modules/next/dist/build/jest/__mocks__/styleMock.js";
2020
const getConfig = createJestConfig({

apps/deploy-web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@
166166
"eslint": "^8.57.0",
167167
"eslint-config-next": "^14.2.3",
168168
"eslint-plugin-simple-import-sort": "^12.1.0",
169-
"jest": "^29.7.0",
170-
"jest-environment-jsdom": "^29.7.0",
169+
"jest": "^30.2.0",
170+
"jest-environment-jsdom": "^30.2.0",
171171
"jest-junit": "^16.0.0",
172172
"jest-mock-extended": "^4.0.0-beta1",
173173
"nock": "^13.5.0",

apps/deploy-web/src/components/onboarding/OnboardingContainer/OnboardingContainer.spec.tsx

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("OnboardingContainer", () => {
137137
});
138138

139139
it("should handle fromSignup URL parameter", async () => {
140-
const { child, mockAnalyticsService, cleanup } = setup({
140+
const { child, mockAnalyticsService } = setup({
141141
windowLocation: {
142142
search: "?fromSignup=true",
143143
href: "http://localhost/onboarding?fromSignup=true",
@@ -159,9 +159,6 @@ describe("OnboardingContainer", () => {
159159

160160
// The component should be on the EMAIL_VERIFICATION step after handling fromSignup
161161
expect(child.mock.calls[child.mock.calls.length - 1][0].currentStep).toBe(OnboardingStepIndex.EMAIL_VERIFICATION);
162-
163-
// Clean up window object modifications
164-
cleanup();
165162
});
166163

167164
function setup(
@@ -182,32 +179,24 @@ describe("OnboardingContainer", () => {
182179
});
183180

184181
// Store original window objects
185-
const originalLocation = window.location;
186-
const originalHistory = window.history;
182+
let windowLocation = window.location;
183+
let windowHistory = window.history;
187184

188185
// Mock window.location and history based on input
189186
if (input.windowLocation) {
190-
Object.defineProperty(window, "location", {
191-
value: { ...originalLocation, ...input.windowLocation },
192-
writable: true
193-
});
187+
windowLocation = { ...windowLocation, ...input.windowLocation };
194188
} else if (!window.location.search) {
195189
// Set default values if window.location is not already mocked
196-
Object.defineProperty(window, "location", {
197-
value: {
198-
href: "http://localhost/onboarding",
199-
origin: "http://localhost",
200-
search: ""
201-
},
202-
writable: true
203-
});
190+
windowLocation = {
191+
...windowLocation,
192+
href: "http://localhost/onboarding",
193+
origin: "http://localhost",
194+
search: ""
195+
};
204196
}
205197

206198
if (input.windowHistory) {
207-
Object.defineProperty(window, "history", {
208-
value: { ...originalHistory, ...input.windowHistory },
209-
writable: true
210-
});
199+
windowHistory = { ...windowHistory, ...input.windowHistory };
211200
}
212201

213202
const mockAnalyticsService = mock<AnalyticsService>();
@@ -245,7 +234,9 @@ describe("OnboardingContainer", () => {
245234
authService,
246235
chainApiHttpClient: mockChainApiHttpClient,
247236
deploymentLocalStorage: mockDeploymentLocalStorage,
248-
appConfig: mockAppConfig
237+
appConfig: mockAppConfig,
238+
windowLocation,
239+
windowHistory
249240
});
250241
const mockUseRouter = jest.fn().mockReturnValue(mockRouter);
251242
const mockUseWallet = jest.fn().mockReturnValue({
@@ -334,18 +325,6 @@ describe("OnboardingContainer", () => {
334325

335326
render(<OnboardingContainer dependencies={dependencies}>{mockChildren}</OnboardingContainer>);
336327

337-
// Return cleanup function to restore original window objects
338-
const cleanup = () => {
339-
Object.defineProperty(window, "location", {
340-
value: originalLocation,
341-
writable: true
342-
});
343-
Object.defineProperty(window, "history", {
344-
value: originalHistory,
345-
writable: true
346-
});
347-
};
348-
349328
return {
350329
child: mockChildren,
351330
mockAnalyticsService,
@@ -366,8 +345,7 @@ describe("OnboardingContainer", () => {
366345
mockNewDeploymentData,
367346
mockValidateDeploymentData,
368347
mockAppendAuditorRequirement,
369-
mockTransactionMessageData,
370-
cleanup
348+
mockTransactionMessageData
371349
};
372350
}
373351
});

apps/deploy-web/src/components/onboarding/OnboardingContainer/OnboardingContainer.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export const OnboardingContainer: React.FunctionComponent<OnboardingContainerPro
6767
const router = d.useRouter();
6868
const { user } = d.useUser();
6969
const { data: paymentMethods = [] } = d.usePaymentMethodsQuery({ enabled: !!user?.stripeCustomerId });
70-
const { analyticsService, urlService, authService, chainApiHttpClient, deploymentLocalStorage, appConfig, errorHandler } = d.useServices();
70+
const { analyticsService, urlService, authService, chainApiHttpClient, deploymentLocalStorage, appConfig, errorHandler, windowLocation, windowHistory } =
71+
d.useServices();
7172
const { hasManagedWallet, isWalletLoading, connectManagedWallet, address, signAndBroadcastTx } = d.useWallet();
7273
const { templates } = d.useTemplates();
7374
const { genNewCertificateIfLocalIsInvalid, updateSelectedCertificate } = d.useCertificate();
@@ -89,7 +90,7 @@ export const OnboardingContainer: React.FunctionComponent<OnboardingContainerPro
8990
}
9091
}
9192

92-
const urlParams = new URLSearchParams(window.location.search);
93+
const urlParams = new URLSearchParams(windowLocation.search);
9394
const fromSignup = urlParams.get("fromSignup");
9495
if (fromSignup === "true") {
9596
analyticsService.track("onboarding_account_created", {
@@ -100,9 +101,9 @@ export const OnboardingContainer: React.FunctionComponent<OnboardingContainerPro
100101
setCurrentStep(OnboardingStepIndex.EMAIL_VERIFICATION);
101102
d.localStorage?.setItem(ONBOARDING_STEP_KEY, OnboardingStepIndex.EMAIL_VERIFICATION.toString());
102103

103-
const newUrl = new URL(window.location.href);
104+
const newUrl = new URL(windowLocation.href);
104105
newUrl.searchParams.delete("fromSignup");
105-
window.history.replaceState({}, "", newUrl.toString());
106+
windowHistory.replaceState({}, "", newUrl.toString());
106107
}
107108
}, [analyticsService, d.localStorage]);
108109

@@ -163,7 +164,7 @@ export const OnboardingContainer: React.FunctionComponent<OnboardingContainerPro
163164
handleStepChange(OnboardingStepIndex.EMAIL_VERIFICATION);
164165
}
165166
} else {
166-
authService.signup({ returnTo: `${window.location.origin}${urlService.onboarding(true)}` });
167+
authService.signup({ returnTo: `${windowLocation.origin}${urlService.onboarding(true)}` });
167168
}
168169
}, [analyticsService, handleStepComplete, urlService, user, handleStepChange, authService]);
169170

apps/deploy-web/src/services/app-di-container/browser-di-container.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ export const services = createChildContainer(rootContainer, {
5555
appConfig: () => browserEnvConfig,
5656
authService: () => new AuthService(services.urlService, services.internalApiHttpClient),
5757
storedWalletsService: () => walletUtils,
58-
deploymentLocalStorage: () => new DeploymentStorageService(localStorage, services.networkStore)
58+
deploymentLocalStorage: () => new DeploymentStorageService(localStorage, services.networkStore),
59+
windowLocation: () => window.location,
60+
windowHistory: () => window.history
5961
});

0 commit comments

Comments
 (0)