tests: profile persistence runs in a real Chrome, in its own shard
The two "session cookie survives closing and relaunching storebound's own profile" tests failed with Playwright's headless shell, which ignores --restore-last-session. They now live in tests/console-persist.test.ts and launch the same browser kind console fill uses for its profile (the resolver's "visible" kind: Google Chrome, else the full Chromium; headless here, so no window). They skip with the reason only when neither is installed. All other browser tests keep the fast headless shell. The file is HEAVY in tools/ci-plan.ts, so it never shares a shard with another browser suite.
This commit is contained in:
parent
e21e274c2a
commit
de243cdbd9
4 changed files with 82 additions and 33 deletions
|
|
@ -4,19 +4,20 @@
|
||||||
// installed (a launch that times out fails instead). Load-proofing (tests/helpers/browser.ts): one launch with a long
|
// installed (a launch that times out fails instead). Load-proofing (tests/helpers/browser.ts): one launch with a long
|
||||||
// launch timeout, every context closed right after its test, event-driven waits for log lines, explicit test timeouts.
|
// launch timeout, every context closed right after its test, event-driven waits for log lines, explicit test timeouts.
|
||||||
// Slow on purpose (marked SLOW): the sign-in / watching tests and the account tests wait out real "not here" timeouts
|
// Slow on purpose (marked SLOW): the sign-in / watching tests and the account tests wait out real "not here" timeouts
|
||||||
// of the engine (navTimeoutMs / navMs, scaled down through the options) and the profile tests relaunch Chromium.
|
// of the engine (navTimeoutMs / navMs, scaled down through the options). The relaunch of storebound's own profile
|
||||||
|
// (session cookies kept) needs a real Chrome: tests/console-persist.test.ts.
|
||||||
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
||||||
import { mkdtempSync, rmSync } from 'node:fs';
|
import { mkdtempSync, rmSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { openAcross, readAccounts, rememberApple, rememberPlay, withAccountIds } from '../cli/console/accounts';
|
import { openAcross, readAccounts, rememberApple, rememberPlay, withAccountIds } from '../cli/console/accounts';
|
||||||
import { createAppHere, fillPage, fillSession, navClick, navigate, resumeAt, run, safeClick, signInPage } from '../cli/console/fill';
|
import { createAppHere, fillPage, fillSession, navClick, navigate, resumeAt, run, safeClick, signInPage } from '../cli/console/fill';
|
||||||
import { type ConsoleBrowser, openConsoleBrowser } from '../cli/console/session';
|
import type { ConsoleBrowser } from '../cli/console/session';
|
||||||
import { parseArgs } from '../cli/lib/args';
|
import { parseArgs } from '../cli/lib/args';
|
||||||
import { type ShipConfig, validateExtras } from '../cli/lib/config';
|
import { type ShipConfig, validateExtras } from '../cli/lib/config';
|
||||||
import { AGE_RATING_API, consoleAnswers, consoleResult, fillValue, FORM_IDS, type FormId, formMeta } from '../cli/lib/console-answers';
|
import { AGE_RATING_API, consoleAnswers, consoleResult, fillValue, FORM_IDS, type FormId, formMeta } from '../cli/lib/console-answers';
|
||||||
import { consoleReached, CREATE_APP_OPENERS, createAppAllowed, formDef, FORM_OPENERS, forbiddenControl, hasToken, isSignInText, isSignInUrl, navAllowed, navPlan, playDeveloperId, switchAllowed } from '../cli/lib/console-forms';
|
import { consoleReached, CREATE_APP_OPENERS, createAppAllowed, formDef, FORM_OPENERS, forbiddenControl, hasToken, isSignInText, isSignInUrl, navAllowed, navPlan, playDeveloperId, switchAllowed } from '../cli/lib/console-forms';
|
||||||
import { AFTER_ALL_MS, AFTER_EACH_MS, capped, CLOSE_TIMEOUT_MS, LAUNCH_TIMEOUT_MS, launchTestBrowser, logLines, testScope } from './helpers/browser';
|
import { AFTER_ALL_MS, AFTER_EACH_MS, launchTestBrowser, logLines, testScope } from './helpers/browser';
|
||||||
|
|
||||||
const config: ShipConfig = {
|
const config: ShipConfig = {
|
||||||
app: { name: 'Example Game', profile: 'game', privacyPolicyUrl: 'https://example.com/privacy', supportUrl: 'https://example.com/support', website: 'https://example.com', contactEmail: 'support@example.com' },
|
app: { name: 'Example Game', profile: 'game', privacyPolicyUrl: 'https://example.com/privacy', supportUrl: 'https://example.com/support', website: 'https://example.com', contactEmail: 'support@example.com' },
|
||||||
|
|
@ -190,9 +191,6 @@ let base = '';
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch: req => {
|
server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch: req => {
|
||||||
const path = new URL(req.url).pathname;
|
const path = new URL(req.url).pathname;
|
||||||
// a session cookie (no Expires / Max-Age): it must survive a relaunch of storebound's profile
|
|
||||||
if (path === '/session-set') return new Response('<p>set</p>', { headers: { 'content-type': 'text/html', 'set-cookie': 'sbsession=example; Path=/; HttpOnly' } });
|
|
||||||
if (path === '/session-echo') return new Response(`<p id="c">${/(?:^|; )sbsession=example(?:;|$)/.test(req.headers.get('cookie') ?? '') ? 'kept' : 'lost'}</p>`, { headers: { 'content-type': 'text/html' } });
|
|
||||||
const dev = path.match(/^\/playm\/u\/0\/developers(?:\/(\d+)\/app-list)?$/);
|
const dev = path.match(/^\/playm\/u\/0\/developers(?:\/(\d+)\/app-list)?$/);
|
||||||
// playn: the same chooser; every account's app list has a Create app button that opens the Create app form
|
// playn: the same chooser; every account's app list has a Create app button that opens the Create app form
|
||||||
const devNew = path.match(/^\/playn\/u\/0\/developers(?:\/(\d+)\/app-list)?$/);
|
const devNew = path.match(/^\/playn\/u\/0\/developers(?:\/(\d+)\/app-list)?$/);
|
||||||
|
|
@ -589,32 +587,7 @@ describe.skipIf(!browser)('sign-in and watching (headless, modeled pages on the
|
||||||
expect(await resumeAt(page, plan)).toBeNull();
|
expect(await resumeAt(page, plan)).toBeNull();
|
||||||
await page.close();
|
await page.close();
|
||||||
}, BROWSER_TEST_MS);
|
}, BROWSER_TEST_MS);
|
||||||
|
// the session-cookie persistence of storebound's own profile: tests/console-persist.test.ts (real Chrome, own shard)
|
||||||
for (const store of ['apple', 'play'] as const) {
|
|
||||||
test(`${store}: a session cookie survives closing and relaunching storebound's own profile`, async () => {
|
|
||||||
const dir = mkdtempSync(join(tmpdir(), `storebound-profile-${store}-`));
|
|
||||||
const root = join(import.meta.dir, '..');
|
|
||||||
// its own Chromium (a persistent profile), launched twice: SLOW, and the launch timeout is raised like the shared one
|
|
||||||
const opts = { store, profileDir: dir, fresh: true, headless: true, say: () => {}, launchTimeoutMs: LAUNCH_TIMEOUT_MS };
|
|
||||||
let b: ConsoleBrowser | null = null;
|
|
||||||
try {
|
|
||||||
b = await openConsoleBrowser(root, opts);
|
|
||||||
await b.page.goto(base + 'session-set');
|
|
||||||
await b.close(); // graceful: Chromium writes its cookie store
|
|
||||||
await b.closed;
|
|
||||||
b = await openConsoleBrowser(root, opts);
|
|
||||||
expect(b.pages()).toHaveLength(1); // the restored tab was closed again
|
|
||||||
await b.page.goto(base + 'session-echo');
|
|
||||||
expect(await b.page.textContent('#c')).toBe('kept');
|
|
||||||
await b.close();
|
|
||||||
await b.closed;
|
|
||||||
} finally {
|
|
||||||
// a failed assertion must not leave this Chromium running into the next test
|
|
||||||
if (b && !b.isClosed()) await capped(b.context.close(), CLOSE_TIMEOUT_MS);
|
|
||||||
rmSync(dir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
}, 2 * LAUNCH_TIMEOUT_MS + SLOW_TEST_MS); // two Chromium launches (each capped) plus the test itself
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---- one login, several developer accounts / teams ----
|
// ---- one login, several developer accounts / teams ----
|
||||||
|
|
|
||||||
60
tests/console-persist.test.ts
Normal file
60
tests/console-persist.test.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
// storebound console fill, mode (c): a session cookie (no Expires / Max-Age) survives closing and relaunching
|
||||||
|
// storebound's own persistent profile (--restore-last-session plus a graceful close). Launched with the browser kind the
|
||||||
|
// product uses for that profile (cli/shots/browser.ts, kind "visible"): real Google Chrome, else Playwright's full
|
||||||
|
// Chromium, headless here so no window appears. Never the headless shell: it does not restore the last session, so the
|
||||||
|
// cookie is always lost there. Skips (with the reason) only when neither is installed. Slow (two real Chrome launches
|
||||||
|
// and graceful closes per store), so tools/ci-plan.ts lists it as HEAVY: a shard of its own.
|
||||||
|
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
||||||
|
import { mkdtempSync, rmSync } from 'node:fs';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { type ConsoleBrowser, openConsoleBrowser } from '../cli/console/session';
|
||||||
|
import { installedBrowsers } from '../cli/shots/browser';
|
||||||
|
import { capped, CLOSE_TIMEOUT_MS, LAUNCH_TIMEOUT_MS, persistentBrowser } from './helpers/browser';
|
||||||
|
|
||||||
|
const real = await persistentBrowser();
|
||||||
|
if (!real.label) console.warn(`console-persist tests skipped: ${real.skipWhy}`);
|
||||||
|
const TEST_MS = 2 * LAUNCH_TIMEOUT_MS + 30_000; // two launches (each capped) plus the test itself
|
||||||
|
|
||||||
|
let server: ReturnType<typeof Bun.serve> | null = null;
|
||||||
|
let base = '';
|
||||||
|
beforeAll(() => {
|
||||||
|
server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch: req => {
|
||||||
|
const path = new URL(req.url).pathname;
|
||||||
|
if (path === '/session-set') return new Response('<p>set</p>', { headers: { 'content-type': 'text/html', 'set-cookie': 'sbsession=example; Path=/; HttpOnly' } });
|
||||||
|
if (path === '/session-echo') return new Response(`<p id="c">${/(?:^|; )sbsession=example(?:;|$)/.test(req.headers.get('cookie') ?? '') ? 'kept' : 'lost'}</p>`, { headers: { 'content-type': 'text/html' } });
|
||||||
|
return new Response('not found', { status: 404 });
|
||||||
|
} });
|
||||||
|
base = `http://127.0.0.1:${server.port}/`;
|
||||||
|
});
|
||||||
|
afterAll(() => { server?.stop(true); });
|
||||||
|
|
||||||
|
describe.skipIf(!real.label)(`storebound's own profile (${real.label ?? 'no real Chrome'})`, () => {
|
||||||
|
for (const store of ['apple', 'play'] as const) {
|
||||||
|
test(`${store}: a session cookie survives closing and relaunching storebound's own profile`, async () => {
|
||||||
|
const dir = mkdtempSync(join(tmpdir(), `storebound-profile-${store}-`));
|
||||||
|
const root = join(import.meta.dir, '..');
|
||||||
|
const { chromium } = await import('playwright');
|
||||||
|
// the resolver's own choice, without a STOREBOUND_CHROME from the environment
|
||||||
|
const installed = installedBrowsers(chromium, { ...process.env, STOREBOUND_CHROME: undefined });
|
||||||
|
const opts = { store, profileDir: dir, fresh: true, headless: true, say: () => {}, launchTimeoutMs: LAUNCH_TIMEOUT_MS, launchDeps: { installed } };
|
||||||
|
let b: ConsoleBrowser | null = null;
|
||||||
|
try {
|
||||||
|
b = await openConsoleBrowser(root, opts);
|
||||||
|
await b.page.goto(base + 'session-set');
|
||||||
|
await b.close(); // graceful: Chrome writes its cookie store
|
||||||
|
await b.closed;
|
||||||
|
b = await openConsoleBrowser(root, opts);
|
||||||
|
expect(b.pages()).toHaveLength(1); // the restored tab was closed again
|
||||||
|
await b.page.goto(base + 'session-echo');
|
||||||
|
expect(await b.page.textContent('#c')).toBe('kept');
|
||||||
|
await b.close();
|
||||||
|
await b.closed;
|
||||||
|
} finally {
|
||||||
|
// a failed assertion must not leave this Chrome running into the next test
|
||||||
|
if (b && !b.isClosed()) await capped(b.context.close(), CLOSE_TIMEOUT_MS);
|
||||||
|
rmSync(dir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
}, TEST_MS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -72,6 +72,22 @@ const firstLine = (e: unknown) => (e as Error).message.split('\n')[0]!;
|
||||||
/** Playwright's "no such browser" errors (bundled build not downloaded, Chrome channel not installed). */
|
/** Playwright's "no such browser" errors (bundled build not downloaded, Chrome channel not installed). */
|
||||||
const notInstalled = (e: unknown) => /Executable doesn't exist|distribution '[^']+' is not found|Failed to launch .* because executable/i.test((e as Error).message);
|
const notInstalled = (e: unknown) => /Executable doesn't exist|distribution '[^']+' is not found|Failed to launch .* because executable/i.test((e as Error).message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The browser the persistent-profile tests (tests/console-persist.test.ts) launch: the same kind `console fill` uses
|
||||||
|
* for storebound's own profile (cli/shots/browser.ts, kind "visible"): real Google Chrome (channel "chrome"), else
|
||||||
|
* Playwright's FULL Chromium (channel "chromium"). Never the fast headless shell launchTestBrowser uses: it ignores
|
||||||
|
* --restore-last-session, so session cookies are dropped on relaunch. `label` is null when neither is installed.
|
||||||
|
*/
|
||||||
|
export async function persistentBrowser(): Promise<{ label: string | null; skipWhy: string }> {
|
||||||
|
const { installedBrowsers, launchCandidates } = await import('../../cli/shots/browser');
|
||||||
|
let pw: any = null;
|
||||||
|
try { pw = (await import('playwright')).chromium; } catch (e) { return { label: null, skipWhy: `playwright is not installed (${firstLine(e)})` }; }
|
||||||
|
// STOREBOUND_CHROME left out: the tests pin the resolver's choice of an installed Chrome / full Chromium
|
||||||
|
const c = launchCandidates('visible', installedBrowsers(pw, { ...process.env, STOREBOUND_CHROME: undefined }))[0];
|
||||||
|
return c ? { label: c.label, skipWhy: '' }
|
||||||
|
: { label: null, skipWhy: 'neither Google Chrome nor Playwright\'s full Chromium is installed (the headless shell drops session cookies on relaunch); install Google Chrome or run `bunx playwright install chromium`' };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contexts and engine runs of the current test. `newPage` opens a page in a fresh context (as browser.newPage
|
* The contexts and engine runs of the current test. `newPage` opens a page in a fresh context (as browser.newPage
|
||||||
* does) and tracks it; `track` adds one opened elsewhere; `settle` (afterEach) closes them all and waits for the runs.
|
* does) and tracks it; `track` adds one opened elsewhere; `settle` (afterEach) closes them all and waits for the runs.
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export const TIMINGS = join(ROOT, 'node_modules/.cache/storebound-ci/test-timing
|
||||||
* suite next to it, so they don't fight for CPU and time out. */
|
* suite next to it, so they don't fight for CPU and time out. */
|
||||||
export const HEAVY = [
|
export const HEAVY = [
|
||||||
'tests/console-fill.test.ts', 'tests/site-overflow.test.ts', 'tests/local-fonts.test.ts', 'tests/glyphs.test.ts',
|
'tests/console-fill.test.ts', 'tests/site-overflow.test.ts', 'tests/local-fonts.test.ts', 'tests/glyphs.test.ts',
|
||||||
'tests/capture-web.test.ts', 'tests/console-session.test.ts',
|
'tests/capture-web.test.ts', 'tests/console-session.test.ts', 'tests/console-persist.test.ts',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** Changes that can affect every test: run the whole suite. */
|
/** Changes that can affect every test: run the whole suite. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue