From 30b7f079b3f2149151ef37614efe67211f4538d2 Mon Sep 17 00:00:00 2001 From: Brendan Baldwin Date: Mon, 10 Sep 2018 16:25:11 -0700 Subject: [PATCH] Revert "Retry browser navigation in WCT if the browser doesn't connect. (#680)" This reverts commit 44f48fb59b3cdd2b8fd74eef0c1368d82bd852db. --- .../runner/browserrunner.ts | 69 +++---------------- .../integration/compilation/golden.json | 10 ++- .../integration/components_dir/golden.json | 12 ++-- .../fail-until-third-load.js | 31 --------- .../connects-on-third-load/golden.json | 13 ---- .../connects-on-third-load/test/index.html | 12 ---- .../connects-on-third-load/wct.conf.json | 16 ----- .../custom-components_dir/golden.json | 12 ++-- .../golden.json | 30 ++++---- .../define-webserver-hook/golden.json | 10 ++- .../fixtures/integration/failing/golden.json | 10 ++- .../fixtures/integration/missing/golden.json | 12 ++-- .../integration/mixed-suites/golden.json | 10 ++- .../multiple-component_dirs/golden.json | 30 ++++---- .../integration/multiple-replace/golden.json | 12 ++-- .../fixtures/integration/nested/golden.json | 10 ++- .../integration/never-loads/block-loading.js | 29 -------- .../integration/never-loads/golden.json | 5 -- .../integration/never-loads/test/index.html | 12 ---- .../integration/never-loads/wct.conf.json | 16 ----- .../fixtures/integration/no-tests/golden.json | 12 ++-- .../integration/query-string/golden.json | 12 ++-- .../test/integration/browser.ts | 46 +++++++------ 23 files changed, 107 insertions(+), 324 deletions(-) delete mode 100644 packages/web-component-tester/test/fixtures/integration/connects-on-third-load/fail-until-third-load.js delete mode 100644 packages/web-component-tester/test/fixtures/integration/connects-on-third-load/golden.json delete mode 100644 packages/web-component-tester/test/fixtures/integration/connects-on-third-load/test/index.html delete mode 100644 packages/web-component-tester/test/fixtures/integration/connects-on-third-load/wct.conf.json delete mode 100644 packages/web-component-tester/test/fixtures/integration/never-loads/block-loading.js delete mode 100644 packages/web-component-tester/test/fixtures/integration/never-loads/golden.json delete mode 100644 packages/web-component-tester/test/fixtures/integration/never-loads/test/index.html delete mode 100644 packages/web-component-tester/test/fixtures/integration/never-loads/wct.conf.json diff --git a/packages/web-component-tester/runner/browserrunner.ts b/packages/web-component-tester/runner/browserrunner.ts index 89a4930ff..73044fe48 100644 --- a/packages/web-component-tester/runner/browserrunner.ts +++ b/packages/web-component-tester/runner/browserrunner.ts @@ -33,17 +33,6 @@ export interface BrowserDef extends wd.Capabilities { variant?: string; } -/** - * Returns a promise that resolves after a given duration to an optional - * result. - * - * @param duration The time, in milliseconds, after which the promise should - * resolve. - * @param result The result to resolve the promise to. - */ -const timeout = (duration: number, result?: any) => - new Promise(resolve => setTimeout(() => resolve(result), duration)); - // Browser abstraction, responsible for spinning up a browser instance via wd.js // and executing runner.html test files passed in options.files export class BrowserRunner { @@ -65,11 +54,6 @@ export class BrowserRunner { private _resolve: () => void; private _reject: (err: any) => void; - private _navigationAttemptCount: number; - private _navigationAttemptTimeout: number; - private _navigationSucceeded: Promise; - private _resolveNavigationSucceeded: Function; - /** * @param emitter The emitter to send updates about test progress to. * @param def A BrowserDef describing and defining the browser to be run. @@ -92,13 +76,6 @@ export class BrowserRunner { this.emitter = emitter; this.url = url; - this._navigationAttemptCount = 3; - this._navigationAttemptTimeout = Math.min(this.timeout / 2, 10000); - this._navigationSucceeded = new Promise((resolve) => { - this._resolveNavigationSucceeded = resolve; - }); - - this.stats = {status: 'initializing'}; this.donePromise = new Promise((resolve, reject) => { @@ -196,53 +173,23 @@ export class BrowserRunner { } else { this.sessionId = sessionId; this.startTest(); + this.extendTimeout(); } } - async startTest() { + startTest() { const paramDelim = (this.url.indexOf('?') === -1 ? '?' : '&'); const extra = `${paramDelim}cli_browser_id=${this.def.id}`; - await this._attemptNavigation( - this.url + extra, - this._navigationAttemptCount, - this._navigationAttemptTimeout); - this.extendTimeout(); - } - - /** - * Asks the connected browser to navigate to the given URL, retrying until - * `this.onEvent` receives any event from the browser. - * - * @param url The URL to navigate to. - * @param attemptCount The number of attempts to make. - * @param timeoutDuration The time to wait before considering an attempt as - * having failed, in milliseconds. - */ - private async _attemptNavigation( - url: string, attemptCount: number, timeoutDuration: number) { - for (let remaining = attemptCount; remaining > 0; remaining--) { - this.browser.get(url, (error) => { - if (error) { - this.done(error.data || error); - } else { - this.extendTimeout(); - } - }); - - const timeoutToken = Symbol('timeoutToken'); - const raceResult = await Promise.race( - [this._navigationSucceeded, timeout(timeoutDuration, timeoutToken)]); - if (raceResult !== timeoutToken) { - return; + this.browser.get(this.url + extra, (error) => { + if (error) { + this.done(error.data || error); + } else { + this.extendTimeout(); } - } - - this.done(new Error(`The browser failed to navigate to "${url}".`)); + }); } onEvent(event: string, data: any) { - this._resolveNavigationSucceeded(); - this.extendTimeout(); if (event === 'browser-start') { // Always assign, to handle re-runs (no browser-init). diff --git a/packages/web-component-tester/test/fixtures/integration/compilation/golden.json b/packages/web-component-tester/test/fixtures/integration/compilation/golden.json index 96d22bcaa..7d3a4f8ed 100644 --- a/packages/web-component-tester/test/fixtures/integration/compilation/golden.json +++ b/packages/web-component-tester/test/fixtures/integration/compilation/golden.json @@ -1,10 +1,8 @@ { - "stats": { - "passing": 1, - "pending": 0, - "failing": 0, - "status": "complete" - }, + "passing": 1, + "pending": 0, + "failing": 0, + "status": "complete", "tests": { "test/": { "ES6 works": { diff --git a/packages/web-component-tester/test/fixtures/integration/components_dir/golden.json b/packages/web-component-tester/test/fixtures/integration/components_dir/golden.json index 0dab2216b..a617ba022 100644 --- a/packages/web-component-tester/test/fixtures/integration/components_dir/golden.json +++ b/packages/web-component-tester/test/fixtures/integration/components_dir/golden.json @@ -1,13 +1,11 @@ { - "stats": { - "passing": 1, - "pending": 0, - "failing": 0, - "status": "complete" - }, + "passing": 1, + "pending": 0, + "failing": 0, + "status": "complete", "tests": { "test/": { "inline passing test": {"state": "passing"} } } -} +} \ No newline at end of file diff --git a/packages/web-component-tester/test/fixtures/integration/connects-on-third-load/fail-until-third-load.js b/packages/web-component-tester/test/fixtures/integration/connects-on-third-load/fail-until-third-load.js deleted file mode 100644 index 288a1e296..000000000 --- a/packages/web-component-tester/test/fixtures/integration/connects-on-third-load/fail-until-third-load.js +++ /dev/null @@ -1,31 +0,0 @@ -{ - // This script should only run in the context of the test runner's top level - // page, which is the page that WCT will attempt to reload if it doesn't - // contact WCT's server. - if (location.pathname === '/components/connects-on-third-load/generated-index.html') { - // Use `localStorage` to track how many times this page has been loaded. - const key = 'loadCount'; - // Note that (1) if a key is not set in `localStorage`, then `getItem` - // returns null and (2) that `Number(null) === 0`. - const previousLoadCount = Number(localStorage.getItem(key)); - if (previousLoadCount < 2) { - localStorage.setItem(key, previousLoadCount + 1); - // Open a comment to prevent all other scripts from loading, including - // the one which connects to WCT. - document.write('