Skip to content

Commit 0c64a00

Browse files
committed
Update
1 parent 5683d23 commit 0c64a00

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

tests/browser-application-retirement-contract.test.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ test('every browser spec owns production application retirement', async () => {
3131
}
3232
});
3333

34+
test('every explicit browser page or context retires before closure', async () => {
35+
const specFiles = (await readdir(browserDir))
36+
.filter(name => name.endsWith('.spec.mjs'))
37+
.sort();
38+
39+
for (const filename of specFiles) {
40+
const source = await readFile(path.join(browserDir, filename), 'utf8');
41+
if (/browser\.newContext\(/.test(source)) {
42+
assert.match(
43+
source,
44+
/closeContextWithApplicationRetirement/,
45+
`${filename} closes a custom context without application retirement`,
46+
);
47+
assert.doesNotMatch(source, /\bcontext\?*\.close\(/);
48+
}
49+
if (/context\.newPage\(/.test(source)) {
50+
assert.match(
51+
source,
52+
/close(?:Page|Context)WithApplicationRetirement/,
53+
`${filename} closes an explicit page without application retirement`,
54+
);
55+
}
56+
}
57+
});
58+
3459
test('the browser fixture retires even a failed test through the stable owner', async () => {
3560
const source = await readFile(
3661
path.join(browserDir, 'helpers', 'test.mjs'),
@@ -40,7 +65,8 @@ test('the browser fixture retires even a failed test through the stable owner',
4065
source,
4166
/finally\s*\{[\s\S]*retireContextApplications\(context\)/,
4267
);
43-
assert.match(source, /applicationRetirement:[\s\S]*auto:\s*true/);
68+
assert.match(source, /page:\s*async\s*\(\{\s*context,\s*page\s*\},\s*use\)/);
69+
assert.doesNotMatch(source, /applicationRetirement:[\s\S]*auto:\s*true/);
4470
assert.match(source, /window\._cellucidDispose/);
4571
assert.match(source, /secondTask\s*!==\s*firstTask/);
4672
assert.match(

tests/browser/community-annotation-oauth-worker-lifecycle.spec.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { once } from 'node:events';
22
import { createPrivateKey } from 'node:crypto';
33
import { createServer } from 'node:https';
44

5-
import { expect, test } from './helpers/test.mjs';
5+
import {
6+
closeContextWithApplicationRetirement,
7+
expect,
8+
test,
9+
} from './helpers/test.mjs';
610

711
import worker from '../../assets/js/app/community-annotations/_worker-code.js';
812
import {
@@ -180,6 +184,7 @@ test('OAuth owner cookies preserve exact raw Set-Cookie bytes', async () => {
180184
test(
181185
'state-specific OAuth cookies coexist and retire independently',
182186
async ({ browser }) => {
187+
expect(browser.contexts()).toHaveLength(0);
183188
const previousFetch = globalThis.fetch;
184189
globalThis.fetch = async (_url, options) => {
185190
const body = parseExactJson(options.body);
@@ -290,7 +295,9 @@ test(
290295
expect(workerServer.serverErrors).toEqual([]);
291296
} finally {
292297
const cleanup = await Promise.allSettled([
293-
context?.close(),
298+
context === null
299+
? undefined
300+
: closeContextWithApplicationRetirement(context),
294301
workerServer?.close(),
295302
]);
296303
globalThis.fetch = previousFetch;

tests/browser/helpers/test.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,18 @@ export async function closeContextWithApplicationRetirement(context) {
109109
}
110110

111111
export const test = playwrightTest.extend({
112-
applicationRetirement: [async ({ context }, use) => {
112+
// Override the lazy page fixture instead of installing an auto context
113+
// fixture. An auto fixture materializes an otherwise unused default context
114+
// in browser-only tests, and its teardown can run after Playwright has
115+
// already closed the base page. This boundary retires the application while
116+
// both its document and context are still live.
117+
page: async ({ context, page }, use) => {
113118
try {
114-
await use();
119+
await use(page);
115120
} finally {
116121
await retireContextApplications(context);
117122
}
118-
}, { auto: true }],
123+
},
119124
});
120125

121126
export { expect };

tests/browser/reduced-motion-camera-path.spec.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ async function playAndMeasure(page, reducedMotion) {
139139
test('camera path playback honours a reduced-motion preference', async ({
140140
browser
141141
}) => {
142+
// This test deliberately owns custom contexts so it can compare two media
143+
// preferences in one browser generation. Its fixture must not materialize
144+
// an unused default context alongside them.
145+
expect(browser.contexts()).toHaveLength(0);
142146
const measurements = {};
143147
const errors = {};
144148

0 commit comments

Comments
 (0)