mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
test: clean test in after hook (#12325)
This commit is contained in:
parent
461a8ff92f
commit
dc303f061b
@ -100,10 +100,10 @@ export class CdpBrowser extends BrowserBase {
|
||||
this.#defaultViewport = defaultViewport;
|
||||
this.#process = process;
|
||||
this.#connection = connection;
|
||||
this.#closeCallback = closeCallback || function (): void {};
|
||||
this.#closeCallback = closeCallback || (() => {});
|
||||
this.#targetFilterCallback =
|
||||
targetFilterCallback ||
|
||||
((): boolean => {
|
||||
(() => {
|
||||
return true;
|
||||
});
|
||||
this.#setIsPageTargetCallback(isPageTargetCallback);
|
||||
|
@ -96,7 +96,7 @@ const defaultBrowserOptions = Object.assign(
|
||||
headless: headless === 'shell' ? ('shell' as const) : isHeadless,
|
||||
dumpio: !!process.env['DUMPIO'],
|
||||
protocol,
|
||||
},
|
||||
} satisfies PuppeteerLaunchOptions,
|
||||
extraLaunchOptions
|
||||
);
|
||||
|
||||
@ -171,7 +171,7 @@ export const setupTestBrowserHooks = (): void => {
|
||||
}
|
||||
});
|
||||
|
||||
after(() => {
|
||||
after(async () => {
|
||||
if (typeof gc !== 'undefined') {
|
||||
gc();
|
||||
const memory = process.memoryUsage();
|
||||
@ -185,6 +185,14 @@ export const setupTestBrowserHooks = (): void => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (state.context) {
|
||||
await state.context.close();
|
||||
state.context = undefined;
|
||||
state.page = undefined;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const getTestState = async (
|
||||
@ -211,15 +219,12 @@ export const getTestState = async (
|
||||
} else if (!state.browser.connected) {
|
||||
throw new Error('Browser has disconnected!');
|
||||
}
|
||||
|
||||
if (state.context) {
|
||||
await state.context.close();
|
||||
state.context = undefined;
|
||||
state.page = undefined;
|
||||
throw new Error('Previous state was not cleared');
|
||||
}
|
||||
|
||||
if (!skipContextCreation) {
|
||||
state.context = await state.browser!.createBrowserContext();
|
||||
state.context = await state.browser.createBrowserContext();
|
||||
state.page = await state.context.newPage();
|
||||
}
|
||||
return state as PuppeteerTestState;
|
||||
|
Loading…
Reference in New Issue
Block a user