Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test setup #640

Merged
merged 45 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d03e7cb
Use jest-cli instead of gulp plugin.
arunoda Jan 3, 2017
1e745d0
Use jest-cli instead of gulp plugin.
arunoda Jan 3, 2017
3a54b1d
Move fixtures into the examples dir.
arunoda Jan 3, 2017
a876c08
Move test code of example app to the basic example.
arunoda Jan 3, 2017
30093ca
Add isolated tests for server/resolve
arunoda Jan 3, 2017
d7d7e5f
Allow tests to use cheerio.
arunoda Jan 3, 2017
06cb294
Use portfinder to get a unique port.
arunoda Jan 3, 2017
f0ad0d0
Move back integration tests into the example dir.
arunoda Jan 3, 2017
14527a7
Introduce next-test-utils.
arunoda Jan 3, 2017
72f7a2e
Remove gulp-jest
arunoda Jan 3, 2017
b86bc1b
Add coveralls support.
arunoda Jan 4, 2017
ae2587c
Use transpiled version of code in dist.
arunoda Jan 4, 2017
aa35a8d
Add support for source maps.
arunoda Jan 4, 2017
ee15d3f
Use code from dist always.
arunoda Jan 4, 2017
e96000b
Use nyc to stop instrument.
arunoda Jan 4, 2017
c327e44
Add integration test suite for production usage.
arunoda Jan 4, 2017
c7e3c3e
Use jest-cli.
arunoda Jan 5, 2017
5b3c8e6
Add support for running e2e tests.
arunoda Jan 5, 2017
4f0760a
Check gzipPath with fs.stat before serving
arunoda Jan 5, 2017
67b9133
Install chromedriver with npm install.
arunoda Jan 5, 2017
1fad929
Install chrome on travis-ci.
arunoda Jan 5, 2017
284e255
Merge branch 'master' into new-test-setup
arunoda Jan 5, 2017
43677cd
Add --forceExit to Jest.
arunoda Jan 5, 2017
790d5ca
Run tests only on Node v6.
arunoda Jan 5, 2017
b382917
Use chromedriver NPM module to install chromedriver.
arunoda Jan 5, 2017
7efe717
Use wd as the webdriver client.
arunoda Jan 5, 2017
b3dafb5
Run chromedriver before tests.
arunoda Jan 5, 2017
594f26d
Run travis for both node 4 and 6
arunoda Jan 5, 2017
0c12c6d
Remove unwanted npm install script.
arunoda Jan 5, 2017
874df60
Move some common text utilities to next-test-utils
arunoda Jan 6, 2017
160be44
Add lint checks and testing in npm prepublish hook.
arunoda Jan 6, 2017
b40388c
Resolve conflicts.
arunoda Jan 6, 2017
de9b539
Use npm on travis-ci.
arunoda Jan 7, 2017
6fc3d5e
Resolve conflicts.
arunoda Jan 9, 2017
b8ffc95
Resolve conflicts.
arunoda Jan 9, 2017
7ed86f6
Make tests work on windows.\n But chromedriver doesn't work.
arunoda Jan 9, 2017
8b94ac9
Clean up dependencies.
arunoda Jan 9, 2017
14421c6
Run chromedriver in background without any tools.
arunoda Jan 9, 2017
b5a8db6
Fix a typo in the code.
arunoda Jan 9, 2017
3e38906
Use ES6 features used in node4 inside the gulpfile.
arunoda Jan 9, 2017
814ef71
Add some comments.
arunoda Jan 9, 2017
3a5c248
Add support for running in windows.
arunoda Jan 9, 2017
6dc9805
Stop chromedriver properly on windows.
arunoda Jan 9, 2017
8a4d5e5
Fix typos.
arunoda Jan 11, 2017
189d3ac
Resolve conflicts.
arunoda Jan 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const sequence = require('run-sequence')
const webpack = require('webpack')
const webpackStream = require('webpack-stream')
const del = require('del')
const jest = require('gulp-jest')

const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'))

Expand Down Expand Up @@ -123,21 +122,6 @@ gulp.task('build-prefetcher', ['compile-lib', 'compile-client'], () => {
.pipe(notify('Built release prefetcher'))
})

gulp.task('test', ['compile'], () => {
return gulp.src('./test')
.pipe(jest.default({
coverage: true,
verbose: true,
config: {
rootDir: './test',
testEnvironment: 'node',
coveragePathIgnorePatterns: [
'test/.*'
]
}
}))
})

gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => {
return gulp.src('dist/bench/*.js', {read: false})
.pipe(benchmark({
Expand Down Expand Up @@ -193,7 +177,6 @@ gulp.task('default', [
'compile',
'build',
'copy',
'test',
'watch'
])

Expand All @@ -202,7 +185,6 @@ gulp.task('release', (cb) => {
'compile',
'build',
'copy',
'test'
], cb)
})

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
},
"scripts": {
"build": "gulp",
"pretest": "npm run lint",
"test": "gulp test",
"html-report": "nyc report --temp-directory=./coverage --reporter=html",
"jest": "jest --coverage",
"coveralls": "nyc report --temp-directory=./coverage --reporter=text-lcov | coveralls",
"pretest": "npm run lint && npm run prepublish",
"test": "NODE_PATH=test/lib jest test/unit/*.test.js test/isolated/*.test.js test/integration/**/test/*.test.js",
"testonly": "NODE_PATH=test/lib jest test/unit/*.test.js test/isolated/*.test.js test/integration/**/test/*.test.js",
"coverage": "npm run test -- --coverage",
"lint": "standard 'bin/*' 'client/**/*.js' 'examples/**/*.js' 'lib/**/*.js' 'pages/**/*.js' 'server/**/*.js' 'test/**/*.js'",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does coveralls works. Do we need this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunoda coveralls needs to be piped the lcov format test output post test:

https://github.com/zeit/next.js/blob/master/.travis.yml#L14

so this logic is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Thanks.
I'll add it back.

"prepublish": "gulp release",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run prepublish is used to run tests. It looks this is not true now ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"precommit": "npm run lint"
Expand Down Expand Up @@ -81,19 +80,21 @@
},
"devDependencies": {
"babel-eslint": "7.1.1",
"babel-jest": "^18.0.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"babel-preset-env": "1.1.4",
"benchmark": "2.1.3",
"cheerio": "^0.22.0",
"coveralls": "2.11.15",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-benchmark": "1.1.1",
"gulp-cached": "1.1.1",
"gulp-jest": "^0.6.0",
"gulp-notify": "2.2.0",
"husky": "0.12.0",
"jest": "^18.0.0",
"nyc": "^10.0.0",
"node-fetch": "^1.6.3",
"portfinder": "^1.0.10",
"run-sequence": "1.2.2",
"standard": "8.6.0",
"webpack-stream": "3.2.0"
Expand Down
9 changes: 9 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export default class Server {
if (this.hotReloader) {
await this.hotReloader.stop()
}

if (this.http) {
Copy link
Contributor Author

@arunoda arunoda Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this because, we need to close the HTTP server after completing each test suite.

await new Promise((resolve, reject) => {
this.http.close((err) => {
if (err) return reject(err)
return resolve()
})
})
}
}

defineRoutes () {
Expand Down
4 changes: 2 additions & 2 deletions server/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function getPaths (id) {

if (i[i.length - 1] === sep) {
return [
i + 'index.json',
i + 'index.js'
i + 'index.js',
i + 'index.json'
]
}

Expand Down
18 changes: 0 additions & 18 deletions test/fixtures/basic/pages/async-props.js

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/basic/pages/error.js

This file was deleted.

122 changes: 0 additions & 122 deletions test/integration.test.js

This file was deleted.

18 changes: 18 additions & 0 deletions test/integration/basic/pages/async-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'

export default class AsyncProps extends React.Component {
static async getInitialProps () {
return await fetchData()
}

render () {
return <p>{this.props.name}</p>
}
}

function fetchData () {
const p = new Promise(resolve => {
setTimeout(() => resolve({ name: 'Diego Milito' }), 10)
})
return p
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import style from 'next/css'

export default () => <div className={styles}>This is red</div>
export default () => <div id='red-box' className={styles}>This is red</div>

const styles = style({ color: 'red' })
3 changes: 3 additions & 0 deletions test/integration/basic/pages/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {
throw new Error('This is an expected error')
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export default class Statefull extends Component {
}

render () {
return <div>
<p>The answer is {this.state.answer}</p>
</div>
return (
<div>
<p id='answer'>The answer is {this.state.answer}</p>
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default () => (
<div>
<p>This is blue</p>
<p id='blue-box'>This is blue</p>
<style jsx>{`p { color: blue }`}</style>
</div>
)
42 changes: 42 additions & 0 deletions test/integration/basic/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* global jasmine, describe, beforeAll, afterAll */

import { next, findPort } from 'next-test-utils'
import fetch from 'node-fetch'
import { join } from 'path'

// test suits
import xPoweredBy from './xpowered-by'
import rendering from './rendering'
import misc from './misc'

const app = next({
dir: join(__dirname, '../'),
dev: true,
quiet: true
})

let appPort
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

describe('Basic Features', () => {
beforeAll(async () => {
await app.prepare()
appPort = await findPort()
await app.start(appPort)
})
afterAll(() => app.close())

rendering(app, 'Rendering via API', renderingViaAPI)
rendering(app, 'Rendering via HTTP', renderingViaHTTP)
xPoweredBy(app)
misc(app)
})

function renderingViaAPI (pathname, query = {}) {
return app.renderToHTML({}, {}, pathname, query)
}

function renderingViaHTTP (pathname, query = {}) {
const url = `http://localhost:${appPort}${pathname}`
return fetch(url).then((res) => res.text())
}
16 changes: 16 additions & 0 deletions test/integration/basic/test/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* global describe, test, expect */

export default function (app) {
describe('Misc', () => {
test('finishes response', async () => {
const res = {
finished: false,
end () {
this.finished = true
}
}
const html = await app.renderToHTML({}, res, '/finish-response', {})
expect(html).toBeFalsy()
})
})
}
Loading