Skip to content

Commit d296b44

Browse files
committed
fix(e2e): more robust tests
1 parent bc9b6d3 commit d296b44

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
export const data: string[] = [];
1+
// Per-session storage so the mpa and spa Playwright describe blocks (and any
2+
// other parallel workers) don't race on a shared module-level array.
3+
// The session id is carried in a cookie set by the root action.
4+
const sessionData = new Map<string, string[]>();
5+
6+
export const SESSION_COOKIE = 'issue2644-session';
7+
8+
export const getSessionData = (sessionId: string | undefined): string[] => {
9+
if (!sessionId) {
10+
return [];
11+
}
12+
let data = sessionData.get(sessionId);
13+
if (!data) {
14+
data = [];
15+
sessionData.set(sessionId, data);
16+
}
17+
return data;
18+
};
19+
20+
export const createSessionId = () =>
21+
`s-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;

e2e/qwik-e2e/apps/qwikrouter-test/src/routes/(common)/issue2644/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { component$ } from '@qwik.dev/core';
22
import { Form, routeAction$ } from '@qwik.dev/router';
3-
import { data } from './data';
3+
import { SESSION_COOKIE, createSessionId, getSessionData } from './data';
44

55
export const useRootAction = routeAction$(
6-
(form, { redirect }) => {
7-
const name = form.name as string;
6+
(form, { redirect, cookie }) => {
7+
let sessionId = cookie.get(SESSION_COOKIE)?.value;
8+
if (!sessionId) {
9+
sessionId = createSessionId();
10+
cookie.set(SESSION_COOKIE, sessionId, { path: '/' });
11+
}
12+
const data = getSessionData(sessionId);
813
data.length = 0;
9-
data.push(name);
14+
data.push(form.name as string);
1015
throw redirect(303, '/qwikrouter-test/issue2644/other/');
1116
},
1217
{

e2e/qwik-e2e/apps/qwikrouter-test/src/routes/(common)/issue2644/other/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Form, routeAction$, routeLoader$ } from '@qwik.dev/router';
22
import { component$ } from '@qwik.dev/core';
3-
import { data } from '../data';
3+
import { SESSION_COOKIE, getSessionData } from '../data';
44

5-
export const useGetData = routeLoader$(() => {
6-
return data;
5+
export const useGetData = routeLoader$(({ cookie }) => {
6+
return getSessionData(cookie.get(SESSION_COOKIE)?.value);
77
});
88

9-
export const useOtherAction = routeAction$((form) => {
9+
export const useOtherAction = routeAction$((form, { cookie }) => {
10+
const data = getSessionData(cookie.get(SESSION_COOKIE)?.value);
1011
const name = form.name as string;
1112
data.push(name);
1213
return { success: true };

e2e/qwik-e2e/tests/starter-partytown.e2e.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ test('rendered', async ({ page }) => {
1111

1212
const state = page.locator('#state');
1313

14-
await expect(state).toHaveText('finished');
14+
// Partytown spins up a web worker to run the simulated async work; under parallel
15+
// test load the worker init can take well over the default 3s expect timeout.
16+
await expect(state).toHaveText('finished', { timeout: 15000 });
1517
});
1618

1719
test('update text', async ({ page }) => {

0 commit comments

Comments
 (0)