diff --git a/.cirrus.yml b/.cirrus.yml index 6f47edb63a0c6..aaaad69fe7bed 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -24,12 +24,12 @@ task: task: matrix: - - name: Firefox (node8 + linux) + - name: Firefox Juggler (node8 + linux) container: dockerfile: .ci/node8/Dockerfile.linux xvfb_start_background_script: Xvfb :99 -ac -screen 0 1024x768x24 install_script: npm install --unsafe-perm && cd experimental/puppeteer-firefox && npm install --unsafe-perm - test_script: npm run funit + test_script: npm run fjunit task: osx_instance: diff --git a/.travis.yml b/.travis.yml index 84f45ce3c4f3b..bee3a08c00737 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ script: - 'if [ "$NODE8" = "true" ]; then npm run lint; fi' - 'if [ "$NODE8" = "true" ]; then npm run coverage; fi' - 'if [ "$FIREFOX" = "true" ]; then cd experimental/puppeteer-firefox && npm i && cd ../..; fi' - - 'if [ "$FIREFOX" = "true" ]; then npm run funit; fi' + - 'if [ "$FIREFOX" = "true" ]; then npm run fjunit; fi' - 'if [ "$NODE8" = "true" ]; then npm run test-doclint; fi' - 'if [ "$NODE8" = "true" ]; then npm run test-types; fi' - 'if [ "$NODE8" = "true" ]; then npm run bundle; fi' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 777bfb04b1f80..43454687c2788 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -199,10 +199,10 @@ npm run unit -- --break-on-failure HEADLESS=false npm run unit ``` -- To run tests with custom Chromium executable: +- To run tests with custom browser executable: ```bash -CHROME= npm run unit +BINARY= npm run unit ``` - To run tests in slow-mode: @@ -211,6 +211,13 @@ CHROME= npm run unit HEADLESS=false SLOW_MO=500 npm run unit ``` +- To run tests with additional Launcher options: + +```bash +EXTRA_LAUNCH_OPTIONS='{"args": ["--user-data-dir=some/path"], "handleSIGINT": true}' npm run unit +``` + + - To debug a test, "focus" a test first and then run: ```bash diff --git a/experimental/puppeteer-firefox/.cirrus.yml b/experimental/puppeteer-firefox/.cirrus.yml index 9a6c162a757e3..dc0ec87a9c42c 100644 --- a/experimental/puppeteer-firefox/.cirrus.yml +++ b/experimental/puppeteer-firefox/.cirrus.yml @@ -7,7 +7,7 @@ task: dockerfile: .ci/node8/Dockerfile.linux xvfb_start_background_script: Xvfb :99 -ac -screen 0 1024x768x24 install_script: npm install - test_script: npm run funit + test_script: npm run fjunit task: name: node8 (macOS) @@ -19,7 +19,7 @@ task: - brew install node@8 - brew link --force node@8 install_script: npm install - test_script: npm run funit + test_script: npm run fjunit # task: # allow_failures: true @@ -28,4 +28,4 @@ task: # os_version: 2016 # name: node8 (windows) # install_script: npm install --unsafe-perm -# test_script: npm run funit +# test_script: npm run fjunit diff --git a/package.json b/package.json index c62c1157dec02..c17ec5739f489 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ }, "scripts": { "unit": "node test/test.js", - "funit": "BROWSER=firefox node test/test.js", + "fjunit": "PUPPETEER_PRODUCT=juggler node test/test.js", + "funit": "PUPPETEER_PRODUCT=firefox node test/test.js", "debug-unit": "node --inspect-brk test/test.js", "test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js", "test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-types && node utils/testrunner/test/test.js", diff --git a/test/fixtures.spec.js b/test/fixtures.spec.js index a2447f64a4059..574b4f3b54f6f 100644 --- a/test/fixtures.spec.js +++ b/test/fixtures.spec.js @@ -16,7 +16,7 @@ const path = require('path'); -module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, puppeteerPath, CHROME}) { +module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, puppeteer, puppeteerPath, JUGGLER}) { const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner; const {it, fit, xit, it_fails_ffox} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; @@ -38,16 +38,16 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p const options = Object.assign({}, defaultBrowserOptions, {dumpio: true}); const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), puppeteerPath, JSON.stringify(options)]); - if (CHROME) - res.stderr.on('data', data => dumpioData += data.toString('utf8')); - else + if (JUGGLER) res.stdout.on('data', data => dumpioData += data.toString('utf8')); + else + res.stderr.on('data', data => dumpioData += data.toString('utf8')); await new Promise(resolve => res.on('close', resolve)); - if (CHROME) - expect(dumpioData).toContain('DevTools listening on ws://'); - else + if (JUGGLER) expect(dumpioData).toContain('Juggler listening on ws://'); + else + expect(dumpioData).toContain('DevTools listening on ws://'); }); it('should close the browser when the node process closes', async({ server }) => { const {spawn, execSync} = require('child_process'); diff --git a/test/puppeteer.spec.js b/test/puppeteer.spec.js index ffbbf75b67dfa..e9542183b9b32 100644 --- a/test/puppeteer.spec.js +++ b/test/puppeteer.spec.js @@ -28,31 +28,40 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => { const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; const CHROME = product === 'Chromium'; - const FFOX = product === 'Firefox'; + const FFOX = (product === 'Firefox' || product === 'Juggler'); + const JUGGLER = product === 'Juggler'; const puppeteer = require(puppeteerPath); const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true'; const slowMo = parseInt((process.env.SLOW_MO || '0').trim(), 10); + let extraLaunchOptions = {}; + try { + extraLaunchOptions = JSON.parse(process.env.EXTRA_LAUNCH_OPTIONS || '{}'); + } catch (e) { + console.warn(`${YELLOW_COLOR}Error parsing EXTRA_LAUNCH_OPTIONS: ${e.message}. Skipping.${RESET_COLOR}`); + } - const defaultBrowserOptions = { + const defaultBrowserOptions = Object.assign({ handleSIGINT: false, - executablePath: CHROME ? process.env.CHROME : process.env.FFOX, + executablePath: process.env.BINARY, slowMo, headless, dumpio: !!process.env.DUMPIO, - }; + }, extraLaunchOptions); + if (defaultBrowserOptions.executablePath) { console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}${RESET_COLOR}`); } else { - // Make sure the `npm install` was run after the chromium roll. - if (!fs.existsSync(puppeteer.executablePath())) - throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`); + const path = puppeteer.executablePath(); + if (!fs.existsSync(path)) + throw new Error(`Browser is not downloaded at ${path}. Run 'npm install' and try to re-run tests`); } - const GOLDEN_DIR = path.join(__dirname, 'golden-' + product.toLowerCase()); - const OUTPUT_DIR = path.join(__dirname, 'output-' + product.toLowerCase()); + const suffix = JUGGLER ? 'firefox' : product.toLowerCase(); + const GOLDEN_DIR = path.join(__dirname, 'golden-' + suffix); + const OUTPUT_DIR = path.join(__dirname, 'output-' + suffix); if (fs.existsSync(OUTPUT_DIR)) rm(OUTPUT_DIR); const {expect} = new Matchers({ @@ -64,6 +73,7 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => { product, FFOX, CHROME, + JUGGLER, puppeteer, expect, defaultBrowserOptions, @@ -72,7 +82,7 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => { }; beforeAll(async() => { - if (FFOX && defaultBrowserOptions.executablePath) + if (JUGGLER && defaultBrowserOptions.executablePath) await require('../experimental/puppeteer-firefox/misc/install-preferences')(defaultBrowserOptions.executablePath); }); diff --git a/test/test.js b/test/test.js index 55c5cc657bf0d..d13509e976db9 100644 --- a/test/test.js +++ b/test/test.js @@ -76,28 +76,44 @@ const CHROMIUM_NO_COVERAGE = new Set([ 'page.emulateMedia', // Legacy alias for `page.emulateMediaType`. ]); -if (process.env.BROWSER === 'firefox') { - testRunner.addTestDSL('it_fails_ffox', 'skip'); - testRunner.addSuiteDSL('describe_fails_ffox', 'skip'); - describe('Firefox', () => { - require('./puppeteer.spec.js').addTests({ - product: 'Firefox', - puppeteerPath: path.resolve(__dirname, '../experimental/puppeteer-firefox/'), - testRunner, +switch (process.env.PUPPETEER_PRODUCT) { + case 'firefox': + testRunner.addTestDSL('it_fails_ffox', 'skip'); + testRunner.addSuiteDSL('describe_fails_ffox', 'skip'); + describe('Firefox', () => { + require('./puppeteer.spec.js').addTests({ + product: 'Firefox', + puppeteerPath: utils.projectRoot(), + testRunner, + }); + if (process.env.COVERAGE) + utils.recordAPICoverage(testRunner, require('../lib/api'), require('../lib/Events').Events, CHROMIUM_NO_COVERAGE); }); - }); -} else { - testRunner.addTestDSL('it_fails_ffox', 'run'); - testRunner.addSuiteDSL('describe_fails_ffox', 'run'); - describe('Chromium', () => { - require('./puppeteer.spec.js').addTests({ - product: 'Chromium', - puppeteerPath: utils.projectRoot(), - testRunner, + break; + case 'juggler': + testRunner.addTestDSL('it_fails_ffox', 'skip'); + testRunner.addSuiteDSL('describe_fails_ffox', 'skip'); + describe('Firefox (Juggler)', () => { + require('./puppeteer.spec.js').addTests({ + product: 'Juggler', + puppeteerPath: path.resolve(__dirname, '../experimental/puppeteer-firefox/'), + testRunner, + }); + }); + break; + case 'chrome': + default: + testRunner.addTestDSL('it_fails_ffox', 'run'); + testRunner.addSuiteDSL('describe_fails_ffox', 'run'); + describe('Chromium', () => { + require('./puppeteer.spec.js').addTests({ + product: 'Chromium', + puppeteerPath: utils.projectRoot(), + testRunner, + }); + if (process.env.COVERAGE) + utils.recordAPICoverage(testRunner, require('../lib/api'), require('../lib/Events').Events, CHROMIUM_NO_COVERAGE); }); - if (process.env.COVERAGE) - utils.recordAPICoverage(testRunner, require('../lib/api'), require('../lib/Events').Events, CHROMIUM_NO_COVERAGE); - }); } if (process.env.CI && testRunner.hasFocusedTestsOrSuites()) { diff --git a/utils/protocol-types-generator/index.js b/utils/protocol-types-generator/index.js index c1d46ce5f6f56..95029572b3afd 100644 --- a/utils/protocol-types-generator/index.js +++ b/utils/protocol-types-generator/index.js @@ -3,7 +3,7 @@ const path = require('path'); const puppeteer = require('../..'); module.exports = puppeteer.launch({ pipe: false, - executablePath: process.env.CHROME, + executablePath: process.env.BINARY, }).then(async browser => { const origin = browser.wsEndpoint().match(/ws:\/\/([0-9A-Za-z:\.]*)\//)[1]; const page = await browser.newPage();