mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
[WIP] Improve test setup (#1372)
* Run tests serially. * Make test result verbose. * Don't wait until closing the browser. * Add some debug logs. * Add bailing support. * Get the browser with a timeout. * Add some comments. * Remove istanbul babel tranformation. Jest already do it and it's breaking our coveralls hit.
This commit is contained in:
parent
634a62441d
commit
f9286f74bf
5
.babelrc
5
.babelrc
|
@ -9,11 +9,6 @@
|
|||
"transform-runtime"
|
||||
],
|
||||
"env": {
|
||||
"test-build": {
|
||||
"plugins": [
|
||||
"istanbul"
|
||||
]
|
||||
},
|
||||
"test": {
|
||||
"presets": [
|
||||
"es2015",
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
"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",
|
||||
"test": "npm run testonly -- --coverage --forceExit",
|
||||
"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'",
|
||||
"prepublish": "npm run release",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -2,9 +2,51 @@ import wd from 'wd'
|
|||
|
||||
export default async function (appPort, pathname) {
|
||||
const url = `http://localhost:${appPort}${pathname}`
|
||||
console.log(`> Start loading browser with url: ${url}`)
|
||||
|
||||
const browser = wd.promiseChainRemote('http://localhost:9515/')
|
||||
await browser.init({browserName: 'chrome'}).get(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.log(`> 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.error(`> 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/')
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
18
yarn.lock
18
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"
|
||||
|
|
Loading…
Reference in a new issue