chore(deps-dev): bump msw from 2.15.0 to 3.0.8 and move the client tests to it

msw 3 renames onUnhandledRequest to onUnhandledFrame and reports every
network frame there; the setup judges the HTTP frames as before (another
origin is an error, the page's own a warning).

It also resolves a relative handler, and its fetch interceptor a
relative URL, against location.href at the time of the request, while
jsdom's XHR sends to the document's own address. Tests that replaced
window.location with a stand-in on http://localhost while the page runs
on http://localhost:3000 sent their requests past every handler.
tests/helpers/location.ts builds such stand-ins on the page's own origin
(locationAt, pageUrl), and every one of them now uses it.

msw no longer escapes fake timers, and responses are timed differently,
which surfaced tests that ended with work still running: a held request
answering in the next test, a lookup still out when the assertions ran,
a reload switched by counting reads. Each of those now waits for, or
releases, what it started, and answers by what happened rather than by
a count.

The day panel suites share their setup through
tests/helpers/dayDetailPanel.ts instead of a copy each, which keeps the
larger one under its size limit.
This commit is contained in:
Maurice
2026-11-26 13:15:45 +01:00
parent 05f4c84885
commit 32837afe2e
24 changed files with 493 additions and 434 deletions
+4 -2
View File
@@ -1535,8 +1535,10 @@ describe('AdminPage', () => {
const matrixCard = matrixHeading.closest<HTMLElement>('section');
// The matrix switch is named after its event and channel; the card's first
// buttons belong to the webhook and ntfy targets above the matrix.
fireEvent.click(within(matrixCard!).getByRole('button', { name: /, email$/i }));
// buttons belong to the webhook and ntfy targets above the matrix. The card's
// heading renders before the matrix fetch lands (a loading row stands in until
// then), so wait for the switch itself.
fireEvent.click(await within(matrixCard!).findByRole('button', { name: /, email$/i }));
await waitFor(() => {
expect(prefUpdateCalled).toBe(true);
+6 -1
View File
@@ -276,7 +276,10 @@ describe('AtlasPage wiring', () => {
fireEvent.click(screen.getByText('atlas.unmark'));
await waitFor(() => expect(atlas.setConfirmAction).toHaveBeenLastCalledWith(null));
// The cancel above already closed with null, so wait for the unmark's own close:
// it comes only after the region delete and the country check have both answered.
await waitFor(() => expect(atlas.setConfirmAction).toHaveBeenCalledTimes(2));
expect(atlas.setConfirmAction).toHaveBeenLastCalledWith(null);
expect(atlas.visitedRegions).toEqual({});
const data = atlas.data as AtlasData;
expect(data.countries.map((c) => c.code)).toEqual(['FR']);
@@ -379,6 +382,8 @@ describe('AtlasPage wiring', () => {
fireEvent.click(screen.getByText('atlas.addToBucket'));
await waitFor(() => expect(body).toMatchObject({ name: 'Bretagne', country_code: 'FR', target_date: null }));
// Let the post answer and the popup close here, not in the next test.
await waitFor(() => expect(atlas.setConfirmAction).toHaveBeenLastCalledWith(null));
});
it('FE-PAGE-ATLASW-018b: a country already wishlisted for that date is not posted again (#1898)', async () => {
@@ -5,6 +5,7 @@ import React from 'react';
import { MemoryRouter } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { buildAppConfig } from '../../../tests/helpers/factories';
import { locationAt, pageUrl } from '../../../tests/helpers/location';
import { server } from '../../../tests/helpers/msw/server';
import { act, renderHook, waitFor } from '../../../tests/helpers/render';
import { resetAllStores } from '../../../tests/helpers/store';
@@ -54,7 +55,7 @@ beforeEach(() => {
Object.defineProperty(window, 'location', {
configurable: true,
writable: true,
value: { ...realLocation, pathname: '/login', href: 'http://localhost/login', search: '' },
value: locationAt('/login'),
});
});
@@ -78,7 +79,7 @@ describe('useLogin in the native app', () => {
);
const { result } = renderLogin();
await waitFor(() => expect(result.current.appConfig).not.toBeNull());
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
expect(result.current.oidcOnly).toBe(true);
});
+17 -10
View File
@@ -7,6 +7,7 @@ import { http, HttpResponse } from 'msw';
import { server } from '../../../tests/helpers/msw/server';
import { resetAllStores } from '../../../tests/helpers/store';
import { buildAppConfig } from '../../../tests/helpers/factories';
import { locationAt, pageUrl } from '../../../tests/helpers/location';
import { markSignedOut, clearSignedOut, wasSignedOut } from '../../utils/signedOut';
import { TranslationProvider } from '../../i18n/TranslationContext';
import { useAuthStore, type LoginResult } from '../../store/authStore';
@@ -54,7 +55,7 @@ function setSearch(search: string) {
Object.defineProperty(window, 'location', {
configurable: true,
writable: true,
value: { ...realLocation, pathname: '/login', href: 'http://localhost/login', search },
value: locationAt(`/login${search}`),
});
}
@@ -196,7 +197,7 @@ describe('useLogin — app config probe', () => {
await ready(result);
expect(result.current.noRedirect).toBe(true);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
it('FE-LOGIN-HOOK-009: never auto-redirects on a cached config', async () => {
@@ -210,7 +211,7 @@ describe('useLogin — app config probe', () => {
await ready(result);
expect(result.current.oidcOnly).toBe(true);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
});
@@ -1183,13 +1184,13 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
await waitFor(() => expect(result.current.redirectScreen).toBe(false));
expect(result.current.configWait).toBe(false);
expect(result.current.oidcOnly).toBe(true);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
it('FE-LOGIN-HOOK-208: a redirect that stalls offers the way on by hand after eight seconds', () => {
it('FE-LOGIN-HOOK-208: a redirect that stalls offers the way on by hand after eight seconds', async () => {
vi.useFakeTimers();
localStorage.setItem(CONFIG_CACHE_KEY, JSON.stringify(oidcOnlyConfig()));
heldConfig(oidcOnlyConfig());
const release = heldConfig(oidcOnlyConfig());
const { result } = renderLogin();
expect(result.current.redirectScreen).toBe(true);
@@ -1197,6 +1198,12 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
expect(result.current.idpSlow).toBe(false);
act(() => { vi.advanceTimersByTime(1); });
expect(result.current.idpSlow).toBe(true);
// The probe answers in the end and the redirect goes ahead, here and not in
// the next test.
vi.useRealTimers();
release();
await waitFor(() => expect(window.location.href).toBe('/api/auth/oidc/login?remember=1'));
});
it('FE-LOGIN-HOOK-209: a failed sign-in at the IdP shows the OIDC-only screen and its error, without going back', async () => {
@@ -1209,7 +1216,7 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
expect(result.current.configWait).toBe(false);
expect(result.current.redirectScreen).toBe(false);
expect(result.current.error).not.toBe('');
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login?oidc_error=token_failed'));
});
it('FE-LOGIN-HOOK-215: with the auto redirect turned off the page stays, with its SSO button (#2925)', async () => {
@@ -1222,7 +1229,7 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
expect(result.current.oidcOnly).toBe(true);
expect(result.current.redirectScreen).toBe(false);
expect(result.current.configWait).toBe(false);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
it('FE-LOGIN-HOOK-216: a cached config with the auto redirect off announces no redirect while the probe is out', async () => {
@@ -1237,7 +1244,7 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
release();
await ready(result);
expect(result.current.redirectScreen).toBe(false);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
it('FE-LOGIN-HOOK-217: a server from before the switch, with no field, keeps the redirect', async () => {
@@ -1259,6 +1266,6 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
release();
await ready(result);
expect(window.location.href).toBe('http://localhost/login');
expect(window.location.href).toBe(pageUrl('/login'));
});
});
@@ -2,6 +2,7 @@
import React from 'react';
import { MemoryRouter } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { locationAt } from '../../../tests/helpers/location';
import { act, renderHook, waitFor } from '../../../tests/helpers/render';
import { resetAllStores } from '../../../tests/helpers/store';
import { rememberHandoffReturn, requestHandoffCode, signInWithPasskey } from '../../native/browserSignIn';
@@ -28,7 +29,7 @@ function setSearch(search: string) {
Object.defineProperty(window, 'location', {
configurable: true,
writable: true,
value: { ...realLocation, search, href: 'http://localhost/native-handoff' + search, replace: vi.fn() },
value: locationAt(`/native-handoff${search}`, { replace: vi.fn() }),
});
}