Skip to content

Commit bfaf191

Browse files
authored
test: add missing tests (#965)
Chromium tests on Linux now call all our API methods and events at least once!
1 parent 1d84f38 commit bfaf191

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

src/page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class Page extends platform.EventEmitter {
216216
}
217217

218218
async $wait(selector: string, options?: types.TimeoutOptions & { visibility?: types.Visibility }): Promise<dom.ElementHandle<Element> | null> {
219-
return this.waitForSelector(selector, options);
219+
return this.mainFrame().$wait(selector, options);
220220
}
221221

222222
evaluateHandle: types.EvaluateHandle = async (pageFunction, ...args) => {

test/features/permissions.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,39 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {
2727
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
2828

2929
// Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API)
30-
describe('Permissions', function() {
30+
describe.skip(WEBKIT)('Permissions', function() {
3131
function getPermission(page, name) {
3232
return page.evaluate(name => navigator.permissions.query({name}).then(result => result.state), name);
3333
}
3434

35-
it.skip(WEBKIT)('should be prompt by default', async({page, server, context}) => {
35+
it('should be prompt by default', async({page, server, context}) => {
3636
await page.goto(server.EMPTY_PAGE);
3737
expect(await getPermission(page, 'geolocation')).toBe('prompt');
3838
});
39-
it.skip(WEBKIT)('should deny permission when not listed', async({page, server, context}) => {
39+
it('should deny permission when not listed', async({page, server, context}) => {
4040
await page.goto(server.EMPTY_PAGE);
4141
await context.setPermissions(server.EMPTY_PAGE, []);
4242
expect(await getPermission(page, 'geolocation')).toBe('denied');
4343
});
44-
it.skip(WEBKIT)('should fail when bad permission is given', async({page, server, context}) => {
44+
it('should fail when bad permission is given', async({page, server, context}) => {
4545
await page.goto(server.EMPTY_PAGE);
4646
let error = {};
4747
await context.setPermissions(server.EMPTY_PAGE, ['foo']).catch(e => error = e);
4848
expect(error.message).toBe('Unknown permission: foo');
4949
});
50-
it.skip(WEBKIT)('should grant permission when listed', async({page, server, context}) => {
50+
it('should grant permission when listed', async({page, server, context}) => {
5151
await page.goto(server.EMPTY_PAGE);
5252
await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);
5353
expect(await getPermission(page, 'geolocation')).toBe('granted');
5454
});
55-
it.skip(WEBKIT)('should reset permissions', async({page, server, context}) => {
55+
it('should reset permissions', async({page, server, context}) => {
5656
await page.goto(server.EMPTY_PAGE);
5757
await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);
5858
expect(await getPermission(page, 'geolocation')).toBe('granted');
5959
await context.clearPermissions();
6060
expect(await getPermission(page, 'geolocation')).toBe('prompt');
6161
});
62-
it.skip(WEBKIT)('should trigger permission onchange', async({page, server, context}) => {
62+
it('should trigger permission onchange', async({page, server, context}) => {
6363
await page.goto(server.EMPTY_PAGE);
6464
await page.evaluate(() => {
6565
window['events'] = [];
@@ -78,7 +78,7 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {
7878
await context.clearPermissions();
7979
expect(await page.evaluate(() => window['events'])).toEqual(['prompt', 'denied', 'granted', 'prompt']);
8080
});
81-
it.skip(WEBKIT)('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {
81+
it('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {
8282
await page.goto(server.EMPTY_PAGE);
8383
const otherContext = await newContext();
8484
const otherPage = await otherContext.newPage();

test/launcher.spec.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
4545
await playwright.launch(options).catch(e => waitError = e);
4646
expect(waitError.message).toContain('Failed to launch');
4747
});
48+
});
49+
50+
describe('Playwright.launchPersistent', function() {
4851
it('should have default URL when launching browser', async function() {
4952
const userDataDir = await makeUserDataDir();
5053
const browserContext = await playwright.launchPersistent(userDataDir, defaultBrowserOptions);
@@ -68,12 +71,20 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
6871
await browserContext.close();
6972
await removeUserDataDir(userDataDir);
7073
});
74+
});
75+
76+
describe('Playwright.launchServer', function() {
7177
it('should return child_process instance', async () => {
72-
const userDataDir = await makeUserDataDir();
73-
const browserServer = await playwright.launchServer(userDataDir, defaultBrowserOptions);
78+
const browserServer = await playwright.launchServer(defaultBrowserOptions);
7479
expect(browserServer.process().pid).toBeGreaterThan(0);
7580
await browserServer.close();
76-
await removeUserDataDir(userDataDir);
81+
});
82+
it('should fire close event', async () => {
83+
const browserServer = await playwright.launchServer(defaultBrowserOptions);
84+
await Promise.all([
85+
utils.waitEvent(browserServer, 'close'),
86+
browserServer.close(),
87+
]);
7788
});
7889
});
7990

test/test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,22 @@ beforeEach(async({server, httpsServer}) => {
8080
const products = ['WebKit', 'Firefox', 'Chromium'];
8181
let product;
8282
let events;
83+
let missingCoverage;
8384
if (process.env.BROWSER === 'firefox') {
8485
product = 'Firefox';
8586
events = {
8687
...require('../lib/events').Events,
8788
...require('../lib/chromium/events').Events,
8889
};
90+
missingCoverage = ['browserContext.setGeolocation', 'elementHandle.scrollIntoViewIfNeeded', 'page.setOfflineMode'];
8991
} else if (process.env.BROWSER === 'webkit') {
9092
product = 'WebKit';
9193
events = require('../lib/events').Events;
94+
missingCoverage = ['browserContext.clearPermissions'];
9295
} else {
9396
product = 'Chromium';
9497
events = require('../lib/events').Events;
98+
missingCoverage = [];
9599
}
96100

97101
describe(product, () => {
@@ -108,7 +112,7 @@ describe(product, () => {
108112
return;
109113
filteredApi[name] = api[name];
110114
});
111-
utils.recordAPICoverage(testRunner, filteredApi, events);
115+
utils.recordAPICoverage(testRunner, filteredApi, events, missingCoverage);
112116
}
113117
});
114118

test/utils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,24 @@ const utils = module.exports = {
7979
return promisified;
8080
},
8181

82-
recordAPICoverage: function(testRunner, api, events) {
82+
recordAPICoverage: function(testRunner, api, events, ignoredMethodsArray = []) {
8383
const coverage = new Map();
84+
const ignoredMethods = new Set(ignoredMethodsArray);
8485
for (const [className, classType] of Object.entries(api))
8586
traceAPICoverage(coverage, events, className, classType);
8687
const focus = testRunner.hasFocusedTestsOrSuites();
8788
(focus ? testRunner.fdescribe : testRunner.describe)(COVERAGE_TESTSUITE_NAME, () => {
8889
(focus ? testRunner.fit : testRunner.it)('should call all API methods', () => {
8990
const missingMethods = [];
91+
const extraIgnoredMethods = [];
9092
for (const method of coverage.keys()) {
91-
if (!coverage.get(method))
93+
if (!coverage.get(method) && !ignoredMethods.has(method))
9294
missingMethods.push(method);
95+
else if (coverage.get(method) && ignoredMethods.has(method))
96+
extraIgnoredMethods.push(method);
9397
}
98+
if (extraIgnoredMethods.length)
99+
throw new Error('Certain API Methods are called and should not be ignored: ' + extraIgnoredMethods.join(', '));
94100
if (missingMethods.length)
95101
throw new Error('Certain API Methods are not called: ' + missingMethods.join(', '));
96102
});

0 commit comments

Comments
 (0)