Skip to content

Commit

Permalink
chore: enable unit tests for Firefox on Windows (#6895)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Scheffler <janscheffler@chromium.org>
  • Loading branch information
whimboo and jschfflr committed Mar 5, 2021
1 parent abb3280 commit 669f04a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ jobs:
CHROMIUM: true
run: |
npm run unit
- name: Run unit tests on Firefox
env:
FIREFOX: true
MOZ_WEBRENDER: 0
run: |
npm run funit
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"unit-debug": "npm run tsc-cjs && mocha --inspect-brk --config mocha-config/puppeteer-unit-tests.js",
"unit-with-coverage": "cross-env COVERAGE=1 npm run unit",
"assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
"funit": "PUPPETEER_PRODUCT=firefox npm run unit",
"funit": "cross-env PUPPETEER_PRODUCT=firefox npm run unit",
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-browser",
"prepare": "node typescript-if-required.js",
"prepublishOnly": "npm run build",
Expand Down
6 changes: 5 additions & 1 deletion src/node/BrowserRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { LaunchOptions } from './LaunchOptions.js';
import { Connection } from '../common/Connection.js';
import { NodeWebSocketTransport as WebSocketTransport } from '../node/NodeWebSocketTransport.js';
import { PipeTransport } from './PipeTransport.js';
import { Product } from '../common/Product.js';
import * as readline from 'readline';
import { TimeoutError } from '../common/Errors.js';
import { promisify } from 'util';
Expand All @@ -36,6 +37,7 @@ Please check your open processes and ensure that the browser processes that Pupp
If you think this is a bug, please report it on the Puppeteer issue tracker.`;

export class BrowserRunner {
private _product: Product;
private _executablePath: string;
private _processArguments: string[];
private _tempDirectory?: string;
Expand All @@ -48,10 +50,12 @@ export class BrowserRunner {
private _processClosing: Promise<void>;

constructor(
product: Product,
executablePath: string,
processArguments: string[],
tempDirectory?: string
) {
this._product = product;
this._executablePath = executablePath;
this._processArguments = processArguments;
this._tempDirectory = tempDirectory;
Expand Down Expand Up @@ -128,7 +132,7 @@ export class BrowserRunner {

close(): Promise<void> {
if (this._closed) return Promise.resolve();
if (this._tempDirectory) {
if (this._tempDirectory && this._product !== 'firefox') {
this.kill();
} else if (this.connection) {
// Attempt to close the browser gracefully
Expand Down
2 changes: 2 additions & 0 deletions src/node/Launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ChromeLauncher implements ProductLauncher {

const usePipe = chromeArguments.includes('--remote-debugging-pipe');
const runner = new BrowserRunner(
this.product,
chromeExecutable,
chromeArguments,
temporaryUserDataDir
Expand Down Expand Up @@ -281,6 +282,7 @@ class FirefoxLauncher implements ProductLauncher {
}

const runner = new BrowserRunner(
this.product,
firefoxExecutable,
firefoxArguments,
temporaryUserDataDir
Expand Down
9 changes: 2 additions & 7 deletions test/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
getTestState,
itFailsFirefox,
itOnlyRegularInstall,
itFailsWindows,
} from './mocha-utils'; // eslint-disable-line import/extensions
import utils from './utils.js';
import expect from 'expect';
Expand Down Expand Up @@ -339,7 +338,7 @@ describe('Launcher specs', function () {
if (isChrome) expect(puppeteer.product).toBe('chrome');
else if (isFirefox) expect(puppeteer.product).toBe('firefox');
});
it('should work with no default arguments', async () => {
itFailsFirefox('should work with no default arguments', async () => {
const { defaultBrowserOptions, puppeteer } = getTestState();
const options = Object.assign({}, defaultBrowserOptions);
options.ignoreDefaultArgs = true;
Expand Down Expand Up @@ -470,11 +469,7 @@ describe('Launcher specs', function () {
]);
});

/* We think there's a bug in the FF Windows launcher, or some
* combo of that plus it running on CI, but it's hard to track down.
* See comment here: https://github.com/puppeteer/puppeteer/issues/5673#issuecomment-670141377.
*/
itFailsWindows('should be able to launch Firefox', async function () {
it('should be able to launch Firefox', async function () {
this.timeout(FIREFOX_TIMEOUT);
const { puppeteer } = getTestState();
const browser = await puppeteer.launch({ product: 'firefox' });
Expand Down
63 changes: 33 additions & 30 deletions test/screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,39 +203,42 @@ describe('Screenshots', function () {
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden('screenshot-element-padding-border.png');
});
it('should capture full element when larger than viewport', async () => {
const { page } = getTestState();
itFailsFirefox(
'should capture full element when larger than viewport',
async () => {
const { page } = getTestState();

await page.setViewport({ width: 500, height: 500 });
await page.setViewport({ width: 500, height: 500 });

await page.setContent(`
something above
<style>
div.to-screenshot {
border: 1px solid blue;
width: 600px;
height: 600px;
margin-left: 50px;
}
::-webkit-scrollbar{
display: none;
}
</style>
<div class="to-screenshot"></div>
`);
const elementHandle = await page.$('div.to-screenshot');
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden(
'screenshot-element-larger-than-viewport.png'
);
await page.setContent(`
something above
<style>
div.to-screenshot {
border: 1px solid blue;
width: 600px;
height: 600px;
margin-left: 50px;
}
::-webkit-scrollbar{
display: none;
}
</style>
<div class="to-screenshot"></div>
`);
const elementHandle = await page.$('div.to-screenshot');
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden(
'screenshot-element-larger-than-viewport.png'
);

expect(
await page.evaluate(() => ({
w: window.innerWidth,
h: window.innerHeight,
}))
).toEqual({ w: 500, h: 500 });
});
expect(
await page.evaluate(() => ({
w: window.innerWidth,
h: window.innerHeight,
}))
).toEqual({ w: 500, h: 500 });
}
);
it('should scroll element into view', async () => {
const { page } = getTestState();

Expand Down

0 comments on commit 669f04a

Please sign in to comment.