Skip to content

Commit 24f6d19

Browse files
authored
test: move remaining tests to jest (#3009)
1 parent 9790cf2 commit 24f6d19

15 files changed

+231
-240
lines changed

test/chromium/chromium.spec.js renamed to test/chromium/chromium.jest.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = require('../utils').testOptions(browserType);
17+
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = testOptions;
1818

19-
describe('Service Worker', function() {
20-
it('should create a worker from a service worker', async({browser, page, server, context}) => {
19+
describe.skip(!CHROMIUM)('Service Worker', function() {
20+
it('should create a worker from a service worker', async({page, server, context}) => {
2121
const [worker] = await Promise.all([
2222
context.waitForEvent('serviceworker'),
2323
page.goto(server.PREFIX + '/serviceworkers/empty/sw.html')
2424
]);
2525
expect(await worker.evaluate(() => self.toString())).toBe('[object ServiceWorkerGlobalScope]');
2626
});
27-
it('serviceWorkers() should return current workers', async({browser, page, server, context}) => {
27+
it('serviceWorkers() should return current workers', async({page, server, context}) => {
2828
const [worker1] = await Promise.all([
2929
context.waitForEvent('serviceworker'),
3030
page.goto(server.PREFIX + '/serviceworkers/empty/sw.html')
@@ -41,7 +41,7 @@ describe('Service Worker', function() {
4141
expect(workers).toContain(worker1);
4242
expect(workers).toContain(worker2);
4343
});
44-
it('should not create a worker from a shared worker', async({browser, page, server, context}) => {
44+
it('should not create a worker from a shared worker', async({page, server, context}) => {
4545
await page.goto(server.EMPTY_PAGE);
4646
let serviceWorkerCreated;
4747
context.once('serviceworker', () => serviceWorkerCreated = true);
@@ -65,7 +65,7 @@ describe('Service Worker', function() {
6565
});
6666
});
6767

68-
describe('Chromium-Specific Page Tests', function() {
68+
describe.skip(!CHROMIUM)('Chromium-Specific Page Tests', function() {
6969
it('Page.route should work with intervention headers', async({server, page}) => {
7070
server.setRoute('/intervention', (req, res) => res.end(`
7171
<script>

test/chromium/launcher.spec.js renamed to test/chromium/launcher.jest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
const path = require('path');
1818
const utils = require('../utils');
1919
const {makeUserDataDir, removeUserDataDir} = utils;
20-
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS} = utils.testOptions(browserType);
20+
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS} = testOptions;
2121

22-
describe('launcher', function() {
22+
describe.skip(!CHROMIUM)('launcher', function() {
2323
it('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => {
2424
const options = Object.assign({}, defaultBrowserOptions);
2525
options.args = ['--remote-debugging-pipe'].concat(options.args || []);
@@ -49,7 +49,7 @@ describe('launcher', function() {
4949
});
5050
});
5151

52-
describe('extensions', () => {
52+
describe.skip(!CHROMIUM)('extensions', () => {
5353
it('should return background pages', async({browserType, defaultBrowserOptions}) => {
5454
const userDataDir = await makeUserDataDir();
5555
const extensionPath = path.join(__dirname, '..', 'assets', 'simple-extension');
@@ -73,7 +73,7 @@ describe('extensions', () => {
7373
});
7474
});
7575

76-
describe('BrowserContext', function() {
76+
describe.skip(!CHROMIUM)('BrowserContext', function() {
7777
it('should not create pages automatically', async ({browserType, defaultBrowserOptions}) => {
7878
const browser = await browserType.launch(defaultBrowserOptions);
7979
const browserSession = await browser.newBrowserCDPSession();

test/chromium/oopif.spec.js renamed to test/chromium/oopif.jest.js

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,47 @@
1414
* limitations under the License.
1515
*/
1616

17-
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = require('../utils').testOptions(browserType);
17+
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = testOptions;
1818

19-
describe('OOPIF', function() {
20-
beforeAll(async function(state) {
21-
state.browser = await state.browserType.launch(Object.assign({}, state.defaultBrowserOptions, {
22-
args: (state.defaultBrowserOptions.args || []).concat(['--site-per-process']),
23-
}));
19+
registerFixture('sppBrowser', async ({browserType, defaultBrowserOptions}, test) => {
20+
const browser = await browserType.launch({
21+
...defaultBrowserOptions,
22+
args: (defaultBrowserOptions.args || []).concat(['--site-per-process'])
2423
});
25-
beforeEach(async function(state) {
26-
state.context = await state.browser.newContext();
27-
state.page = await state.context.newPage();
28-
});
29-
afterEach(async function(state) {
30-
await state.context.close();
31-
state.page = null;
32-
state.context = null;
33-
});
34-
afterAll(async function(state) {
35-
await state.browser.close();
36-
state.browser = null;
37-
});
38-
it('should report oopif frames', async function({browser, page, server, context}) {
24+
try {
25+
await test(browser);
26+
} finally {
27+
await browser.close();
28+
}
29+
});
30+
31+
registerFixture('sppContext', async ({sppBrowser}, test) => {
32+
const context = await sppBrowser.newContext();
33+
try {
34+
await test(context);
35+
} finally {
36+
await context.close();
37+
}
38+
});
39+
40+
registerFixture('sppPage', async ({sppContext}, test) => {
41+
const page = await sppContext.newPage();
42+
await test(page);
43+
});
44+
45+
46+
describe.skip(!CHROMIUM)('OOPIF', function() {
47+
it('should report oopif frames', async function({sppBrowser, sppPage, server}) {
48+
const browser = sppBrowser;
49+
const page = sppPage;
3950
await page.goto(server.PREFIX + '/dynamic-oopif.html');
4051
expect(await countOOPIFs(browser)).toBe(1);
4152
expect(page.frames().length).toBe(2);
4253
expect(await page.frames()[1].evaluate(() => '' + location.href)).toBe(server.CROSS_PROCESS_PREFIX + '/grid.html');
4354
});
44-
it('should handle oopif detach', async function({browser, page, server, context}) {
55+
it('should handle oopif detach', async function({sppBrowser, sppPage, server}) {
56+
const browser = sppBrowser;
57+
const page = sppPage;
4558
await page.goto(server.PREFIX + '/dynamic-oopif.html');
4659
expect(await countOOPIFs(browser)).toBe(1);
4760
expect(page.frames().length).toBe(2);
@@ -53,7 +66,9 @@ describe('OOPIF', function() {
5366
]);
5467
expect(detachedFrame).toBe(frame);
5568
});
56-
it('should handle remote -> local -> remote transitions', async function({browser, page, server, context}) {
69+
it('should handle remote -> local -> remote transitions', async function({sppBrowser, sppPage, server}) {
70+
const browser = sppBrowser;
71+
const page = sppPage;
5772
await page.goto(server.PREFIX + '/dynamic-oopif.html');
5873
expect(page.frames().length).toBe(2);
5974
expect(await countOOPIFs(browser)).toBe(1);
@@ -71,7 +86,9 @@ describe('OOPIF', function() {
7186
expect(await page.frames()[1].evaluate(() => '' + location.href)).toBe(server.CROSS_PROCESS_PREFIX + '/grid.html');
7287
expect(await countOOPIFs(browser)).toBe(1);
7388
});
74-
it.fail(CHROMIUM)('should get the proper viewport', async({browser, page, server}) => {
89+
it.fail(true)('should get the proper viewport', async({sppBrowser, sppPage, server}) => {
90+
const browser = sppBrowser;
91+
const page = sppPage;
7592
expect(page.viewportSize()).toEqual({width: 1280, height: 720});
7693
await page.goto(server.PREFIX + '/dynamic-oopif.html');
7794
expect(page.frames().length).toBe(2);
@@ -89,7 +106,9 @@ describe('OOPIF', function() {
89106
expect(await oopif.evaluate(() => matchMedia('(device-height: 456px)').matches)).toBe(true);
90107
expect(await oopif.evaluate(() => 'ontouchstart' in window)).toBe(false);
91108
});
92-
it('should expose function', async({browser, page, server}) => {
109+
it('should expose function', async({sppBrowser, sppPage, server}) => {
110+
const browser = sppBrowser;
111+
const page = sppPage;
93112
await page.goto(server.PREFIX + '/dynamic-oopif.html');
94113
expect(page.frames().length).toBe(2);
95114
expect(await countOOPIFs(browser)).toBe(1);
@@ -100,7 +119,9 @@ describe('OOPIF', function() {
100119
});
101120
expect(result).toBe(36);
102121
});
103-
it('should emulate media', async({browser, page, server}) => {
122+
it('should emulate media', async({sppBrowser, sppPage, server}) => {
123+
const browser = sppBrowser;
124+
const page = sppPage;
104125
await page.goto(server.PREFIX + '/dynamic-oopif.html');
105126
expect(page.frames().length).toBe(2);
106127
expect(await countOOPIFs(browser)).toBe(1);
@@ -109,7 +130,10 @@ describe('OOPIF', function() {
109130
await page.emulateMedia({ colorScheme: 'dark' });
110131
expect(await oopif.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches)).toBe(true);
111132
});
112-
it('should emulate offline', async({browser, page, context, server}) => {
133+
it('should emulate offline', async({sppBrowser, sppPage, sppContext, server}) => {
134+
const browser = sppBrowser;
135+
const context = sppContext;
136+
const page = sppPage;
113137
await page.goto(server.PREFIX + '/dynamic-oopif.html');
114138
expect(page.frames().length).toBe(2);
115139
expect(await countOOPIFs(browser)).toBe(1);
@@ -118,7 +142,8 @@ describe('OOPIF', function() {
118142
await context.setOffline(true);
119143
expect(await oopif.evaluate(() => navigator.onLine)).toBe(false);
120144
});
121-
it('should support context options', async({browser, server}) => {
145+
it('should support context options', async({sppBrowser, server, playwright}) => {
146+
const browser = sppBrowser;
122147
const iPhone = playwright.devices['iPhone 6']
123148
const context = await browser.newContext({ ...iPhone, timezoneId: 'America/Jamaica', locale: 'fr-CH', userAgent: 'UA' });
124149
const page = await context.newPage();
@@ -139,7 +164,9 @@ describe('OOPIF', function() {
139164

140165
await context.close();
141166
});
142-
it('should respect route', async({browser, page, server}) => {
167+
it('should respect route', async({sppBrowser, sppPage, server}) => {
168+
const browser = sppBrowser;
169+
const page = sppPage;
143170
let intercepted = false;
144171
await page.route('**/digits/0.png', route => {
145172
intercepted = true;
@@ -150,19 +177,25 @@ describe('OOPIF', function() {
150177
expect(await countOOPIFs(browser)).toBe(1);
151178
expect(intercepted).toBe(true);
152179
});
153-
it('should take screenshot', async({browser, page, server, golden}) => {
180+
it('should take screenshot', async({sppBrowser, sppPage, server}) => {
181+
const browser = sppBrowser;
182+
const page = sppPage;
154183
await page.setViewportSize({width: 500, height: 500});
155184
await page.goto(server.PREFIX + '/dynamic-oopif.html');
156185
expect(page.frames().length).toBe(2);
157186
expect(await countOOPIFs(browser)).toBe(1);
158-
expect(await page.screenshot()).toBeGolden(golden('screenshot-oopif.png'));
187+
expect(await page.screenshot()).toBeGolden('screenshot-oopif.png');
159188
});
160-
it('should load oopif iframes with subresources and request interception', async function({browser, page, server, context}) {
189+
it('should load oopif iframes with subresources and request interception', async function({sppBrowser, sppPage, server, context}) {
190+
const browser = sppBrowser;
191+
const page = sppPage;
161192
await page.route('**/*', route => route.continue());
162193
await page.goto(server.PREFIX + '/dynamic-oopif.html');
163194
expect(await countOOPIFs(browser)).toBe(1);
164195
});
165-
it('should report main requests', async function({browser, page, server, context}) {
196+
it('should report main requests', async function({sppBrowser, sppPage, server}) {
197+
const browser = sppBrowser;
198+
const page = sppPage;
166199
const requestFrames = [];
167200
page.on('request', r => requestFrames.push(r.frame()));
168201
const finishedFrames = [];
@@ -199,7 +232,10 @@ describe('OOPIF', function() {
199232
expect(requestFrames[2]).toBe(grandChild);
200233
expect(finishedFrames[2]).toBe(grandChild);
201234
});
202-
it('should support exposeFunction', async function({browser, page, server, context}) {
235+
it('should support exposeFunction', async function({sppBrowser, sppContext, sppPage, server}) {
236+
const browser = sppBrowser;
237+
const context = sppContext;
238+
const page = sppPage;
203239
await context.exposeFunction('dec', a => a - 1);
204240
await page.exposeFunction('inc', a => a + 1);
205241
await page.goto(server.PREFIX + '/dynamic-oopif.html');
@@ -210,7 +246,10 @@ describe('OOPIF', function() {
210246
expect(await page.frames()[0].evaluate(() => dec(3))).toBe(2);
211247
expect(await page.frames()[1].evaluate(() => dec(4))).toBe(3);
212248
});
213-
it('should support addInitScript', async function({browser, page, server, context}) {
249+
it('should support addInitScript', async function({sppBrowser, sppContext, sppPage, server}) {
250+
const browser = sppBrowser;
251+
const context = sppContext;
252+
const page = sppPage;
214253
await context.addInitScript(() => window.bar = 17);
215254
await page.addInitScript(() => window.foo = 42);
216255
await page.goto(server.PREFIX + '/dynamic-oopif.html');
@@ -222,7 +261,9 @@ describe('OOPIF', function() {
222261
expect(await page.frames()[1].evaluate(() => window.bar)).toBe(17);
223262
});
224263
// @see https://github.com/microsoft/playwright/issues/1240
225-
it('should click a button when it overlays oopif', async function({browser, page, server, context}) {
264+
it('should click a button when it overlays oopif', async function({sppBrowser, sppPage, server}) {
265+
const browser = sppBrowser;
266+
const page = sppPage;
226267
await page.goto(server.PREFIX + '/button-overlay-oopif.html');
227268
expect(await countOOPIFs(browser)).toBe(1);
228269
await page.click('button');

test/chromium/session.spec.js renamed to test/chromium/session.jest.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
const {FFOX, CHROMIUM, WEBKIT, CHANNEL, USES_HOOKS} = require('../utils').testOptions(browserType);
17+
const {FFOX, CHROMIUM, WEBKIT, CHANNEL, USES_HOOKS} = testOptions;
1818

19-
describe('ChromiumBrowserContext.createSession', function() {
20-
it('should work', async function({page, browser, server}) {
19+
describe.skip(!CHROMIUM)('ChromiumBrowserContext.createSession', function() {
20+
it('should work', async function({page}) {
2121
const client = await page.context().newCDPSession(page);
2222

2323
await Promise.all([
@@ -27,15 +27,15 @@ describe('ChromiumBrowserContext.createSession', function() {
2727
const foo = await page.evaluate(() => window.foo);
2828
expect(foo).toBe('bar');
2929
});
30-
it('should send events', async function({page, browser, server}) {
30+
it('should send events', async function({page, server}) {
3131
const client = await page.context().newCDPSession(page);
3232
await client.send('Network.enable');
3333
const events = [];
3434
client.on('Network.requestWillBeSent', event => events.push(event));
3535
await page.goto(server.EMPTY_PAGE);
3636
expect(events.length).toBe(1);
3737
});
38-
it('should enable and disable domains independently', async function({page, browser, server}) {
38+
it('should enable and disable domains independently', async function({page}) {
3939
const client = await page.context().newCDPSession(page);
4040
await client.send('Runtime.enable');
4141
await client.send('Debugger.enable');
@@ -52,7 +52,7 @@ describe('ChromiumBrowserContext.createSession', function() {
5252
page.evaluate('//# sourceURL=foo.js')
5353
]);
5454
});
55-
it('should be able to detach session', async function({page, browser, server}) {
55+
it('should be able to detach session', async function({page}) {
5656
const client = await page.context().newCDPSession(page);
5757
await client.send('Runtime.enable');
5858
const evalResponse = await client.send('Runtime.evaluate', {expression: '1 + 2', returnByValue: true});
@@ -66,7 +66,7 @@ describe('ChromiumBrowserContext.createSession', function() {
6666
}
6767
expect(error.message).toContain(CHANNEL ? 'Target browser or context has been closed' : 'Session closed.');
6868
});
69-
it('should throw nice errors', async function({page, browser}) {
69+
it('should throw nice errors', async function({page}) {
7070
const client = await page.context().newCDPSession(page);
7171
const error = await theSourceOfTheProblems().catch(error => error);
7272
expect(error.stack).toContain('theSourceOfTheProblems');
@@ -76,27 +76,27 @@ describe('ChromiumBrowserContext.createSession', function() {
7676
await client.send('ThisCommand.DoesNotExist');
7777
}
7878
});
79-
it('should not break page.close()', async function({browser, server}) {
79+
it('should not break page.close()', async function({browser}) {
8080
const context = await browser.newContext();
8181
const page = await context.newPage();
8282
const session = await page.context().newCDPSession(page);
8383
await session.detach();
8484
await page.close();
8585
await context.close();
8686
});
87-
it('should detach when page closes', async function({browser, server}) {
87+
it('should detach when page closes', async function({browser}) {
8888
const context = await browser.newContext();
8989
const page = await context.newPage();
9090
const session = await context.newCDPSession(page);
9191
await page.close();
9292
let error;
9393
await session.detach().catch(e => error = e);
94-
expect(error).toBeTruthy('Calling detach on a closed page\'s session should throw');
94+
expect(error).toBeTruthy();
9595
await context.close();
9696
});
9797
});
98-
describe('ChromiumBrowser.newBrowserCDPSession', function() {
99-
it('should work', async function({page, browser, server}) {
98+
describe.skip(!CHROMIUM)('ChromiumBrowser.newBrowserCDPSession', function() {
99+
it('should work', async function({browser}) {
100100
const session = await browser.newBrowserCDPSession();
101101

102102
const version = await session.send('Browser.getVersion');

0 commit comments

Comments
 (0)