Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add FR integration scenarios #13092

Merged
merged 4 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions lighthouse-core/test/fraggle-rock/scenarios/api-test-pptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,7 @@ jest.setTimeout(90_000);
describe('Fraggle Rock API', () => {
const state = createTestState();

beforeAll(async () => {
await state.beforeAll();
});

beforeEach(async () => {
await state.beforeEach();
});

afterEach(async () => {
await state.afterEach();
});

afterAll(async () => {
await state.afterAll();
});
state.installSetupAndTeardownHooks();

async function setupTestPage() {
await state.page.goto(`${state.serverBaseUrl}/onclick.html`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,12 @@ jest.setTimeout(90_000);
describe('Disconnect', () => {
const state = createTestState();

beforeAll(async () => {
await state.beforeAll();
});
state.installSetupAndTeardownHooks();

beforeEach(async () => {
await state.beforeEach();
beforeAll(async () => {
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
state.server.baseDir = `${LH_ROOT}/lighthouse-core/test/fixtures/fraggle-rock/snapshot-basic`;
});

afterEach(async () => {
await state.afterEach();
});

afterAll(async () => {
await state.afterAll();
});

it('should reset the listeners/protocol when LH is done', async () => {
const pageUrl = `${state.serverBaseUrl}/onclick.html`;
await state.page.goto(pageUrl, {waitUntil: ['networkidle0']});
Expand Down
57 changes: 32 additions & 25 deletions lighthouse-core/test/fraggle-rock/scenarios/pptr-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
*/
'use strict';

import {beforeAll, beforeEach, afterAll, afterEach} from '@jest/globals';
import puppeteer from 'puppeteer';
import {Server} from '../../../../lighthouse-cli/test/fixtures/static-server.js';

/** @typedef {InstanceType<typeof import('../../../../lighthouse-cli/test/fixtures/static-server.js').Server>} StaticServer */

/**
* Some audits can be notApplicable based on machine timing information.
* Exclude these audits from applicability comparisons.
*/
const FLAKY_AUDIT_IDS_APPLICABILITY = new Set([
'long-tasks', // Depends on whether the longest task takes <50ms.
'screenshot-thumbnails', // Depends on OS whether frames happen to be generated on non-visual timespan changes.
'layout-shift-elements', // Depends on if the JS takes too long after input to be ignored for layout shift.
]);

export function createTestState() {
/** @param {string} name @return {any} */
const any = name => new Proxy({}, {get: () => {
Expand All @@ -22,36 +33,32 @@ export function createTestState() {
server: /** @type {StaticServer} */ (any('server')),
serverBaseUrl: '',

async beforeAll() {
this.server = new Server();
await this.server.listen(0, '127.0.0.1');
this.serverBaseUrl = `http://localhost:${this.server.getPort()}`;
this.browser = await puppeteer.launch({
headless: true,
installSetupAndTeardownHooks() {
beforeAll(async () => {
this.server = new Server();
await this.server.listen(0, '127.0.0.1');
this.serverBaseUrl = `http://localhost:${this.server.getPort()}`;
this.browser = await puppeteer.launch({
headless: true,
});
});

beforeEach(async () => {
this.page = await this.browser.newPage();
});

afterEach(async () => {
await this.page.close();
});

afterAll(async () => {
await this.browser.close();
await this.server.close();
});
},
async beforeEach() {
this.page = await this.browser.newPage();
},
async afterEach() {
await this.page.close();
},
async afterAll() {
await this.browser.close();
await this.server.close();
},
};
}

/**
* Some audits can be notApplicable based on machine timing information.
* Exclude these audits from applicability comparisons. */
const FLAKY_AUDIT_IDS_APPLICABILITY = new Set([
'long-tasks', // Depends on whether the longest task takes <50ms.
'screenshot-thumbnails', // Depends on OS whether frames happen to be generated on non-visual timespan changes.
'layout-shift-elements', // Depends on if the JS takes too long after input to be ignored for layout shift.
]);

/**
* @param {LH.Result} lhr
*/
Expand Down