test: put test runner api on global, remove unused parameters (#1684)

This commit is contained in:
Dmitry Gozman 2020-04-07 08:10:31 -07:00 committed by GitHub
parent e15fc08d46
commit e0c8fbf1a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 70 additions and 236 deletions

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Accessibility', function() { describe('Accessibility', function() {
it('should work', async function({page}) { it('should work', async function({page}) {

View file

@ -1,12 +0,0 @@
<script src='../../web.js'></script>
<script>
async function setup(product, wsEndpoint) {
window.browser = await window.playwrightweb[product].connect(wsEndpoint);
window.context = await window.browser.newContext();
window.page = await window.context.newPage();
}
async function teardown() {
await window.context.close();
await window.browser.close();
}
</script>

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Auto waiting', () => { describe('Auto waiting', () => {
it('should await navigation when clicking anchor', async({page, server}) => { it('should await navigation when clicking anchor', async({page, server}) => {

View file

@ -14,15 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
const utils = require('./utils');
/** /**
* @type {BrowserTestSuite} * @type {BrowserTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Browser.newPage', function() { describe('Browser.newPage', function() {
it('should create new page', async function({browser}) { it('should create new page', async function({browser}) {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {BrowserTestSuite} * @type {BrowserTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FFOX, WEBKIT, LINUX}) { module.exports.describe = function({playwright, CHROMIUM, FFOX, WEBKIT, LINUX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('BrowserContext', function() { describe('BrowserContext', function() {
it('should create new context', async function({browser}) { it('should create new context', async function({browser}) {

View file

@ -14,16 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
const utils = require('./utils');
const { waitEvent } = utils;
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, WIN, WEBKIT}) { module.exports.describe = function({WIN, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Capabilities', function() { describe('Capabilities', function() {
it.fail(WEBKIT && WIN)('Web Assembly should work', async function({page, server}) { it.fail(WEBKIT && WIN)('Web Assembly should work', async function({page, server}) {

View file

@ -14,15 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
const { waitEvent } = require('../utils');
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('ChromiumBrowserContext', function() { describe('ChromiumBrowserContext', function() {
it('should create a worker from a service worker', async({browser, page, server, context}) => { it('should create a worker from a service worker', async({browser, page, server, context}) => {

View file

@ -17,10 +17,7 @@
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('JSCoverage', function() { describe('JSCoverage', function() {
it('should work', async function({page, server}) { it('should work', async function({page, server}) {

View file

@ -18,21 +18,12 @@ const util = require('util');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const os = require('os'); const os = require('os');
const readFileAsync = util.promisify(fs.readFile);
const rmAsync = util.promisify(require('rimraf'));
const mkdtempAsync = util.promisify(fs.mkdtemp);
const statAsync = util.promisify(fs.stat);
const { makeUserDataDir, removeUserDataDir } = require('../utils'); const { makeUserDataDir, removeUserDataDir } = require('../utils');
const TMP_FOLDER = path.join(os.tmpdir(), 'pw_tmp_folder-');
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, browserType, WIN}) { module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false

View file

@ -17,10 +17,7 @@
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false

View file

@ -20,15 +20,12 @@ const path = require('path');
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, headless, ASSETS_DIR}) { module.exports.describe = function({headless, OUTPUT_DIR}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
// Printing to pdf is currently only supported in headless // Printing to pdf is currently only supported in headless
describe.fail(!headless)('Page.pdf', function() { describe.fail(!headless)('Page.pdf', function() {
it('should be able to save file', async({page, server}) => { it('should be able to save file', async({page, server}) => {
const outputFile = path.join(ASSETS_DIR, 'output.pdf'); const outputFile = path.join(OUTPUT_DIR, 'output.pdf');
await page.pdf({path: outputFile}); await page.pdf({path: outputFile});
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0); expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
fs.unlinkSync(outputFile); fs.unlinkSync(outputFile);

View file

@ -19,10 +19,7 @@ const { waitEvent } = require('../utils');
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('ChromiumBrowserContext.createSession', function() { describe('ChromiumBrowserContext.createSession', function() {
it('should work', async function({page, browser, server}) { it('should work', async function({page, browser, server}) {

View file

@ -20,14 +20,11 @@ const path = require('path');
/** /**
* @type {ChromiumTestSuite} * @type {ChromiumTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, browserType, ASSETS_DIR}) { module.exports.describe = function({defaultBrowserOptions, browserType, OUTPUT_DIR}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Chromium.startTracing', function() { describe('Chromium.startTracing', function() {
beforeEach(async function(state) { beforeEach(async function(state) {
state.outputFile = path.join(ASSETS_DIR, `trace-${state.parallelIndex}.json`); state.outputFile = path.join(OUTPUT_DIR, `trace-${state.parallelIndex}.json`);
state.browser = await browserType.launch(defaultBrowserOptions); state.browser = await browserType.launch(defaultBrowserOptions);
state.page = await state.browser.newPage(); state.page = await state.browser.newPage();
}); });

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.click', function() { describe('Page.click', function() {
it('should click the button', async({page, server}) => { it('should click the button', async({page, server}) => {

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, browserType, defaultBrowserOptions, MAC, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({browserType, defaultBrowserOptions, MAC, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('BrowserContext.cookies', function() { describe('BrowserContext.cookies', function() {
it('should return no cookies in pristine browser context', async({context, page, server}) => { it('should return no cookies in pristine browser context', async({context, page, server}) => {

View file

@ -20,10 +20,7 @@ const { makeUserDataDir, removeUserDataDir } = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function ({ testRunner, expect, defaultBrowserOptions, browserType, WEBKIT }) { module.exports.describe = function ({ defaultBrowserOptions, browserType, WEBKIT }) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('launchPersistentContext()', function() { describe('launchPersistentContext()', function() {
beforeEach(async state => { beforeEach(async state => {

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.Events.Dialog', function() { describe('Page.Events.Dialog', function() {
it('should fire', async({page, server}) => { it('should fire', async({page, server}) => {

View file

@ -17,10 +17,7 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
module.exports.describe = function({testRunner, expect, browserType, CHROMIUM, WEBKIT, FFOX, WIN, MAC}) { module.exports.describe = function({browserType, CHROMIUM, WEBKIT, FFOX, WIN, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe.fail(FFOX)('Download', function() { describe.fail(FFOX)('Download', function() {
beforeEach(async(state) => { beforeEach(async(state) => {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('ElementHandle.boundingBox', function() { describe('ElementHandle.boundingBox', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, headless, FFOX, CHROMIUM, WEBKIT, MAC, WIN}) { module.exports.describe = function({playwright, headless, FFOX, CHROMIUM, WEBKIT, MAC, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const iPhone = playwright.devices['iPhone 6']; const iPhone = playwright.devices['iPhone 6'];
const iPhoneLandscape = playwright.devices['iPhone 6 landscape']; const iPhoneLandscape = playwright.devices['iPhone 6 landscape'];

View file

@ -17,15 +17,11 @@
const utils = require('./utils'); const utils = require('./utils');
const path = require('path'); const path = require('path');
const bigint = typeof BigInt !== 'undefined';
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, LINUX}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.evaluate', function() { describe('Page.evaluate', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -21,10 +21,7 @@ const {spawn, execSync} = require('child_process');
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.describe = function({testRunner, expect, product, browserType, playwrightPath, defaultBrowserOptions, WIN, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({browserType, playwrightPath, defaultBrowserOptions, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
async function testSignal(action, exitOnClose) { async function testSignal(action, exitOnClose) {
const options = Object.assign({}, defaultBrowserOptions, { const options = Object.assign({}, defaultBrowserOptions, {
@ -34,7 +31,7 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
handleSIGTERM: true, handleSIGTERM: true,
handleSIGHUP: true, handleSIGHUP: true,
}); });
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options), exitOnClose ? 'true' : '']); const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, browserType.name(), JSON.stringify(options), exitOnClose ? 'true' : '']);
let wsEndPointCallback; let wsEndPointCallback;
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x); const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
let output = ''; let output = '';
@ -71,14 +68,7 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
describe('Fixtures', function() { describe('Fixtures', function() {
it.slow()('should dump browser process stderr', async({server}) => { it.slow()('should dump browser process stderr', async({server}) => {
let dumpioData = ''; let dumpioData = '';
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product, 'usewebsocket']); const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, browserType.name()]);
res.stdout.on('data', data => dumpioData += data.toString('utf8'));
await new Promise(resolve => res.on('close', resolve));
expect(dumpioData).toContain('message from dumpio');
});
it.slow()('should dump browser process stderr', async({server}) => {
let dumpioData = '';
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product]);
res.stdout.on('data', data => dumpioData += data.toString('utf8')); res.stdout.on('data', data => dumpioData += data.toString('utf8'));
await new Promise(resolve => res.on('close', resolve)); await new Promise(resolve => res.on('close', resolve));
expect(dumpioData).toContain('message from dumpio'); expect(dumpioData).toContain('message from dumpio');

View file

@ -1,6 +1,6 @@
(async() => { (async() => {
const [, , playwrightRoot, product, options, exitOnClose] = process.argv; const [, , playwrightRoot, browserType, options, exitOnClose] = process.argv;
const browserServer = await require(playwrightRoot)[product.toLowerCase()].launchServer(JSON.parse(options)); const browserServer = await require(playwrightRoot)[browserType].launchServer(JSON.parse(options));
browserServer.on('close', (exitCode, signal) => { browserServer.on('close', (exitCode, signal) => {
console.log(`browserClose:${exitCode}:${signal}:browserClose`); console.log(`browserClose:${exitCode}:${signal}:browserClose`);
if (exitOnClose) if (exitOnClose)

View file

@ -4,7 +4,7 @@
console.log('unhandledRejection', error.message); console.log('unhandledRejection', error.message);
}); });
const [, , playwrightRoot, product, useWebSocket] = process.argv; const [, , playwrightRoot, browserType] = process.argv;
const options = { const options = {
ignoreDefaultArgs: true, ignoreDefaultArgs: true,
dumpio: true, dumpio: true,
@ -12,9 +12,8 @@
executablePath: 'node', executablePath: 'node',
args: ['-e', 'console.error("message from dumpio")', '--'] args: ['-e', 'console.error("message from dumpio")', '--']
} }
console.error('using web socket: ' + options.webSocket);
try { try {
await require(playwrightRoot)[product.toLowerCase()].launchServer(options); await require(playwrightRoot)[browserType].launchServer(options);
console.error('Browser launch unexpectedly succeeded.'); console.error('Browser launch unexpectedly succeeded.');
} catch (e) { } catch (e) {
} }

View file

@ -14,16 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
const utils = require('./utils');
const { waitEvent } = utils;
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect}) { module.exports.describe = function({}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.focus', function() { describe('Page.focus', function() {
it('should work', async function({page, server}) { it('should work', async function({page, server}) {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Frame.evaluateHandle', function() { describe('Frame.evaluateHandle', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function ({ testRunner, expect, FFOX, WEBKIT }) { module.exports.describe = function ({ FFOX, WEBKIT }) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Overrides.setGeolocation', function() { describe('Overrides.setGeolocation', function() {
it('should work', async({page, server, context}) => { it('should work', async({page, server, context}) => {

View file

@ -19,10 +19,7 @@ const { makeUserDataDir, removeUserDataDir } = require('./utils');
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.describe = function({testRunner, expect, browserType, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) { module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false

View file

@ -18,10 +18,8 @@
/** /**
* @type {BrowserTestSuite} * @type {BrowserTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('ignoreHTTPSErrors', function() { describe('ignoreHTTPSErrors', function() {
it('should work', async({browser, httpsServer}) => { it('should work', async({browser, httpsServer}) => {
let error = null; let error = null;
@ -40,7 +38,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e); const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
expect(error).toBe(null); expect(error).toBe(null);
expect(response.ok()).toBe(true); expect(response.ok()).toBe(true);
await context.close(); await context.close();
} }
{ {
let error = null; let error = null;
@ -48,7 +46,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
const page = await context.newPage(); const page = await context.newPage();
await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e); await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
expect(error).not.toBe(null); expect(error).not.toBe(null);
await context.close(); await context.close();
} }
}); });
it('should work with mixed content', async({browser, server, httpsServer}) => { it('should work with mixed content', async({browser, server, httpsServer}) => {

View file

@ -24,10 +24,8 @@ const FILE_TO_UPLOAD = path.join(__dirname, '/assets/file-to-upload.txt');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('input', function() { describe('input', function() {
it('should upload the file', async({page, server}) => { it('should upload the file', async({page, server}) => {
await page.goto(server.PREFIX + '/input/fileupload.html'); await page.goto(server.PREFIX + '/input/fileupload.html');

View file

@ -24,10 +24,7 @@ const vm = require('vm');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.route', function() { describe('Page.route', function() {
it('should intercept', async({page, server}) => { it('should intercept', async({page, server}) => {

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT}) { module.exports.describe = function({CHROMIUM, FFOX, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.evaluateHandle', function() { describe('Page.evaluateHandle', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -21,10 +21,7 @@ const os = require('os');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Keyboard', function() { describe('Keyboard', function() {
it('should type into a textarea', async({page, server}) => { it('should type into a textarea', async({page, server}) => {

View file

@ -23,10 +23,7 @@ const { makeUserDataDir, removeUserDataDir } = require('./utils');
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, browserType, playwrightPath, product, CHROMIUM, FFOX, WEBKIT, WIN}) { module.exports.describe = function({defaultBrowserOptions, playwright, browserType, playwrightPath, CHROMIUM, FFOX, WEBKIT, WIN}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Playwright', function() { describe('Playwright', function() {
describe('browserType.launch', function() { describe('browserType.launch', function() {

View file

@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const os = require('os');
function dimensions() { function dimensions() {
const rect = document.querySelector('textarea').getBoundingClientRect(); const rect = document.querySelector('textarea').getBoundingClientRect();
@ -29,10 +28,7 @@ function dimensions() {
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, MAC}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Mouse', function() { describe('Mouse', function() {
it('should click the document', async({page, server}) => { it('should click the document', async({page, server}) => {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('BrowserContext', function() { describe('BrowserContext', function() {
it('should work across sessions', async () => { it('should work across sessions', async () => {

View file

@ -22,10 +22,7 @@ const url = require('url');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.goto', function() { describe('Page.goto', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -22,10 +22,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.Events.Request', function() { describe('Page.Events.Request', function() {
it('should fire for navigation requests', async({page, server}) => { it('should fire for navigation requests', async({page, server}) => {

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const fs = require('fs');
const path = require('path'); const path = require('path');
const utils = require('./utils'); const utils = require('./utils');
const {waitEvent} = utils; const {waitEvent} = utils;
@ -23,10 +23,7 @@ const vm = require('vm');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, headless, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.close', function() { describe('Page.close', function() {
it('should reject all promises when page is closed', async({context}) => { it('should reject all promises when page is closed', async({context}) => {

View file

@ -15,16 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
const fs = require('fs');
const path = require('path');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, WEBKIT, FFOX}) { module.exports.describe = function({WEBKIT, FFOX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
// Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API) // Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API)
describe.skip(WEBKIT)('Permissions', function() { describe.skip(WEBKIT)('Permissions', function() {

View file

@ -49,11 +49,7 @@ const browserNames = BROWSER_CONFIGS.map(config => config.name);
/** /**
* @type {TestSuite} * @type {TestSuite}
*/ */
module.exports.addPlaywrightTests = ({testRunner, platform, products, playwrightPath, headless, slowMo, dumpProtocolOnFailure, coverage}) => { module.exports.addPlaywrightTests = ({platform, products, playwrightPath, headless, slowMo, dumpProtocolOnFailure, coverage}) => {
const {describe, xdescribe, fdescribe} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
const {expect} = testRunner;
const MAC = platform === 'darwin'; const MAC = platform === 'darwin';
const LINUX = platform === 'linux'; const LINUX = platform === 'linux';
const WIN = platform === 'win32'; const WIN = platform === 'win32';
@ -121,14 +117,12 @@ module.exports.addPlaywrightTests = ({testRunner, platform, products, playwright
const GOLDEN_DIR = path.join(__dirname, 'golden-' + product.toLowerCase()); const GOLDEN_DIR = path.join(__dirname, 'golden-' + product.toLowerCase());
const OUTPUT_DIR = path.join(__dirname, 'output-' + product.toLowerCase()); const OUTPUT_DIR = path.join(__dirname, 'output-' + product.toLowerCase());
const ASSETS_DIR = path.join(__dirname, 'assets');
if (fs.existsSync(OUTPUT_DIR)) if (fs.existsSync(OUTPUT_DIR))
rm(OUTPUT_DIR); rm(OUTPUT_DIR);
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
expect.setupGolden(GOLDEN_DIR, OUTPUT_DIR); expect.setupGolden(GOLDEN_DIR, OUTPUT_DIR);
const testOptions = { const testOptions = {
testRunner,
product,
FFOX, FFOX,
WEBKIT, WEBKIT,
CHROMIUM, CHROMIUM,
@ -137,11 +131,10 @@ module.exports.addPlaywrightTests = ({testRunner, platform, products, playwright
WIN, WIN,
browserType, browserType,
playwright, playwright,
expect,
defaultBrowserOptions, defaultBrowserOptions,
playwrightPath, playwrightPath,
headless: !!defaultBrowserOptions.headless, headless: !!defaultBrowserOptions.headless,
ASSETS_DIR, OUTPUT_DIR,
}; };
function loadTests(modulePath) { function loadTests(modulePath) {
@ -281,7 +274,7 @@ module.exports.addPlaywrightTests = ({testRunner, platform, products, playwright
return; return;
filteredApi[apiName] = api[apiName]; filteredApi[apiName] = api[apiName];
}); });
require('./utils').recordAPICoverage(testRunner, filteredApi, browserConfig.events, browserConfig.missingCoverage); require('./utils').recordAPICoverage(filteredApi, browserConfig.events, browserConfig.missingCoverage);
} }
}); });
} }

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEBKIT, FFOX}) { module.exports.describe = function({playwright, CHROMIUM, WEBKIT, FFOX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Link navigation', function() { describe('Link navigation', function() {
it('should inherit user agent from browser context', async function({browser, server}) { it('should inherit user agent from browser context', async function({browser, server}) {

View file

@ -21,10 +21,7 @@ const zsSelectorEngineSource = require('../lib/generated/zsSelectorEngineSource'
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.$eval', function() { describe('Page.$eval', function() {
it('should work with css selector', async({page, server}) => { it('should work with css selector', async({page, server}) => {

View file

@ -18,10 +18,7 @@
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, product, playwright, FFOX, CHROMIUM, WEBKIT, LINUX }) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX }) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.screenshot', function() { describe('Page.screenshot', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {

View file

@ -68,16 +68,22 @@ function valueFromEnv(name, defaultValue) {
return JSON.parse(process.env[name]); return JSON.parse(process.env[name]);
} }
for (const [key, value] of Object.entries(testRunner.api()))
global[key] = value;
require('./playwright.spec.js').addPlaywrightTests({ require('./playwright.spec.js').addPlaywrightTests({
playwrightPath: utils.projectRoot(), playwrightPath: utils.projectRoot(),
products, products,
platform: os.platform(), platform: os.platform(),
testRunner: testRunner.api(),
headless: !!valueFromEnv('HEADLESS', true), headless: !!valueFromEnv('HEADLESS', true),
slowMo: valueFromEnv('SLOW_MO', 0), slowMo: valueFromEnv('SLOW_MO', 0),
dumpProtocolOnFailure: valueFromEnv('DEBUGP', false), dumpProtocolOnFailure: valueFromEnv('DEBUGP', false),
coverage: process.env.COVERAGE, coverage: process.env.COVERAGE,
}); });
for (const [key, value] of Object.entries(testRunner.api())) {
// expect is used when running tests, while the rest of api is not.
if (key !== 'expect')
delete global[key];
}
const filterArgIndex = process.argv.indexOf('--filter'); const filterArgIndex = process.argv.indexOf('--filter');
if (filterArgIndex !== -1) { if (filterArgIndex !== -1) {
@ -86,4 +92,4 @@ if (filterArgIndex !== -1) {
} }
// await utils.initializeFlakinessDashboardIfNeeded(testRunner); // await utils.initializeFlakinessDashboardIfNeeded(testRunner);
testRunner.run(); testRunner.run().then(() => { delete global.expect; });

View file

@ -80,13 +80,13 @@ const utils = module.exports = {
return promisified; return promisified;
}, },
recordAPICoverage: function(testRunner, api, events, ignoredMethodsArray = []) { recordAPICoverage: function(api, events, ignoredMethodsArray = []) {
const coverage = new Map(); const coverage = new Map();
const ignoredMethods = new Set(ignoredMethodsArray); const ignoredMethods = new Set(ignoredMethodsArray);
for (const [className, classType] of Object.entries(api)) for (const [className, classType] of Object.entries(api))
traceAPICoverage(coverage, events, className, classType); traceAPICoverage(coverage, events, className, classType);
testRunner.describe(COVERAGE_TESTSUITE_NAME, () => { describe(COVERAGE_TESTSUITE_NAME, () => {
testRunner.it('should call all API methods', () => { it('should call all API methods', () => {
const missingMethods = []; const missingMethods = [];
const extraIgnoredMethods = []; const extraIgnoredMethods = [];
for (const method of coverage.keys()) { for (const method of coverage.keys()) {

View file

@ -20,10 +20,7 @@ const utils = require('./utils');
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, product, playwright, FFOX, CHROMIUM, WEBKIT}) { module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Page.waitFor', function() { describe('Page.waitFor', function() {
it('should wait for selector', async({page, server}) => { it('should wait for selector', async({page, server}) => {

View file

@ -21,10 +21,7 @@ const { waitEvent } = utils;
/** /**
* @type {PageTestSuite} * @type {PageTestSuite}
*/ */
module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT, LINUX}) { module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('Workers', function() { describe('Workers', function() {
it('Page.workers', async function({page, server}) { it('Page.workers', async function({page, server}) {