2020-08-05 01:57:25 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2020-08-17 05:19:52 +03:00
|
|
|
|
2020-10-12 19:16:02 +03:00
|
|
|
import { folio } from '../fixtures';
|
2020-08-07 21:19:15 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2020-08-27 00:16:35 +03:00
|
|
|
import type { ChromiumBrowser } from '../..';
|
2020-08-14 17:22:54 +03:00
|
|
|
|
2020-09-11 07:31:46 +03:00
|
|
|
type TestState = {
|
|
|
|
outputTraceFile: string;
|
|
|
|
};
|
2020-10-14 08:40:25 +03:00
|
|
|
const fixtures = folio.extend<TestState>();
|
2020-10-12 23:48:56 +03:00
|
|
|
fixtures.outputTraceFile.init(async ({ testInfo }, run) => {
|
2020-10-12 19:16:02 +03:00
|
|
|
await run(testInfo.outputPath(path.join(`trace.json`)));
|
2020-08-05 01:57:25 +03:00
|
|
|
});
|
2020-10-12 19:16:02 +03:00
|
|
|
const { it, expect, describe } = fixtures.build();
|
2020-10-06 03:03:24 +03:00
|
|
|
|
2020-09-27 02:05:58 +03:00
|
|
|
describe('oopif', (suite, { browserName }) => {
|
|
|
|
suite.skip(browserName !== 'chromium');
|
2020-08-29 01:45:09 +03:00
|
|
|
}, () => {
|
2020-09-03 07:43:38 +03:00
|
|
|
it('should output a trace', async ({browser, page, server, outputTraceFile}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {screenshots: true, path: outputTraceFile});
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await (browser as ChromiumBrowser).stopTracing();
|
2020-09-03 07:43:38 +03:00
|
|
|
expect(fs.existsSync(outputTraceFile)).toBe(true);
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-10-06 03:03:24 +03:00
|
|
|
it('should create directories as needed', async ({browser, page, server, testInfo}) => {
|
|
|
|
const filePath = testInfo.outputPath(path.join('these', 'are', 'directories', 'trace.json'));
|
2020-08-28 23:53:47 +03:00
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {screenshots: true, path: filePath});
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await (browser as ChromiumBrowser).stopTracing();
|
|
|
|
expect(fs.existsSync(filePath)).toBe(true);
|
|
|
|
});
|
2020-08-18 02:53:19 +03:00
|
|
|
|
2020-09-03 07:43:38 +03:00
|
|
|
it('should run with custom categories if provided', async ({browser, page, outputTraceFile}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {path: outputTraceFile, categories: ['disabled-by-default-v8.cpu_profiler.hires']});
|
2020-08-28 23:53:47 +03:00
|
|
|
await (browser as ChromiumBrowser).stopTracing();
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-09-03 07:43:38 +03:00
|
|
|
const traceJson = JSON.parse(fs.readFileSync(outputTraceFile).toString());
|
2020-08-28 23:53:47 +03:00
|
|
|
expect(traceJson.metadata['trace-config']).toContain('disabled-by-default-v8.cpu_profiler.hires');
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-09-03 07:43:38 +03:00
|
|
|
it('should throw if tracing on two pages', async ({browser, page, outputTraceFile}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {path: outputTraceFile});
|
2020-08-28 23:53:47 +03:00
|
|
|
const newPage = await browser.newPage();
|
|
|
|
let error = null;
|
2020-09-03 07:43:38 +03:00
|
|
|
await (browser as ChromiumBrowser).startTracing(newPage, {path: outputTraceFile}).catch(e => error = e);
|
2020-08-28 23:53:47 +03:00
|
|
|
await newPage.close();
|
|
|
|
expect(error).toBeTruthy();
|
|
|
|
await (browser as ChromiumBrowser).stopTracing();
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-09-03 07:43:38 +03:00
|
|
|
it('should return a buffer', async ({browser, page, server, outputTraceFile}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {screenshots: true, path: outputTraceFile});
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const trace = await (browser as ChromiumBrowser).stopTracing();
|
2020-09-03 07:43:38 +03:00
|
|
|
const buf = fs.readFileSync(outputTraceFile);
|
2020-08-28 23:53:47 +03:00
|
|
|
expect(trace.toString()).toEqual(buf.toString());
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should work without options', async ({browser, page, server}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page);
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const trace = await (browser as ChromiumBrowser).stopTracing();
|
|
|
|
expect(trace).toBeTruthy();
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should support a buffer without a path', async ({browser, page, server}) => {
|
|
|
|
await (browser as ChromiumBrowser).startTracing(page, {screenshots: true});
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const trace = await (browser as ChromiumBrowser).stopTracing();
|
|
|
|
expect(trace.toString()).toContain('screenshot');
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
});
|