From e6b8c77d94a54dd1e8de561cc33f571c26e7b05d Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Thu, 22 Oct 2020 14:37:28 +0100 Subject: [PATCH 1/2] chore: fix travis config (#6537) --- .travis.yml | 32 ++++++++++++++-------------- mocha-config/puppeteer-unit-tests.js | 4 ++-- package.json | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fb8b9b29126c..7a7e80dab914f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ services: xvfb jobs: include: - - os: "osx" + - os: 'osx' name: 'Unit tests: macOS/Chromium' - node_js: "10.19.0" + node_js: '10.19.0' osx_image: xcode11.4 env: - CHROMIUM=true @@ -14,11 +14,11 @@ jobs: script: - ls .local-chromium .local-firefox - npm run tsc - - travis_retry npm run unit + - npm run unit - - os: "windows" + - os: 'windows' name: 'Unit tests: Windows/Chromium' - node_js: "10.19.0" + node_js: '10.19.0' env: - CHROMIUM=true before_install: @@ -29,7 +29,7 @@ jobs: - travis_retry npm run unit # Runs unit tests on Linux + Chromium - - node_js: "10.19.0" + - node_js: '10.19.0' name: 'Unit tests [with coverage]: Linux/Chromium' env: - CHROMIUM=true @@ -39,35 +39,35 @@ jobs: - travis_retry npm run unit-with-coverage - npm run assert-unit-coverage - - node_js: "12.16.3" + - node_js: '12.16.3' name: 'Unit tests [Node 12]: Linux/Chromium' env: - CHROMIUM=true before_install: - PUPPETEER_PRODUCT=firefox npm install script: - - travis_retry npm run unit + - npm run unit - - node_js: "14.2.0" + - node_js: '14.2.0' name: 'Unit tests [Node 14]: Linux/Chromium' env: - CHROMIUM=true before_install: - PUPPETEER_PRODUCT=firefox npm install script: - - travis_retry npm run unit + - npm run unit - - node_js: "12.16.3" + - node_js: '12.16.3' name: 'Browser tests: Linux/Chromium' addons: chrome: stable env: - CHROMIUM=true script: - - travis_retry npm run test-browser + - npm run test-browser # This bot runs all the extra checks that aren't the main Puppeteer unit tests - - node_js: "10.19.0" + - node_js: '10.19.0' name: 'Extra tests: Linux/Chromium' env: - CHROMIUM=true @@ -79,7 +79,7 @@ jobs: # This bot runs separately as it changes package.json to test puppeteer-core # and we don't want that leaking into other bots and causing issues. - - node_js: "10.19.0" + - node_js: '10.19.0' name: 'Test bundling and install of packages' env: - CHROMIUM=true @@ -87,14 +87,14 @@ jobs: - npm run test-install # Runs unit tests on Linux + Firefox - - node_js: "10.19.0" + - node_js: '10.19.0' name: 'Unit tests: Linux/Firefox' env: - FIREFOX=true before_install: - PUPPETEER_PRODUCT=firefox npm install script: - - travis_retry npm run funit + - npm run funit notifications: email: false diff --git a/mocha-config/puppeteer-unit-tests.js b/mocha-config/puppeteer-unit-tests.js index 8ab70f6be958c..cb1bb7cae9c89 100644 --- a/mocha-config/puppeteer-unit-tests.js +++ b/mocha-config/puppeteer-unit-tests.js @@ -21,8 +21,8 @@ module.exports = { require: ['./test/mocha-ts-require', './test/mocha-utils.ts'], spec: 'test/*.spec.ts', extension: ['js', 'ts'], - parallel: process.env.CI && !process.env.COVERAGE, - // retry twice more, so we run each test up to 3 times if needed. retries: process.env.CI ? 2 : 0, + parallel: !!process.env.PARALLEL, timeout: 25 * 1000, + reporter: process.env.CI ? 'spec' : 'dot', }; diff --git a/package.json b/package.json index a0e8204581d49..718b1910ea436 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "jpeg-js": "^0.3.7", "mime": "^2.0.3", "minimist": "^1.2.0", - "mocha": "^8.1.3", + "mocha": "^8.2.0", "ncp": "^2.0.0", "pixelmatch": "^4.0.2", "pngjs": "^5.0.0", From 5e5fed1deb6ba963a9e905711de5827696ccb248 Mon Sep 17 00:00:00 2001 From: Johan Bay Date: Fri, 23 Oct 2020 12:45:47 +0200 Subject: [PATCH 2/2] fix: ignore spurious bindingCalled events (#6538) --- src/common/DOMWorld.ts | 10 +++++++++- src/common/Page.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index 825d0c533e83f..de09fe368a646 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -537,7 +537,15 @@ export class DOMWorld { private async _onBindingCalled( event: Protocol.Runtime.BindingCalledEvent ): Promise { - const { type, name, seq, args } = JSON.parse(event.payload); + let payload: { type: string; name: string; seq: number; args: unknown[] }; + try { + payload = JSON.parse(event.payload); + } catch { + // The binding was either called by something in the page or it was + // called before our wrapper was initialized. + return; + } + const { type, name, seq, args } = payload; if (type !== 'internal' || !this._ctxBindings.has(name)) return; if (!this._hasContext()) return; const context = await this.executionContext(); diff --git a/src/common/Page.ts b/src/common/Page.ts index 215e48576df4f..e805e2e7aa749 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -1132,7 +1132,15 @@ export class Page extends EventEmitter { private async _onBindingCalled( event: Protocol.Runtime.BindingCalledEvent ): Promise { - const { type, name, seq, args } = JSON.parse(event.payload); + let payload: { type: string; name: string; seq: number; args: unknown[] }; + try { + payload = JSON.parse(event.payload); + } catch { + // The binding was either called by something in the page or it was + // called before our wrapper was initialized. + return; + } + const { type, name, seq, args } = payload; if (type !== 'exposedFun' || !this._pageBindings.has(name)) return; let expression = null; try {