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.#defaultViewport = defaultViewport;
|
||||||
this.#process = process;
|
this.#process = process;
|
||||||
this.#connection = connection;
|
this.#connection = connection;
|
||||||
this.#closeCallback = closeCallback || function (): void {};
|
this.#closeCallback = closeCallback || (() => {});
|
||||||
this.#targetFilterCallback =
|
this.#targetFilterCallback =
|
||||||
targetFilterCallback ||
|
targetFilterCallback ||
|
||||||
((): boolean => {
|
(() => {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
this.#setIsPageTargetCallback(isPageTargetCallback);
|
this.#setIsPageTargetCallback(isPageTargetCallback);
|
||||||
|
@ -96,7 +96,7 @@ const defaultBrowserOptions = Object.assign(
|
|||||||
headless: headless === 'shell' ? ('shell' as const) : isHeadless,
|
headless: headless === 'shell' ? ('shell' as const) : isHeadless,
|
||||||
dumpio: !!process.env['DUMPIO'],
|
dumpio: !!process.env['DUMPIO'],
|
||||||
protocol,
|
protocol,
|
||||||
},
|
} satisfies PuppeteerLaunchOptions,
|
||||||
extraLaunchOptions
|
extraLaunchOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ export const setupTestBrowserHooks = (): void => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(async () => {
|
||||||
if (typeof gc !== 'undefined') {
|
if (typeof gc !== 'undefined') {
|
||||||
gc();
|
gc();
|
||||||
const memory = process.memoryUsage();
|
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 (
|
export const getTestState = async (
|
||||||
@ -211,15 +219,12 @@ export const getTestState = async (
|
|||||||
} else if (!state.browser.connected) {
|
} else if (!state.browser.connected) {
|
||||||
throw new Error('Browser has disconnected!');
|
throw new Error('Browser has disconnected!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.context) {
|
if (state.context) {
|
||||||
await state.context.close();
|
throw new Error('Previous state was not cleared');
|
||||||
state.context = undefined;
|
|
||||||
state.page = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipContextCreation) {
|
if (!skipContextCreation) {
|
||||||
state.context = await state.browser!.createBrowserContext();
|
state.context = await state.browser.createBrowserContext();
|
||||||
state.page = await state.context.newPage();
|
state.page = await state.context.newPage();
|
||||||
}
|
}
|
||||||
return state as PuppeteerTestState;
|
return state as PuppeteerTestState;
|
||||||
|
Loading…
Reference in New Issue
Block a user