chore(test): convert some more tests to typescript (#3329)
This commit is contained in:
parent
ca3bd5e2ef
commit
83ac3f43f3
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
|
||||
const {USES_HOOKS} = testOptions;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
|
||||
it('clicking on links which do not commit navigation', async({page, server, httpsServer}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {CHROMIUM} = testOptions;
|
||||
|
||||
it('should create new page', async function({browser}) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM} = testOptions;
|
||||
|
||||
it('should work', async({context, page, server}) => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
|
||||
it('should clear cookies', async({context, page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {WEBKIT, WIN} = testOptions;
|
||||
|
||||
it('should return no cookies in pristine browser context', async({context, page, server}) => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {CHROMIUM, HEADLESS} = testOptions;
|
||||
|
||||
it.fail(CHROMIUM && !HEADLESS)('should fail without credentials', async({browser, server}) => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {FFOX} = testOptions;
|
||||
|
||||
it.skip(FFOX)('should work', async({playwright, browser, server}) => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {};
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL, HEADLESS} = testOptions;
|
||||
const {devices} = require('..');
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {CHROMIUM, FFOX, MAC, HEADLESS} = testOptions;
|
||||
|
||||
it('should affect accept-language header', async({browser, server}) => {
|
||||
|
|
@ -25,7 +25,7 @@ it('should affect accept-language header', async({browser, server}) => {
|
|||
server.waitForRequest('/empty.html'),
|
||||
page.goto(server.EMPTY_PAGE),
|
||||
]);
|
||||
expect(request.headers['accept-language'].substr(0, 5)).toBe('fr-CH');
|
||||
expect((request.headers['accept-language'] as string).substr(0, 5)).toBe('fr-CH');
|
||||
await context.close();
|
||||
});
|
||||
|
||||
|
|
@ -79,10 +79,10 @@ it('should format number in popups', async({browser, server}) => {
|
|||
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.evaluate(url => window._popup = window.open(url), server.PREFIX + '/formatted-number.html'),
|
||||
page.evaluate(url => window.open(url), server.PREFIX + '/formatted-number.html'),
|
||||
]);
|
||||
await popup.waitForLoadState('domcontentloaded');
|
||||
const result = await popup.evaluate(() => window.result);
|
||||
const result = await popup.evaluate('window.result');
|
||||
expect(result).toBe('1 000 000,5');
|
||||
await context.close();
|
||||
});
|
||||
|
|
@ -93,10 +93,10 @@ it('should affect navigator.language in popups', async({browser, server}) => {
|
|||
await page.goto(server.EMPTY_PAGE);
|
||||
const [popup] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.evaluate(url => window._popup = window.open(url), server.PREFIX + '/formatted-number.html'),
|
||||
page.evaluate(url => window.open(url), server.PREFIX + '/formatted-number.html'),
|
||||
]);
|
||||
await popup.waitForLoadState('domcontentloaded');
|
||||
const result = await popup.evaluate(() => window.initialNavigatorLanguage);
|
||||
const result = await popup.evaluate('window.initialNavigatorLanguage');
|
||||
expect(result).toBe('fr-CH');
|
||||
await context.close();
|
||||
});
|
||||
|
|
@ -14,8 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL, HEADLESS} = testOptions;
|
||||
const {devices} = require('..');
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL, HEADLESS} = testOptions;
|
||||
const {devices} = require('..');
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {CHROMIUM, FFOX, MAC, HEADLESS} = testOptions;
|
||||
|
||||
it('should work', async ({ browser }) => {
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL, HEADLESS} = testOptions;
|
||||
const {devices} = require('..');
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {CHROMIUM, FFOX, MAC, HEADLESS} = testOptions;
|
||||
|
||||
it.skip(FFOX)('should support mobile emulation', async({playwright, browser, server}) => {
|
||||
|
|
@ -66,7 +66,7 @@ it.skip(FFOX)('should detect touch when applying viewport with touches', async({
|
|||
const page = await context.newPage();
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.addScriptTag({url: server.PREFIX + '/modernizr.js'});
|
||||
expect(await page.evaluate(() => Modernizr.touchevents)).toBe(true);
|
||||
expect(await page.evaluate(() => window['Modernizr'].touchevents)).toBe(true);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
|
|
@ -99,8 +99,8 @@ it.skip(FFOX)('should fire orientationchange event', async({browser, server}) =>
|
|||
const page = await context.newPage();
|
||||
await page.goto(server.PREFIX + '/mobile.html');
|
||||
await page.evaluate(() => {
|
||||
window.counter = 0;
|
||||
window.addEventListener('orientationchange', () => console.log(++window.counter));
|
||||
let counter = 0;
|
||||
window.addEventListener('orientationchange', () => console.log(++counter));
|
||||
});
|
||||
|
||||
const event1 = page.waitForEvent('console');
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {CHROMIUM, FFOX, MAC, HEADLESS} = testOptions;
|
||||
|
||||
it('should get the proper default viewport size', async({page, server}) => {
|
||||
|
|
@ -15,9 +15,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const utils = require('./utils');
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
|
||||
|
||||
it('browserType.executablePath should work', async({browserType}) => {
|
||||
|
|
@ -15,9 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const utils = require('./utils');
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
|
||||
|
||||
it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {
|
||||
|
|
@ -36,15 +34,15 @@ it.slow()('should be able to reconnect to a browser', async({browserType, defaul
|
|||
await page.goto(server.EMPTY_PAGE);
|
||||
await browser.close();
|
||||
}
|
||||
await browserServer._checkLeaks();
|
||||
await (browserServer as any)._checkLeaks();
|
||||
await browserServer.close();
|
||||
});
|
||||
|
||||
it.fail(USES_HOOKS || (CHROMIUM && WIN)).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions, server}) => {
|
||||
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
||||
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
|
||||
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser }).catch(e => e);
|
||||
await browserServer._checkLeaks();
|
||||
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
|
||||
await (browserServer as any)._checkLeaks();
|
||||
await browserServer.close();
|
||||
expect(error.message).toContain('Dummy');
|
||||
});
|
||||
|
|
@ -55,7 +53,7 @@ it('should set the browser connected state', async ({browserType, defaultBrowser
|
|||
expect(remote.isConnected()).toBe(true);
|
||||
await remote.close();
|
||||
expect(remote.isConnected()).toBe(false);
|
||||
await browserServer._checkLeaks();
|
||||
await (browserServer as any)._checkLeaks();
|
||||
await browserServer.close();
|
||||
});
|
||||
|
||||
|
|
@ -68,6 +66,6 @@ it('should throw when used after isConnected returns false', async({browserType,
|
|||
new Promise(f => remote.once('disconnected', f)),
|
||||
]);
|
||||
expect(remote.isConnected()).toBe(false);
|
||||
const error = await page.evaluate('1 + 1').catch(e => e);
|
||||
const error = await page.evaluate('1 + 1').catch(e => e) as Error;
|
||||
expect(error.message).toContain('has been closed');
|
||||
});
|
||||
|
|
@ -15,9 +15,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const utils = require('./utils');
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS, CHANNEL} = testOptions;
|
||||
|
||||
it('should reject all promises when browser is closed', async({browserType, defaultBrowserOptions}) => {
|
||||
|
|
@ -83,7 +83,7 @@ it.skip(USES_HOOKS)('should report launch log', async({browserType, defaultBrows
|
|||
});
|
||||
|
||||
it.slow()('should accept objects as options', async({browserType, defaultBrowserOptions}) => {
|
||||
const browser = await browserType.launch({ ...defaultBrowserOptions, process });
|
||||
const browser = await browserType.launch({ ...defaultBrowserOptions, process } as any);
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
|
|
@ -14,14 +14,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
|
||||
const {FFOX, CHROMIUM, WEBKIT, WIN, LINUX, ASSETS_DIR} = testOptions;
|
||||
|
||||
it.fail(WEBKIT && WIN)('Web Assembly should work', async function({page, server}) {
|
||||
await page.goto(server.PREFIX + '/wasm/table2.html');
|
||||
expect(await page.evaluate(() => loadTable())).toBe('42, 83');
|
||||
expect(await page.evaluate('loadTable()')).toBe('42, 83');
|
||||
});
|
||||
|
||||
it('WebSocket should work', async({page, server}) => {
|
||||
|
|
@ -47,7 +47,7 @@ it('should respect CSP', async({page, server}) => {
|
|||
});
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(await page.evaluate(() => window.testStatus)).toBe('SUCCESS');
|
||||
expect(await page.evaluate(() => window['testStatus'])).toBe('SUCCESS');
|
||||
});
|
||||
|
||||
it.fail(WEBKIT && WIN)('should play video', async({page}) => {
|
||||
|
|
@ -15,10 +15,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import utils from './utils';
|
||||
import { ChromiumBrowser } from '../types/types';
|
||||
const { FFOX, CHROMIUM, WEBKIT, WIN, CHANNEL } = testOptions;
|
||||
|
||||
it.skip(!CHANNEL)('should work', async({browser}) => {
|
||||
expect(!!browser._connection).toBeTruthy();
|
||||
expect(!!browser['_connection']).toBeTruthy();
|
||||
});
|
||||
|
||||
it.skip(!CHANNEL)('should scope context handles', async({browserType, browser, server}) => {
|
||||
|
|
@ -81,7 +83,7 @@ it.skip(!CHANNEL || !CHROMIUM)('should scope CDPSession handles', async({browser
|
|||
};
|
||||
await expectScopeState(browserType, GOLDEN_PRECONDITION);
|
||||
|
||||
const session = await browser.newBrowserCDPSession();
|
||||
const session = await (browser as ChromiumBrowser).newBrowserCDPSession();
|
||||
await expectScopeState(browserType, {
|
||||
_guid: '',
|
||||
objects: [
|
||||
|
|
@ -18,43 +18,43 @@
|
|||
it('should check the box', async({page}) => {
|
||||
await page.setContent(`<input id='checkbox' type='checkbox'></input>`);
|
||||
await page.check('input');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should not check the checked box', async({page}) => {
|
||||
await page.setContent(`<input id='checkbox' type='checkbox' checked></input>`);
|
||||
await page.check('input');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should uncheck the box', async({page}) => {
|
||||
await page.setContent(`<input id='checkbox' type='checkbox' checked></input>`);
|
||||
await page.uncheck('input');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(false);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(false);
|
||||
});
|
||||
|
||||
it('should not uncheck the unchecked box', async({page}) => {
|
||||
await page.setContent(`<input id='checkbox' type='checkbox'></input>`);
|
||||
await page.uncheck('input');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(false);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(false);
|
||||
});
|
||||
|
||||
it('should check the box by label', async({page}) => {
|
||||
await page.setContent(`<label for='checkbox'><input id='checkbox' type='checkbox'></input></label>`);
|
||||
await page.check('label');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should check the box outside label', async({page}) => {
|
||||
await page.setContent(`<label for='checkbox'>Text</label><div><input id='checkbox' type='checkbox'></input></div>`);
|
||||
await page.check('label');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should check the box inside label w/o id', async({page}) => {
|
||||
await page.setContent(`<label>Text<span><input id='checkbox' type='checkbox'></input></span></label>`);
|
||||
await page.check('label');
|
||||
expect(await page.evaluate(() => checkbox.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should check radio', async({page}) => {
|
||||
|
|
@ -63,7 +63,7 @@ it('should check radio', async({page}) => {
|
|||
<input id='two' type='radio'>two</input>
|
||||
<input type='radio'>three</input>`);
|
||||
await page.check('#two');
|
||||
expect(await page.evaluate(() => two.checked)).toBe(true);
|
||||
expect(await page.evaluate(() => window['two'].checked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should check the box by aria role', async({page}) => {
|
||||
|
|
@ -72,5 +72,5 @@ it('should check the box by aria role', async({page}) => {
|
|||
checkbox.addEventListener('click', () => checkbox.setAttribute('aria-checked', 'true'));
|
||||
</script>`);
|
||||
await page.check('div');
|
||||
expect(await page.evaluate(() => checkbox.getAttribute('aria-checked'))).toBe('true');
|
||||
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('true');
|
||||
});
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import utils from './utils';
|
||||
const {FFOX, CHROMIUM, WEBKIT} = testOptions;
|
||||
|
||||
it.skip(!CHROMIUM)('should work', async function({browserType, page, server}) {
|
||||
23
test/types.d.ts
vendored
23
test/types.d.ts
vendored
|
|
@ -2,25 +2,6 @@ type ServerResponse = import('http').ServerResponse;
|
|||
type IncomingMessage = import('http').IncomingMessage;
|
||||
|
||||
type Falsy = false|''|0|null|undefined;
|
||||
interface Expect<T> {
|
||||
toBe(other: T, message?: string): void;
|
||||
toBeFalsy(message?: string): void;
|
||||
toBeTruthy(message?: string): void;
|
||||
toContain(other: any, message?: string): void;
|
||||
toEqual(other: T, message?: string): void;
|
||||
toBeNull(message?: string): void;
|
||||
toBeInstanceOf(other: Function, message?: string): void;
|
||||
|
||||
toBeGreaterThan(other: number, message?: string): void;
|
||||
toBeGreaterThanOrEqual(other: number, message?: string): void;
|
||||
toBeLessThan(other: number, message?: string): void;
|
||||
toBeLessThanOrEqual(other: number, message?: string): void;
|
||||
toBeCloseTo(other: number, precision: number, message?: string): void;
|
||||
|
||||
toBeGolden(golden: {goldenPath: string, outputPath: string, goldenName: string}): void;
|
||||
|
||||
not: Expect<T>;
|
||||
}
|
||||
|
||||
type DescribeFunction = ((name: string, inner: () => void) => void) & {fail(condition: boolean): DescribeFunction};
|
||||
|
||||
|
|
@ -48,7 +29,6 @@ interface TestSetup<STATE> {
|
|||
testRunner: TestRunner<STATE>;
|
||||
product: 'Chromium'|'Firefox'|'WebKit';
|
||||
selectors: import('../index').Selectors;
|
||||
expect<T>(value: T): Expect<T>;
|
||||
playwrightPath;
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +76,7 @@ interface TestServer {
|
|||
declare const describe: DescribeFunction;
|
||||
declare const fdescribe: DescribeFunction;
|
||||
declare const xdescribe: DescribeFunction;
|
||||
declare function expect<T>(value: T): Expect<T>;
|
||||
declare const expect: typeof import('expect');
|
||||
declare const it: ItFunction<PageState>;
|
||||
declare const fit: ItFunction<PageState>;
|
||||
declare const dit: ItFunction<PageState>;
|
||||
|
|
@ -116,6 +96,7 @@ declare const testOptions: {
|
|||
OUTPUT_DIR: string;
|
||||
USES_HOOKS: boolean;
|
||||
CHANNEL: boolean;
|
||||
ASSETS_DIR: string;
|
||||
};
|
||||
|
||||
// keyboard.html
|
||||
|
|
|
|||
Loading…
Reference in a new issue