chore: cleanup some har code (#4306)
Drive-by: do not create <root>/file.png in the tests.
This commit is contained in:
Родитель
d117d0bb93
Коммит
c446bf629d
|
@ -46,13 +46,7 @@ class HarTracer implements ContextListener {
|
|||
}
|
||||
}
|
||||
|
||||
async onContextDidDestroy(context: BrowserContext): Promise<void> {
|
||||
const contextTracer = this._contextTracers.get(context);
|
||||
if (contextTracer) {
|
||||
this._contextTracers.delete(context);
|
||||
await contextTracer.flush();
|
||||
}
|
||||
}
|
||||
async onContextDidDestroy(context: BrowserContext): Promise<void> { }
|
||||
}
|
||||
|
||||
type HarOptions = {
|
||||
|
@ -66,7 +60,7 @@ class HarContextTracer {
|
|||
private _pageEntries = new Map<Page, har.Page>();
|
||||
private _entries = new Map<network.Request, har.Entry>();
|
||||
private _lastPage = 0;
|
||||
private _barrierPromises = new Map<Promise<void>, Page>();
|
||||
private _barrierPromises = new Set<Promise<void>>();
|
||||
|
||||
constructor(context: BrowserContext, options: HarOptions) {
|
||||
this._options = options;
|
||||
|
@ -135,7 +129,7 @@ class HarContextTracer {
|
|||
})),
|
||||
promise
|
||||
]) as Promise<void>;
|
||||
this._barrierPromises.set(race, page);
|
||||
this._barrierPromises.add(race);
|
||||
}
|
||||
|
||||
private _onRequest(page: Page, request: network.Request) {
|
||||
|
@ -233,7 +227,7 @@ class HarContextTracer {
|
|||
}
|
||||
|
||||
async flush() {
|
||||
await Promise.all(this._barrierPromises.keys());
|
||||
await Promise.all(this._barrierPromises);
|
||||
for (const pageEntry of this._log.pages) {
|
||||
if (pageEntry.pageTimings.onContentLoad >= 0)
|
||||
pageEntry.pageTimings.onContentLoad -= pageEntry.startedDateTime.valueOf();
|
||||
|
|
|
@ -394,12 +394,13 @@ describe('element screenshot', (suite, parameters) => {
|
|||
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('screenshot-element-bounding-box.png');
|
||||
});
|
||||
|
||||
it('should prefer type over extension', async ({page, server}) => {
|
||||
it('should prefer type over extension', async ({page, server, testInfo}) => {
|
||||
await page.setViewportSize({width: 500, height: 500});
|
||||
await page.goto(server.PREFIX + '/grid.html');
|
||||
await page.evaluate(() => window.scrollBy(50, 100));
|
||||
const elementHandle = await page.$('.box:nth-of-type(3)');
|
||||
const buffer = await elementHandle.screenshot({ path: 'file.png', type: 'jpeg' });
|
||||
const outputPath = testInfo.outputPath('file.png');
|
||||
const buffer = await elementHandle.screenshot({ path: outputPath, type: 'jpeg' });
|
||||
expect([buffer[0], buffer[1], buffer[2]]).toEqual([0xFF, 0xD8, 0xFF]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -292,8 +292,9 @@ describe('page screenshot', (suite, { browserName, headful }) => {
|
|||
expect(error.message).toContain('path: unsupported mime type "text/plain"');
|
||||
});
|
||||
|
||||
it('should prefer type over extension', async ({page}) => {
|
||||
const buffer = await page.screenshot({ path: 'file.png', type: 'jpeg' });
|
||||
it('should prefer type over extension', async ({page, testInfo}) => {
|
||||
const outputPath = testInfo.outputPath('file.png');
|
||||
const buffer = await page.screenshot({ path: outputPath, type: 'jpeg' });
|
||||
expect([buffer[0], buffer[1], buffer[2]]).toEqual([0xFF, 0xD8, 0xFF]);
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче