Skip to content

Commit 1c0504a

Browse files
authored
test: respect fixtures in describe, match image snapshots (#2989)
1 parent fe95ee0 commit 1c0504a

21 files changed

+56
-43
lines changed

src/rpc/client/browserContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ export class BrowserContext extends ChannelOwner<BrowserContextChannel, BrowserC
204204
}
205205

206206
async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {
207-
const timeout = this._timeoutSettings.timeout(optionsOrPredicate instanceof Function ? {} : optionsOrPredicate);
208-
const predicate = optionsOrPredicate instanceof Function ? optionsOrPredicate : optionsOrPredicate.predicate;
207+
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
208+
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
209209
const waiter = new Waiter();
210210
waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout while waiting for event "${event}"`));
211211
if (event !== Events.BrowserContext.Close)

src/rpc/client/electron.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export class ElectronApplication extends ChannelOwner<ElectronApplicationChannel
9393
}
9494

9595
async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {
96-
const timeout = this._timeoutSettings.timeout(optionsOrPredicate instanceof Function ? {} : optionsOrPredicate);
97-
const predicate = optionsOrPredicate instanceof Function ? optionsOrPredicate : optionsOrPredicate.predicate;
96+
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
97+
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
9898
const waiter = new Waiter();
9999
waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout while waiting for event "${event}"`));
100100
if (event !== ElectronEvents.ElectronApplication.Close)

src/rpc/client/page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
332332
}
333333

334334
async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {
335-
const timeout = this._timeoutSettings.timeout(optionsOrPredicate instanceof Function ? {} : optionsOrPredicate);
336-
const predicate = optionsOrPredicate instanceof Function ? optionsOrPredicate : optionsOrPredicate.predicate;
335+
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
336+
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
337337
const waiter = new Waiter();
338338
waiter.rejectOnTimeout(timeout, new TimeoutError(`Timeout while waiting for event "${event}"`));
339339
if (event !== Events.Page.Crash)

src/rpc/client/playwright.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import { BrowserType } from './browserType';
2020
import { ChannelOwner } from './channelOwner';
2121
import { Selectors } from './selectors';
2222
import { Electron } from './electron';
23+
import { TimeoutError } from '../../errors';
2324

2425
export class Playwright extends ChannelOwner<PlaywrightChannel, PlaywrightInitializer> {
25-
chromium: BrowserType;
26-
firefox: BrowserType;
27-
webkit: BrowserType;
28-
devices: types.Devices;
29-
selectors: Selectors;
26+
readonly chromium: BrowserType;
27+
readonly firefox: BrowserType;
28+
readonly webkit: BrowserType;
29+
readonly devices: types.Devices;
30+
readonly selectors: Selectors;
31+
readonly errors: { TimeoutError: typeof TimeoutError };
3032

3133
constructor(parent: ChannelOwner, type: string, guid: string, initializer: PlaywrightInitializer) {
3234
super(parent, type, guid, initializer);
@@ -39,5 +41,6 @@ export class Playwright extends ChannelOwner<PlaywrightChannel, PlaywrightInitia
3941
for (const { name, descriptor } of initializer.deviceDescriptors)
4042
this.devices[name] = descriptor;
4143
this.selectors = Selectors.from(initializer.selectors);
44+
this.errors = { TimeoutError };
4245
}
4346
}

test/click.jest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ describe('Page.click', function() {
746746
await page.click('button');
747747
expect(await page.evaluate(() => window.result)).toBe(1);
748748
});
749-
it.skip(USES_HOOKS).fail(true)('should retarget when element is recycled during hit testing', async ({page, server}) => {
749+
it.fail(true)('should retarget when element is recycled during hit testing', async ({page, server}) => {
750750
await page.goto(server.PREFIX + '/react.html');
751751
await page.evaluate(() => {
752752
renderComponent(e('div', {}, [e(MyButton, { name: 'button1' }), e(MyButton, { name: 'button2' })] ));
@@ -760,7 +760,7 @@ describe('Page.click', function() {
760760
expect(await page.evaluate(() => window.button1)).toBe(true);
761761
expect(await page.evaluate(() => window.button2)).toBe(undefined);
762762
});
763-
it.skip(USES_HOOKS).fail(true)('should report that selector does not match anymore', async ({page, server}) => {
763+
it.fail(true)('should report that selector does not match anymore', async ({page, server}) => {
764764
await page.goto(server.PREFIX + '/react.html');
765765
await page.evaluate(() => {
766766
renderComponent(e('div', {}, [e(MyButton, { name: 'button1' }), e(MyButton, { name: 'button2' })] ));
@@ -778,7 +778,7 @@ describe('Page.click', function() {
778778
expect(error.message).toContain('page.dblclick: Timeout 3000ms exceeded.');
779779
expect(error.message).toContain('element does not match the selector anymore');
780780
});
781-
it.skip(USES_HOOKS).fail(true)('should retarget when element is recycled before enabled check', async ({page, server}) => {
781+
it.fail(true)('should retarget when element is recycled before enabled check', async ({page, server}) => {
782782
await page.goto(server.PREFIX + '/react.html');
783783
await page.evaluate(() => {
784784
renderComponent(e('div', {}, [e(MyButton, { name: 'button1' }), e(MyButton, { name: 'button2', disabled: true })] ));
@@ -792,7 +792,7 @@ describe('Page.click', function() {
792792
expect(await page.evaluate(() => window.button1)).toBe(true);
793793
expect(await page.evaluate(() => window.button2)).toBe(undefined);
794794
});
795-
it.skip(USES_HOOKS).fail(true)('should not retarget the handle when element is recycled', async ({page, server}) => {
795+
it.fail(true)('should not retarget the handle when element is recycled', async ({page, server}) => {
796796
await page.goto(server.PREFIX + '/react.html');
797797
await page.evaluate(() => {
798798
renderComponent(e('div', {}, [e(MyButton, { name: 'button1' }), e(MyButton, { name: 'button2', disabled: true })] ));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

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

2020
describe('Page.Events.Dialog', function() {
2121
it('should fire', async({page, server}) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
const utils = require('./utils');
18-
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS} = utils.testOptions(browserType);
18+
const {FFOX, CHROMIUM, WEBKIT, WIN, USES_HOOKS} = testOptions;
1919

2020
describe('Page.dispatchEvent(click)', function() {
2121
it('should dispatch click event', async({page, server}) => {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
const fs = require('fs');
1818
const path = require('path');
19-
const {FFOX, CHROMIUM, WEBKIT, MAC, WIN} = require('./utils').testOptions(browserType);
19+
const {FFOX, CHROMIUM, WEBKIT, HEADLESS} = testOptions;
2020

2121
describe('Download', function() {
22-
beforeEach(async(state) => {
23-
state.server.setRoute('/download', (req, res) => {
22+
beforeEach(async ({server}) => {
23+
server.setRoute('/download', (req, res) => {
2424
res.setHeader('Content-Type', 'application/octet-stream');
2525
res.setHeader('Content-Disposition', 'attachment');
2626
res.end(`Hello world`);
2727
});
28-
state.server.setRoute('/downloadWithFilename', (req, res) => {
28+
server.setRoute('/downloadWithFilename', (req, res) => {
2929
res.setHeader('Content-Type', 'application/octet-stream');
3030
res.setHeader('Content-Disposition', 'attachment; filename=file.txt');
3131
res.end(`Hello world`);
@@ -103,7 +103,7 @@ describe('Download', function() {
103103
expect(fs.readFileSync(path).toString()).toBe('Hello world');
104104
await page.close();
105105
})
106-
it.skip(FFOX).fail(WEBKIT)('should report alt-click downloads', async({browser, server}) => {
106+
it.fail(FFOX || WEBKIT)('should report alt-click downloads', async({browser, server}) => {
107107
// Firefox does not download on alt-click by default.
108108
// Our WebKit embedder does not download on alt-click, although Safari does.
109109
server.setRoute('/download', (req, res) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

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

2121
describe('ElementHandle.boundingBox', function() {
2222
it.fail(FFOX && !HEADLESS)('should work', async({page, server}) => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
const utils = require('./utils');
19-
const {FFOX, CHROMIUM, WEBKIT, LINUX} = utils.testOptions(browserType);
19+
const {FFOX, HEADLESS} = testOptions;
2020

2121
describe('BrowserContext({viewport})', function() {
2222
it('should get the proper default viewport size', async({page, server}) => {
@@ -567,7 +567,7 @@ describe('focus', function() {
567567
]);
568568
expect(active).toEqual(['INPUT', 'TEXTAREA']);
569569
});
570-
it.skip(FFOX && !HEADLESS)('should not affect screenshots', async({page, server, golden}) => {
570+
it.skip(FFOX && !HEADLESS)('should not affect screenshots', async({page, server}) => {
571571
// Firefox headful produces a different image.
572572
const page2 = await page.context().newPage();
573573
await Promise.all([
@@ -584,8 +584,8 @@ describe('focus', function() {
584584
page.screenshot(),
585585
page2.screenshot(),
586586
]);
587-
expect(screenshots[0]).toBeGolden(golden('screenshot-sanity.png'));
588-
expect(screenshots[1]).toBeGolden(golden('grid-cell-0.png'));
587+
expect(screenshots[0]).toMatchImageSnapshot('screenshot-sanity');
588+
expect(screenshots[1]).toMatchImageSnapshot('grid-cell-0');
589589
});
590590
it('should change focused iframe', async({page, server}) => {
591591
await page.goto(server.EMPTY_PAGE);

0 commit comments

Comments
 (0)