-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
New test setup #640
Changes from 10 commits
d03e7cb
1e745d0
3a54b1d
a876c08
30093ca
d7d7e5f
06cb294
f0ad0d0
14527a7
72f7a2e
b86bc1b
ae2587c
aa35a8d
ee15d3f
e96000b
c327e44
c7e3c3e
5b3c8e6
4f0760a
67b9133
1fad929
284e255
43677cd
790d5ca
b382917
7efe717
b3dafb5
594f26d
0c12c6d
874df60
160be44
b40388c
de9b539
6fc3d5e
b8ffc95
7ed86f6
8b94ac9
14421c6
b5a8db6
3e38906
814ef71
3a5c248
6dc9805
8a4d5e5
189d3ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'", | ||
"prepublish": "gulp release", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
"precommit": "npm run lint" | ||
|
@@ -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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,15 @@ export default class Server { | |
if (this.hotReloader) { | ||
await this.hotReloader.stop() | ||
} | ||
|
||
if (this.http) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 () { | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
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' }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default () => { | ||
throw new Error('This is an expected error') | ||
} |
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> | ||
) |
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()) | ||
} |
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() | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.