From c1475c5b0e828e69cfddb0983ddd374e97c7da73 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 11:30:26 +0530 Subject: [PATCH 1/8] Run tests serially. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6e092d5c6f7..69b185cb3385 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "testonly": "cross-env NODE_PATH=test/lib jest \\.test.js", "posttestonly": "fly posttest", "pretest": "npm run lint && cross-env NODE_ENV=test-build npm run release", - "test": "npm run testonly -- --coverage --forceExit", + "test": "npm run testonly -- --coverage --forceExit --runInBand", "coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls", "lint": "standard 'bin/*' 'client/**/*.js' 'examples/**/*.js' 'lib/**/*.js' 'pages/**/*.js' 'server/**/*.js' 'test/**/*.js'", "prepublish": "npm run release", From a4fb74cd30f712503fd51802f0f346e98ca4db60 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 11:46:52 +0530 Subject: [PATCH 2/8] Make test result verbose. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 69b185cb3385..526bffa926f6 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "testonly": "cross-env NODE_PATH=test/lib jest \\.test.js", "posttestonly": "fly posttest", "pretest": "npm run lint && cross-env NODE_ENV=test-build npm run release", - "test": "npm run testonly -- --coverage --forceExit --runInBand", + "test": "npm run testonly -- --coverage --forceExit --runInBand --verbose", "coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls", "lint": "standard 'bin/*' 'client/**/*.js' 'examples/**/*.js' 'lib/**/*.js' 'pages/**/*.js' 'server/**/*.js' 'test/**/*.js'", "prepublish": "npm run release", From f5ba0b077e1d3f2f942e5b278bd25fc4544e6dbb Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 11:53:31 +0530 Subject: [PATCH 3/8] Don't wait until closing the browser. --- .../basic/test/client-navigation.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/integration/basic/test/client-navigation.js b/test/integration/basic/test/client-navigation.js index 6198af95a55b..b7bd740bbe5c 100644 --- a/test/integration/basic/test/client-navigation.js +++ b/test/integration/basic/test/client-navigation.js @@ -13,7 +13,7 @@ export default (context, render) => { .elementByCss('p').text() expect(text).toBe('This is the about page.') - await browser.close() + browser.close() }) it('should navigate via the client side', async () => { @@ -28,7 +28,7 @@ export default (context, render) => { .elementByCss('#counter').text() expect(counterText).toBe('Counter: 1') - await browser.close() + browser.close() }) }) @@ -41,7 +41,7 @@ export default (context, render) => { .elementByCss('p').text() expect(text).toBe('This is the home.') - await browser.close() + browser.close() }) }) @@ -56,7 +56,7 @@ export default (context, render) => { const expectedErrorMessage = '"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.' expect(preText.includes(expectedErrorMessage)).toBeTruthy() - await browser.close() + browser.close() }) }) @@ -69,7 +69,7 @@ export default (context, render) => { .elementByCss('p').text() expect(text).toBe('2') - await browser.close() + browser.close() }) it('should remove querystring', async () => { @@ -80,7 +80,7 @@ export default (context, render) => { .elementByCss('p').text() expect(text).toBe('0') - await browser.close() + browser.close() }) }) @@ -95,7 +95,7 @@ export default (context, render) => { .elementByCss('p').text() expect(countAfterClicked).toBe('COUNT: 1') - await browser.close() + browser.close() }) it('should always replace the state', async () => { @@ -116,7 +116,7 @@ export default (context, render) => { .back() .waitForElementByCss('.nav-home') - await browser.close() + browser.close() }) }) @@ -131,7 +131,7 @@ export default (context, render) => { expect(counter).toBe('COUNT: 0') - await browser.close() + browser.close() }) }) @@ -145,7 +145,7 @@ export default (context, render) => { expect(counter).toBe('COUNT: 0') - await browser.close() + browser.close() }) }) @@ -160,7 +160,7 @@ export default (context, render) => { expect(counter).toBe('COUNT: 1') - await browser.close() + browser.close() }) }) @@ -175,7 +175,7 @@ export default (context, render) => { expect(counter).toBe('COUNT: 0') - await browser.close() + browser.close() }) }) }) @@ -193,7 +193,7 @@ export default (context, render) => { .elementByCss('#get-initial-props-run-count').text() expect(getInitialPropsRunCount).toBe('getInitialProps run count: 1') - await browser.close() + browser.close() }) it('should handle the back button and should not run getInitialProps', async () => { @@ -213,7 +213,7 @@ export default (context, render) => { .elementByCss('#get-initial-props-run-count').text() expect(getInitialPropsRunCount).toBe('getInitialProps run count: 1') - await browser.close() + browser.close() }) it('should run getInitialProps always when rending the page to the screen', async () => { @@ -233,7 +233,7 @@ export default (context, render) => { .elementByCss('#get-initial-props-run-count').text() expect(getInitialPropsRunCount).toBe('getInitialProps run count: 2') - await browser.close() + browser.close() }) }) }) From a6f172c6d4a1e371e9fb629c669ceb9211698fe0 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 11:57:12 +0530 Subject: [PATCH 4/8] Add some debug logs. --- test/lib/next-webdriver.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lib/next-webdriver.js b/test/lib/next-webdriver.js index a7967f8adc5b..0c6b654e88da 100644 --- a/test/lib/next-webdriver.js +++ b/test/lib/next-webdriver.js @@ -1,10 +1,12 @@ import wd from 'wd' export default async function (appPort, pathname) { + console.warn(`> Start loading browser with path: ${pathname}`) const url = `http://localhost:${appPort}${pathname}` const browser = wd.promiseChainRemote('http://localhost:9515/') await browser.init({browserName: 'chrome'}).get(url) + console.warn(`> Complete loading browser with path: ${pathname}`) return browser } From 5c5ecf1ebaff1a3918f123115205f1b3c466e6b2 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 12:03:42 +0530 Subject: [PATCH 5/8] Add bailing support. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 526bffa926f6..5317ee6cf0fb 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "testonly": "cross-env NODE_PATH=test/lib jest \\.test.js", "posttestonly": "fly posttest", "pretest": "npm run lint && cross-env NODE_ENV=test-build npm run release", - "test": "npm run testonly -- --coverage --forceExit --runInBand --verbose", + "test": "npm run testonly -- --coverage --forceExit --runInBand --verbose --bail", "coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls", "lint": "standard 'bin/*' 'client/**/*.js' 'examples/**/*.js' 'lib/**/*.js' 'pages/**/*.js' 'server/**/*.js' 'test/**/*.js'", "prepublish": "npm run release", From 6f2e3d4c2204eba74272c236c848eb1cf1aa2a71 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 12:25:59 +0530 Subject: [PATCH 6/8] Get the browser with a timeout. --- test/lib/next-webdriver.js | 46 ++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/test/lib/next-webdriver.js b/test/lib/next-webdriver.js index 0c6b654e88da..8bf47a70283d 100644 --- a/test/lib/next-webdriver.js +++ b/test/lib/next-webdriver.js @@ -1,12 +1,50 @@ import wd from 'wd' export default async function (appPort, pathname) { - console.warn(`> Start loading browser with path: ${pathname}`) const url = `http://localhost:${appPort}${pathname}` + console.warn(`> Start loading browser with url: ${url}`) + for (let lc = 0; lc < 5; lc++) { + try { + const browser = await getBrowser(url, 5000) + console.warn(`> Complete loading browser with url: ${url}`) + return browser + } catch (ex) { + console.warn(`> Error when loading browser with url: ${url}`) + if (ex.message === 'TIMEOUT') continue + throw ex + } + } + + console.warn(`> Tried 5 times. Cannot load the browser for url: ${url}`) + throw new Error(`Couldn't start the browser for url: ${url}`) +} + +function getBrowser (url, timeout) { const browser = wd.promiseChainRemote('http://localhost:9515/') - await browser.init({browserName: 'chrome'}).get(url) - console.warn(`> Complete loading browser with path: ${pathname}`) - return browser + return new Promise((resolve, reject) => { + let timeouted = false + const timeoutHandler = setTimeout(() => { + timeouted = true + const error = new Error('TIMEOUT') + reject(error) + }, timeout) + + browser.init({browserName: 'chrome'}).get(url, (err) => { + if (timeouted) { + browser.close() + return + } + + clearTimeout(timeoutHandler) + + if (err) { + reject(err) + return + } + + resolve(browser) + }) + }) } From 3979678f66ef9f861385414eb9bd0d88aff030ea Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 12:33:14 +0530 Subject: [PATCH 7/8] Add some comments. --- test/lib/next-webdriver.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/lib/next-webdriver.js b/test/lib/next-webdriver.js index 8bf47a70283d..9ccbd6ad3dc4 100644 --- a/test/lib/next-webdriver.js +++ b/test/lib/next-webdriver.js @@ -2,12 +2,14 @@ import wd from 'wd' export default async function (appPort, pathname) { const url = `http://localhost:${appPort}${pathname}` - console.warn(`> Start loading browser with url: ${url}`) + console.log(`> Start loading browser with url: ${url}`) + // Sometimes browser won't initialize due to some random issues. + // So, we need to timeout the initialization and retry again. for (let lc = 0; lc < 5; lc++) { try { const browser = await getBrowser(url, 5000) - console.warn(`> Complete loading browser with url: ${url}`) + console.log(`> Complete loading browser with url: ${url}`) return browser } catch (ex) { console.warn(`> Error when loading browser with url: ${url}`) @@ -16,7 +18,7 @@ export default async function (appPort, pathname) { } } - console.warn(`> Tried 5 times. Cannot load the browser for url: ${url}`) + console.error(`> Tried 5 times. Cannot load the browser for url: ${url}`) throw new Error(`Couldn't start the browser for url: ${url}`) } From a088e01ce503298c0f8c9d0b1db4945bd1f0b415 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 8 Mar 2017 13:14:32 +0530 Subject: [PATCH 8/8] Remove istanbul babel tranformation. Jest already do it and it's breaking our coveralls hit. --- .babelrc | 5 ----- package.json | 4 ++-- yarn.lock | 18 +++++++++--------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.babelrc b/.babelrc index 262731f3281e..6f19a631c2c7 100644 --- a/.babelrc +++ b/.babelrc @@ -9,11 +9,6 @@ "transform-runtime" ], "env": { - "test-build": { - "plugins": [ - "istanbul" - ] - }, "test": { "presets": [ "es2015", diff --git a/package.json b/package.json index 5317ee6cf0fb..3293d7dbf522 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "pretestonly": "fly pretest", "testonly": "cross-env NODE_PATH=test/lib jest \\.test.js", "posttestonly": "fly posttest", - "pretest": "npm run lint && cross-env NODE_ENV=test-build npm run release", + "pretest": "npm run lint", "test": "npm run testonly -- --coverage --forceExit --runInBand --verbose --bail", "coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls", "lint": "standard 'bin/*' 'client/**/*.js' 'examples/**/*.js' 'lib/**/*.js' 'pages/**/*.js' 'server/**/*.js' 'test/**/*.js'", @@ -90,7 +90,7 @@ "devDependencies": { "babel-eslint": "7.1.1", "babel-jest": "18.0.0", - "babel-plugin-istanbul": "3.0.0", + "babel-plugin-istanbul": "4.0.0", "babel-plugin-transform-remove-strict-mode": "0.0.2", "babel-preset-es2015": "6.22.0", "benchmark": "2.1.3", diff --git a/yarn.lock b/yarn.lock index 98f3a81a1970..be7bca83c031 100644 --- a/yarn.lock +++ b/yarn.lock @@ -467,7 +467,15 @@ babel-plugin-check-es2015-constants@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-istanbul@3.0.0, babel-plugin-istanbul@^3.0.0: +babel-plugin-istanbul@4.0.0, babel-plugin-istanbul@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-4.0.0.tgz#36bde8fbef4837e5ff0366531a2beabd7b1ffa10" + dependencies: + find-up "^2.1.0" + istanbul-lib-instrument "^1.4.2" + test-exclude "^4.0.0" + +babel-plugin-istanbul@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-3.0.0.tgz#da7324520ae0b8a44b6a078e72e883374a9fab76" dependencies: @@ -476,14 +484,6 @@ babel-plugin-istanbul@3.0.0, babel-plugin-istanbul@^3.0.0: object-assign "^4.1.0" test-exclude "^3.2.2" -babel-plugin-istanbul@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-4.0.0.tgz#36bde8fbef4837e5ff0366531a2beabd7b1ffa10" - dependencies: - find-up "^2.1.0" - istanbul-lib-instrument "^1.4.2" - test-exclude "^4.0.0" - babel-plugin-jest-hoist@^18.0.0: version "18.0.0" resolved "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-18.0.0.tgz#4150e70ecab560e6e7344adc849498072d34e12a"