Skip to content

Commit

Permalink
test: merge test options into options (#3531)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Aug 19, 2020
1 parent 9ac1bbc commit a65b0bb
Show file tree
Hide file tree
Showing 46 changed files with 210 additions and 283 deletions.
3 changes: 1 addition & 2 deletions test/autowaiting-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/
import './base.fixture';
const { WIRE } = testOptions;

it('should await navigation when clicking anchor', async({page, server}) => {
const messages = [];
Expand Down Expand Up @@ -201,7 +200,7 @@ it('should work with goto following click', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
});

it.skip(WIRE)('should report navigation in the log when clicking anchor', async({page, server}) => {
it.skip(options.WIRE)('should report navigation in the log when clicking anchor', async({page, server}) => {
await page.setContent(`<a href="${server.PREFIX + '/frames/one-frame.html'}">click me</a>`);
const __testHookAfterPointerAction = () => new Promise(f => setTimeout(f, 6000));
const error = await page.click('a', { timeout: 5000, __testHookAfterPointerAction } as any).catch(e => e);
Expand Down
32 changes: 9 additions & 23 deletions test/base.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Transport } from '../lib/rpc/transport';
import { setUnderTest } from '../lib/helper';
import { installCoverageHooks } from './runner/coverage';
import { valueFromEnv } from './runner/utils';
import { registerFixture, registerWorkerFixture, registerOption } from './runner/fixtures';
import { registerFixture, registerWorkerFixture, registerOption, registerOptionGenerator } from './runner/fixtures';
import './runner/builtin.fixtures';

import {mkdtempAsync, removeFolderAsync} from './utils';
Expand All @@ -43,9 +43,6 @@ declare global {
browserType: BrowserType<Browser>;
browserName: string;
browser: Browser;
isChromium: boolean;
isFirefox: boolean;
isWebKit: boolean;
}
interface FixtureState {
toImpl: (rpcObject: any) => any;
Expand All @@ -60,6 +57,8 @@ declare global {
CHROMIUM: boolean;
FFOX: boolean;
WEBKIT: boolean;
HEADLESS: boolean;
WIRE: boolean;
}
}

Expand Down Expand Up @@ -104,14 +103,14 @@ registerWorkerFixture('defaultBrowserOptions', async({browserName}, test) => {
await test({
handleSIGINT: false,
slowMo: valueFromEnv('SLOW_MO', 0),
headless: !!valueFromEnv('HEADLESS', true),
headless: options.HEADLESS,
executablePath
});
});

registerWorkerFixture('playwright', async({parallelIndex, browserName}, test) => {
const {coverage, uninstall} = installCoverageHooks(browserName);
if (process.env.PWWIRE) {
if (options.WIRE) {
const connection = new Connection();
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'rpc', 'server'), [], {
stdio: 'pipe',
Expand Down Expand Up @@ -185,22 +184,6 @@ registerFixture('server', async ({httpService}, test) => {
await test(httpService.server);
});

registerWorkerFixture('browserName', async ({}, test) => {
await test(options.browserName);
});

registerWorkerFixture('isChromium', async ({}, test) => {
await test(options.browserName === 'chromium');
});

registerWorkerFixture('isFirefox', async ({}, test) => {
await test(options.browserName === 'firefox');
});

registerWorkerFixture('isWebKit', async ({}, test) => {
await test(options.browserName === 'webkit');
});

registerFixture('httpsServer', async ({httpService}, test) => {
httpService.httpsServer.reset();
await test(httpService.httpsServer);
Expand All @@ -220,11 +203,14 @@ registerWorkerFixture('golden', async ({browserName}, test) => {
await test(p => path.join(browserName, p));
});

registerOption('browserName', () => {
registerOptionGenerator('browserName', () => {
if (process.env.BROWSER)
return [process.env.BROWSER];
return ['chromium', 'webkit', 'firefox'];
});

registerOption('CHROMIUM', ({browserName}) => browserName === 'chromium');
registerOption('FFOX', ({browserName}) => browserName === 'firefox');
registerOption('WEBKIT', ({browserName}) => browserName === 'webkit');
registerOption('HEADLESS', ({}) => !!valueFromEnv('HEADLESS', true));
registerOption('WIRE', ({}) => process.env.PWWIRE);
6 changes: 2 additions & 4 deletions test/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
import './base.fixture';

import utils from './utils';

it('should create new page', async function({browser}) {
const page1 = await browser.newPage();
expect(browser.contexts().length).toBe(1);
Expand All @@ -39,9 +37,9 @@ it('should throw upon second create new page', async function({browser}) {
expect(error.message).toContain('Please use browser.newContext()');
});

it('version should work', async function({browser, isChromium}) {
it('version should work', async function({browser}) {
const version = browser.version();
if (isChromium)
if (options.CHROMIUM)
expect(version.match(/^\d+\.\d+\.\d+\.\d+$/)).toBeTruthy();
else
expect(version.match(/^\d+\.\d+/)).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions test/browsercontext-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ it('should close all belonging pages once closing context', async function({brow
expect(context.pages().length).toBe(0);
});

it('should disable javascript', async({browser, isWebKit}) => {
it('should disable javascript', async({browser}) => {
{
const context = await browser.newContext({ javaScriptEnabled: false });
const page = await context.newPage();
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
let error = null;
await page.evaluate('something').catch(e => error = e);
if (isWebKit)
if (options.WEBKIT)
expect(error.message).toContain('Can\'t find variable: something');
else
expect(error.message).toContain('something is not defined');
Expand Down
8 changes: 3 additions & 5 deletions test/browsercontext-credentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
import './base.fixture';

const { HEADLESS } = testOptions;

it.fail(options.CHROMIUM && !HEADLESS)('should fail without credentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should fail without credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
Expand All @@ -27,7 +25,7 @@ it.fail(options.CHROMIUM && !HEADLESS)('should fail without credentials', async(
await context.close();
});

it.fail(options.CHROMIUM && !HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
Expand All @@ -50,7 +48,7 @@ it('should work with correct credentials', async({browser, server}) => {
await context.close();
});

it.fail(options.CHROMIUM && !HEADLESS)('should fail with wrong credentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should fail with wrong credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'foo', password: 'bar' }
Expand Down
8 changes: 4 additions & 4 deletions test/browsertype-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ it('browserType.executablePath should work', async({browserType}) => {
expect(fs.realpathSync(executablePath)).toBe(executablePath);
});

it('browserType.name should work', async({browserType, isWebKit, isFirefox, isChromium}) => {
if (isWebKit)
it('browserType.name should work', async({browserType}) => {
if (options.WEBKIT)
expect(browserType.name()).toBe('webkit');
else if (isFirefox)
else if (options.FFOX)
expect(browserType.name()).toBe('firefox');
else if (isChromium)
else if (options.CHROMIUM)
expect(browserType.name()).toBe('chromium');
else
throw new Error('Unknown browser');
Expand Down
9 changes: 4 additions & 5 deletions test/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
import './base.fixture';

const { WIRE } = testOptions;

it.skip(WIRE).slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
it.skip(options.WIRE).slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
{
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
Expand All @@ -37,15 +36,15 @@ it.skip(WIRE).slow()('should be able to reconnect to a browser', async({browserT
await browserServer.close();
});

it.skip(WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
await browserServer.close();
expect(error.message).toContain('Dummy');
});

it.skip(WIRE)('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(remote.isConnected()).toBe(true);
Expand All @@ -54,7 +53,7 @@ it.skip(WIRE)('should set the browser connected state', async ({browserType, def
await browserServer.close();
});

it.skip(WIRE)('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage();
Expand Down
21 changes: 10 additions & 11 deletions test/browsertype-launch-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
import './base.fixture';

const { WIRE } = testOptions;

it.skip(WIRE)('should work', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should work', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browserContext = await browser.newContext();
Expand All @@ -31,7 +30,7 @@ it.skip(WIRE)('should work', async({browserType, defaultBrowserOptions}) => {
await browserServer.close();
});

it.skip(WIRE)('should fire "disconnected" when closing the server', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should fire "disconnected" when closing the server', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
Expand All @@ -43,7 +42,7 @@ it.skip(WIRE)('should fire "disconnected" when closing the server', async({brows
]);
});

it.skip(WIRE)('should fire "close" event during kill', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should fire "close" event during kill', async({browserType, defaultBrowserOptions}) => {
const order = [];
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const closedPromise = new Promise(f => browserServer.on('close', () => {
Expand All @@ -57,13 +56,13 @@ it.skip(WIRE)('should fire "close" event during kill', async({browserType, defau
expect(order).toEqual(['closed', 'killed']);
});

it.skip(WIRE)('should return child_process instance', async ({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should return child_process instance', async ({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
expect(browserServer.process().pid).toBeGreaterThan(0);
await browserServer.close();
});

it.skip(WIRE)('should fire close event', async ({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should fire close event', async ({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const [result] = await Promise.all([
new Promise(f => (browserServer as any).on('close', (exitCode, signal) => f({ exitCode, signal }))),
Expand All @@ -73,7 +72,7 @@ it.skip(WIRE)('should fire close event', async ({browserType, defaultBrowserOpti
expect(result['signal']).toBe(null);
});

it.skip(WIRE)('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => {
it.skip(options.WIRE)('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => {
server.setRoute('/one-style.css', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
Expand All @@ -86,7 +85,7 @@ it.skip(WIRE)('should reject navigation when browser closes', async({browserType
await browserServer.close();
});

it.skip(WIRE)('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => {
it.skip(options.WIRE)('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => {
server.setRoute('/empty.html', () => {});
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
Expand All @@ -102,7 +101,7 @@ it.skip(WIRE)('should reject waitForSelector when browser closes', async({browse
await browserServer.close();
});

it.skip(WIRE)('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage();
Expand All @@ -112,7 +111,7 @@ it.skip(WIRE)('should throw if used after disconnect', async({browserType, defau
await browserServer.close();
});

it.skip(WIRE)('should emit close events on pages and contexts', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should emit close events on pages and contexts', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const context = await remote.newContext();
Expand All @@ -126,7 +125,7 @@ it.skip(WIRE)('should emit close events on pages and contexts', async({browserTy
expect(pageClosed).toBeTruthy();
});

it.skip(WIRE)('should terminate network waiters', async({browserType, defaultBrowserOptions, server}) => {
it.skip(options.WIRE)('should terminate network waiters', async({browserType, defaultBrowserOptions, server}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const newPage = await remote.newPage();
Expand Down
7 changes: 3 additions & 4 deletions test/browsertype-launch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import path from 'path';
import './base.fixture';

const { WIRE } = testOptions;

it('should reject all promises when browser is closed', async({browserType, defaultBrowserOptions}) => {
const browser = await browserType.launch(defaultBrowserOptions);
Expand Down Expand Up @@ -60,22 +59,22 @@ it('should reject if executable path is invalid', async({browserType, defaultBro
expect(waitError.message).toContain('Failed to launch');
});

it.skip(WIRE)('should handle timeout', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should handle timeout', async({browserType, defaultBrowserOptions}) => {
const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };
const error = await browserType.launch(options).catch(e => e);
expect(error.message).toContain(`browserType.launch: Timeout 5000ms exceeded.`);
expect(error.message).toContain(`<launching>`);
expect(error.message).toContain(`<launched> pid=`);
});

it.skip(WIRE)('should handle exception', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should handle exception', async({browserType, defaultBrowserOptions}) => {
const e = new Error('Dummy');
const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 };
const error = await browserType.launch(options).catch(e => e);
expect(error.message).toContain('Dummy');
});

it.skip(WIRE)('should report launch log', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE)('should report launch log', async({browserType, defaultBrowserOptions}) => {
const e = new Error('Dummy');
const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 };
const error = await browserType.launch(options).catch(e => e);
Expand Down
7 changes: 3 additions & 4 deletions test/chromium/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ import path from 'path';
import utils from '../utils';
import { ChromiumBrowser, ChromiumBrowserContext } from '../..';
const { makeUserDataDir, removeUserDataDir } = utils;
const { WIRE } = testOptions;

it.skip(WIRE || !options.CHROMIUM)('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE || !options.CHROMIUM)('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => {
const options = Object.assign({}, defaultBrowserOptions);
options.args = ['--remote-debugging-pipe'].concat(options.args || []);
const error = await browserType.launchServer(options).catch(e => e);
expect(error.message).toContain('Playwright manages remote debugging connection itself');
});

it.skip(WIRE || !options.CHROMIUM)('should not throw with remote-debugging-port argument', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE || !options.CHROMIUM)('should not throw with remote-debugging-port argument', async({browserType, defaultBrowserOptions}) => {
const options = Object.assign({}, defaultBrowserOptions);
options.args = ['--remote-debugging-port=0'].concat(options.args || []);
const browser = await browserType.launchServer(options);
await browser.close();
});

it.skip(!options.CHROMIUM || WIRE || WIN)('should open devtools when "devtools: true" option is given', async({browserType, defaultBrowserOptions}) => {
it.skip(!options.CHROMIUM || options.WIRE || WIN)('should open devtools when "devtools: true" option is given', async({browserType, defaultBrowserOptions}) => {
let devtoolsCallback;
const devtoolsPromise = new Promise(f => devtoolsCallback = f);
const __testHookForDevTools = devtools => devtools.__testHookOnBinding = parsed => {
Expand Down
3 changes: 1 addition & 2 deletions test/click-timeout-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
import './base.fixture';

const { WIRE } = testOptions;

it.skip(WIRE)('should avoid side effects after timeout', async({page, server}) => {
it.skip(options.WIRE)('should avoid side effects after timeout', async({page, server}) => {
await page.goto(server.PREFIX + '/input/button.html');
const error = await page.click('button', { timeout: 2000, __testHookBeforePointerAction: () => new Promise(f => setTimeout(f, 2500))} as any).catch(e => e);
await page.waitForTimeout(5000); // Give it some time to click after the test hook is done waiting.
Expand Down
3 changes: 1 addition & 2 deletions test/click-timeout-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
import './base.fixture';

const { WIRE } = testOptions;

it.skip(WIRE)('should fail when element jumps during hit testing', async({page, server}) => {
it.skip(options.WIRE)('should fail when element jumps during hit testing', async({page, server}) => {
await page.setContent('<button>Click me</button>');
let clicked = false;
const handle = await page.$('button');
Expand Down
Loading

0 comments on commit a65b0bb

Please sign in to comment.