test: cleanup tests and configs after last folio update (#6463)

This commit is contained in:
Dmitry Gozman 2021-05-08 17:45:04 -07:00 committed by GitHub
parent a9523d9d8f
commit 2d4538c23d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 864 additions and 942 deletions

View file

@ -15,7 +15,7 @@
*/
import type { AndroidDevice } from '../../index';
import { CommonArgs, baseTest } from './baseTest';
import { CommonArgs, baseTest } from '../config/baseTest';
import * as folio from 'folio';
export { expect } from 'folio';

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { androidTest as test, expect } from '../config/androidTest';
import { androidTest as test, expect } from './androidTest';
test('androidDevice.model', async function({ androidDevice }) {
expect(androidDevice.model()).toBe('sdk_gphone_x86_arm');

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import { PNG } from 'pngjs';
import { androidTest as test, expect } from '../config/androidTest';
import { androidTest as test, expect } from './androidTest';
test('androidDevice.shell', async function({ androidDevice }) {
const output = await androidDevice.shell('echo 123');

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { androidTest as test, expect } from '../config/androidTest';
import { androidTest as test, expect } from './androidTest';
test('androidDevice.webView', async function({ androidDevice }) {
expect(androidDevice.webViews().length).toBe(0);

View file

@ -19,9 +19,6 @@ import { contextTest as test, expect } from '../config/browserTest';
import { playwrightTest } from '../config/browserTest';
import http from 'http';
test.describe('chromium', () => {
test.skip(({ browserName }) => browserName !== 'chromium');
test('should create a worker from a service worker', async ({page, server}) => {
const [worker] = await Promise.all([
page.context().waitForEvent('serviceworker'),
@ -78,10 +75,6 @@ test.describe('chromium', () => {
// make it work with Edgium.
expect(serverRequest.headers.intervention).toContain('feature/5718547946799104');
});
});
playwrightTest.describe('chromium', () => {
playwrightTest.skip(({ browserName }) => browserName !== 'chromium');
playwrightTest('should close service worker together with the context', async ({browserType, browserOptions, server}) => {
const browser = await browserType.launch(browserOptions);
@ -181,6 +174,7 @@ playwrightTest.describe('chromium', () => {
await browserServer.close();
}
});
playwrightTest('should connect over a ws endpoint', async ({browserType, browserOptions, server}, testInfo) => {
const port = 9339 + testInfo.workerIndex;
const browserServer = await browserType.launch({
@ -213,6 +207,7 @@ playwrightTest.describe('chromium', () => {
await browserServer.close();
}
});
playwrightTest('should send extra headers with connect request', async ({browserType, browserOptions, server}, testInfo) => {
{
const [request] = await Promise.all([
@ -243,4 +238,3 @@ playwrightTest.describe('chromium', () => {
expect(request.headers['foo']).toBe('bar');
}
});
});

View file

@ -16,9 +16,6 @@
import { contextTest as it, expect } from '../config/browserTest';
it.describe('CSS Coverage', () => {
it.skip(({ browserName }) => browserName !== 'chromium');
it('should work', async function({page, server}) {
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/simple.html');
@ -135,4 +132,3 @@ it.describe('CSS Coverage', () => {
const coverage = await page.coverage.stopCSSCoverage();
expect(coverage.length).toBe(1);
});
});

View file

@ -16,9 +16,6 @@
import { contextTest as it, expect } from '../config/browserTest';
it.describe('JS Coverage', () => {
it.skip(({ browserName }) => browserName !== 'chromium');
it('should work', async function({page, server}) {
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/simple.html', { waitUntil: 'load' });
@ -85,4 +82,3 @@ it.describe('JS Coverage', () => {
});
await page.coverage.stopJSCoverage();
});
});

View file

@ -16,8 +16,6 @@
import { playwrightTest as it, expect } from '../config/browserTest';
it.skip(({ browserName }) => browserName !== 'chromium');
it('should throw with remote-debugging-pipe argument', async ({browserType, browserOptions, mode}) => {
it.skip(mode !== 'default');

View file

@ -14,33 +14,9 @@
* limitations under the License.
*/
import { playwrightTest, expect } from '../config/browserTest';
import type { Page } from '../../index';
import { contextTest as it, expect } from '../config/browserTest';
const it = playwrightTest.extend({
async beforeAll({ browserType, browserOptions, browserName }) {
const browser = await browserType.launch({
...browserOptions,
args: browserName === 'chromium' ? (browserOptions.args || []).concat(['--site-per-process']) : browserOptions.args,
});
this.browser = browser;
return { browser };
},
async beforeEach() {
const page = await this.browser.newPage() as Page;
this.page = page;
return { page };
},
async afterEach() {
await this.page.close();
},
async afterAll() {
await this.browser.close();
},
});
it.describe('oopif', () => {
it.skip(({ browserName }) => browserName !== 'chromium');
it.useOptions({ launchOptions: { args: ['--site-per-process'] } });
it('should report oopif frames', async function({page, browser, server}) {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
@ -315,7 +291,6 @@ it.describe('oopif', () => {
await handle1.click();
expect(await handle1.evaluate(() => window['_clicked'])).toBe(true);
});
});
async function countOOPIFs(browser) {
const browserSession = await browser.newBrowserCDPSession();

View file

@ -17,9 +17,6 @@
import { contextTest as it, expect } from '../config/browserTest';
import { browserTest } from '../config/browserTest';
it.describe('session', () => {
it.skip(({ browserName }) => browserName !== 'chromium');
it('should work', async function({page}) {
const client = await page.context().newCDPSession(page);
@ -90,10 +87,6 @@ it.describe('session', () => {
await client.send('ThisCommand.DoesNotExist');
}
});
});
browserTest.describe('session', () => {
browserTest.skip(({ browserName }) => browserName !== 'chromium');
browserTest('should not break page.close()', async function({browser}) {
const context = await browser.newContext();
@ -128,4 +121,3 @@ browserTest.describe('session', () => {
await session.detach();
});
});

View file

@ -18,9 +18,6 @@ import { browserTest as it, expect } from '../config/browserTest';
import fs from 'fs';
import path from 'path';
it.describe('tracing', () => {
it.skip(({ browserName }) => browserName !== 'chromium');
it('should output a trace', async ({browser, server}, testInfo) => {
const page = await browser.newPage();
const outputTraceFile = testInfo.outputPath(path.join(`trace.json`));
@ -93,4 +90,3 @@ it.describe('tracing', () => {
expect(trace.toString()).toContain('screenshot');
await page.close();
});
});

View file

@ -17,7 +17,7 @@
import * as folio from 'folio';
import * as path from 'path';
import { test as pageTest } from '../page/pageTest';
import { AndroidEnv } from './androidTest';
import { AndroidEnv } from '../android/androidTest';
import type { BrowserContext } from '../../index';
import { PlaywrightEnvOptions } from './browserTest';
import { CommonOptions } from './baseTest';

View file

@ -95,14 +95,17 @@ const config: folio.Config<AllOptions> = {
projects: [],
};
for (const browserName of ['chromium', 'webkit', 'firefox'] as BrowserName[]) {
const browserNames = ['chromium', 'webkit', 'firefox'] as BrowserName[];
for (const browserName of browserNames) {
const executablePath = getExecutablePath(browserName);
if (executablePath && (process.env.FOLIO_WORKER_INDEX === undefined || process.env.FOLIO_WORKER_INDEX === ''))
console.error(`Using executable at ${executablePath}`);
const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b));
testIgnore.push(/android/, /electron/);
config.projects.push({
name: browserName,
testDir,
testIgnore: [/android/, /electron/],
testIgnore,
options: {
mode: (process.env.PWTEST_MODE || 'default') as ('default' | 'driver' | 'service'),
browserName,

View file

@ -16,7 +16,7 @@
import * as folio from 'folio';
import * as path from 'path';
import { ElectronEnv } from './electronTest';
import { ElectronEnv } from '../electron/electronTest';
import { test as pageTest } from '../page/pageTest';
import { PlaywrightEnvOptions } from './browserTest';
import { CommonOptions } from './baseTest';

View file

@ -16,11 +16,12 @@
import type { BrowserWindow } from 'electron';
import path from 'path';
import { electronTest as test, baseElectronTest as baseTest, expect } from '../config/electronTest';
import { electronTest as test, expect } from './electronTest';
import { baseTest } from '../config/baseTest';
baseTest('should fire close event', async ({ playwright }) => {
const electronApp = await playwright._electron.launch({
args: [path.join(__dirname, '..', 'config', 'electron-app.js')],
args: [path.join(__dirname, 'electron-app.js')],
});
const events = [];
electronApp.on('close', () => events.push('application'));
@ -34,7 +35,7 @@ baseTest('should fire close event', async ({ playwright }) => {
test('should script application', async ({ electronApp }) => {
const appPath = await electronApp.evaluate(async ({ app }) => app.getAppPath());
expect(appPath).toBe(path.resolve(__dirname, '..', 'config'));
expect(appPath).toBe(path.resolve(__dirname));
});
test('should return windows', async ({ electronApp, newWindow }) => {
@ -92,14 +93,14 @@ test('should have a clipboard instance', async ({ electronApp }) => {
test('should test app that opens window fast', async ({ playwright }) => {
const electronApp = await playwright._electron.launch({
args: [path.join(__dirname, '..', 'config', 'electron-window-app.js')],
args: [path.join(__dirname, 'electron-window-app.js')],
});
await electronApp.close();
});
test('should return browser window', async ({ playwright }) => {
const electronApp = await playwright._electron.launch({
args: [path.join(__dirname, '..', 'config', 'electron-window-app.js')],
args: [path.join(__dirname, 'electron-window-app.js')],
});
const page = await electronApp.waitForEvent('window');
const bwHandle = await electronApp.browserWindow(page);

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { electronTest as test, expect } from '../config/electronTest';
import { electronTest as test, expect } from './electronTest';
test('should click the button', async ({newWindow, server}) => {
const window = await newWindow();

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { baseTest, CommonArgs } from './baseTest';
import { baseTest, CommonArgs } from '../config/baseTest';
import { ElectronApplication, Page } from '../../index';
import * as folio from 'folio';
import * as path from 'path';
@ -79,5 +79,4 @@ export class ElectronEnv {
}
}
export const baseElectronTest = baseTest;
export const electronTest = baseTest.extend(new ElectronEnv());

View file

@ -17,8 +17,6 @@
import { playwrightTest as it, expect } from '../config/browserTest';
it('should pass firefox user preferences', async ({browserType, browserOptions, browserName}) => {
it.skip(browserName !== 'firefox');
const browser = await browserType.launch({
...browserOptions,
firefoxUserPrefs: {

View file

@ -14,8 +14,7 @@
* limitations under the License.
*/
import { cliTest as test, expect } from '../config/cliTest';
import * as http from 'http';
import { test, expect } from './inspectorTest';
test.describe('cli codegen', () => {
test.skip(({ mode }) => mode !== 'default');
@ -58,14 +57,14 @@ await page.ClickAsync("text=Submit");`);
expect(message.text()).toBe('click');
});
test('should click after same-document navigation', async ({ page, openRecorder, httpServer }) => {
test('should click after same-document navigation', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
httpServer.setHandler((req: http.IncomingMessage, res: http.ServerResponse) => {
server.setRoute('/foo.html', (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.end('');
});
await recorder.setContentAndWait(`<button onclick="console.log('click')">Submit</button>`, httpServer.PREFIX + '/foo.html');
await recorder.setContentAndWait(`<button onclick="console.log('click')">Submit</button>`, server.PREFIX + '/foo.html');
await Promise.all([
page.waitForNavigation(),
page.evaluate(() => history.pushState({}, '', '/url.html')),

View file

@ -14,8 +14,7 @@
* limitations under the License.
*/
import { cliTest as test, expect } from '../config/cliTest';
import * as http from 'http';
import { test, expect } from './inspectorTest';
import * as url from 'url';
test.describe('cli codegen', () => {
@ -228,10 +227,10 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", new[] { });`);
});
test('should download files', async ({ page, openRecorder, httpServer }) => {
test('should download files', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
httpServer.setHandler((req: http.IncomingMessage, res: http.ServerResponse) => {
server.setRoute('/download', (req, res) => {
const pathName = url.parse(req.url!).path;
if (pathName === '/download') {
res.setHeader('Content-Type', 'application/octet-stream');
@ -243,8 +242,8 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", new[] { });`);
}
});
await recorder.setContentAndWait(`
<a href="${httpServer.PREFIX}/download" download>Download</a>
`, httpServer.PREFIX);
<a href="${server.PREFIX}/download" download>Download</a>
`, server.PREFIX);
await recorder.hoverOverElement('text=Download');
await Promise.all([
page.waitForEvent('download'),
@ -338,23 +337,19 @@ await page.ClickAsync(\"text=click me\");`);
});
test('should handle history.postData', async ({ page, openRecorder, httpServer }) => {
test('should handle history.postData', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
httpServer.setHandler((req: http.IncomingMessage, res: http.ServerResponse) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.end('Hello world');
});
await recorder.setContentAndWait(`
<script>
let seqNum = 0;
function pushState() {
history.pushState({}, 'title', '${httpServer.PREFIX}/#seqNum=' + (++seqNum));
history.pushState({}, 'title', '${server.PREFIX}/#seqNum=' + (++seqNum));
}
</script>`, httpServer.PREFIX);
</script>`, server.PREFIX);
for (let i = 1; i < 3; ++i) {
await page.evaluate('pushState()');
await recorder.waitForOutput('<javascript>', `await page.goto('${httpServer.PREFIX}/#seqNum=${i}');`);
await recorder.waitForOutput('<javascript>', `await page.goto('${server.PREFIX}/#seqNum=${i}');`);
}
});
@ -581,23 +576,23 @@ await page.GetFrame(name: \"two\").ClickAsync(\"text=Hi, I'm frame\");`);
await page.GetFrame(url: \"http://localhost:${server.PORT}/frames/frame.html\").ClickAsync(\"text=Hi, I'm frame\");`);
});
test('should record navigations after identical pushState', async ({ page, openRecorder, httpServer }) => {
test('should record navigations after identical pushState', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
httpServer.setHandler((req: http.IncomingMessage, res: http.ServerResponse) => {
server.setRoute('/page2.html', (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.end('Hello world');
});
await recorder.setContentAndWait(`
<script>
function pushState() {
history.pushState({}, 'title', '${httpServer.PREFIX}');
history.pushState({}, 'title', '${server.PREFIX}');
}
</script>`, httpServer.PREFIX);
</script>`, server.PREFIX);
for (let i = 1; i < 3; ++i)
await page.evaluate('pushState()');
await page.goto(httpServer.PREFIX + '/page2.html');
await recorder.waitForOutput('<javascript>', `await page.goto('${httpServer.PREFIX}/page2.html');`);
await page.goto(server.PREFIX + '/page2.html');
await recorder.waitForOutput('<javascript>', `await page.goto('${server.PREFIX}/page2.html');`);
});
test('should record slow navigation signal after mouse move', async ({ page, openRecorder, server }) => {

View file

@ -16,7 +16,7 @@
import path from 'path';
import fs from 'fs';
import { cliTest as test, expect } from '../config/cliTest';
import { test, expect } from './inspectorTest';
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { cliTest as test, expect } from '../config/cliTest';
import { test, expect } from './inspectorTest';
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { cliTest as test, expect } from '../config/cliTest';
import { test, expect } from './inspectorTest';
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { cliTest as test, expect } from '../config/cliTest';
import { test, expect } from './inspectorTest';
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { cliTest as test, expect } from '../config/cliTest';
import { test, expect } from './inspectorTest';
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {

View file

@ -14,9 +14,8 @@
* limitations under the License.
*/
import { contextTest } from './browserTest';
import { contextTest } from '../config/browserTest';
import type { Page } from '../../index';
import * as http from 'http';
import * as path from 'path';
import type { Source } from '../../src/server/supplements/recorder/recorderTypes';
import { ChildProcess, spawn } from 'child_process';
@ -24,23 +23,15 @@ import { chromium } from '../../index';
import * as folio from 'folio';
export { expect } from 'folio';
interface CLIHTTPServer {
setHandler: (handler: http.RequestListener) => void;
PREFIX: string;
}
type CLITestArgs = {
httpServer: CLIHTTPServer;
recorderPageGetter: () => Promise<Page>;
openRecorder: () => Promise<Recorder>;
runCLI: (args: string[]) => CLIMock;
};
export const cliTest = contextTest.extend({
export const test = contextTest.extend({
async beforeAll({}, workerInfo: folio.WorkerInfo) {
this._port = 10907 + workerInfo.workerIndex * 2;
this._server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => this._handler(req, res)).listen(this._port);
process.env.PWTEST_RECORDER_PORT = String(this._port + 1);
process.env.PWTEST_RECORDER_PORT = String(10907 + workerInfo.workerIndex);
},
async beforeEach({ page, context, toImpl, browserName, browserChannel, headful, mode }, testInfo: folio.TestInfo): Promise<CLITestArgs> {
@ -54,10 +45,6 @@ export const cliTest = contextTest.extend({
return c.pages()[0] || await c.waitForEvent('page');
};
return {
httpServer: {
setHandler: newHandler => this._handler = newHandler,
PREFIX: `http://127.0.0.1:${this._port}`,
},
runCLI: (cliArgs: string[]) => {
this._cli = new CLIMock(browserName, browserChannel, !headful, cliArgs);
return this._cli;
@ -76,13 +63,6 @@ export const cliTest = contextTest.extend({
this._cli = undefined;
}
},
async afterAll({}, workerInfo: folio.WorkerInfo) {
if (this._server) {
this._server.close();
this._server = undefined;
}
},
});
class Recorder {

View file

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Page } from '../index';
import { cliTest as it, expect } from './config/cliTest';
import { Page } from '../../index';
import { test as it, expect } from './inspectorTest';
it.describe('pause', () => {
it.skip(({ mode }) => mode !== 'default');