Skip to content

Commit c56fde8

Browse files
author
Benjamin Coe
committedNov 22, 2016
chore: add test coverage
1 parent 462c12b commit c56fde8

11 files changed

+131
-45
lines changed
 

‎.babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": ["es2015", "react"],
3+
"plugins": [
4+
"transform-async-to-generator",
5+
"transform-object-rest-spread",
6+
"transform-class-properties",
7+
"transform-runtime"
8+
],
9+
"env": {
10+
"test": {
11+
"plugins": ["istanbul"]
12+
}
13+
}
14+
}

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ npm-debug.log
1010

1111
# other
1212
.next
13+
14+
# coverage
15+
.nyc_output
16+
coverage

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_js:
66
cache:
77
directories:
88
- node_modules
9+
after_script: npm run coveralls

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<img width="112" alt="screen shot 2016-10-25 at 2 37 27 pm" src="https://cloud.githubusercontent.com/assets/13041/19686250/971bf7f8-9ac0-11e6-975c-188defd82df1.png">
22

33
[![Build Status](https://travis-ci.org/zeit/next.js.svg?branch=master)](https://travis-ci.org/zeit/next.js)
4+
[![Coverage Status](https://coveralls.io/repos/zeit/next.js/badge.svg?branch=master)](https://coveralls.io/r/zeit/next.js?branch=master)
5+
46
[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat)
57

68
Next.js is a minimalistic framework for server-rendered React applications.

‎gulpfile.js

+10-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const gulp = require('gulp')
23
const babel = require('gulp-babel')
34
const cache = require('gulp-cached')
@@ -8,15 +9,7 @@ const sequence = require('run-sequence')
89
const webpack = require('webpack-stream')
910
const del = require('del')
1011

11-
const babelOptions = {
12-
presets: ['es2015', 'react'],
13-
plugins: [
14-
'transform-async-to-generator',
15-
'transform-object-rest-spread',
16-
'transform-class-properties',
17-
'transform-runtime'
18-
]
19-
}
12+
const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'))
2013

2114
gulp.task('compile', [
2215
'compile-bin',
@@ -57,26 +50,13 @@ gulp.task('compile-client', () => {
5750
.pipe(notify('Compiled client files'))
5851
})
5952

60-
gulp.task('compile-test', () => {
61-
return gulp.src('test/*.js')
62-
.pipe(cache('test'))
63-
.pipe(babel(babelOptions))
64-
.pipe(gulp.dest('dist/test'))
65-
.pipe(notify('Compiled test files'))
66-
})
67-
6853
gulp.task('copy', ['copy-pages'])
6954

7055
gulp.task('copy-pages', () => {
7156
return gulp.src('pages/**/*.js')
7257
.pipe(gulp.dest('dist/pages'))
7358
})
7459

75-
gulp.task('copy-test-fixtures', () => {
76-
return gulp.src('test/fixtures/**/*')
77-
.pipe(gulp.dest('dist/test/fixtures'))
78-
})
79-
8060
gulp.task('compile-bench', () => {
8161
return gulp.src('bench/*.js')
8262
.pipe(cache('bench'))
@@ -153,9 +133,13 @@ gulp.task('build-client', ['compile-lib', 'compile-client'], () => {
153133
.pipe(notify('Built release client'))
154134
})
155135

156-
gulp.task('test', ['compile', 'copy', 'compile-test', 'copy-test-fixtures'], () => {
157-
return gulp.src('dist/test/*.js')
158-
.pipe(ava())
136+
gulp.task('test', () => {
137+
process.env.NODE_ENV = 'test'
138+
return gulp.src('test/**/**.test.js')
139+
.pipe(ava({
140+
verbose: true,
141+
nyc: true
142+
}))
159143
})
160144

161145
gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => {
@@ -209,10 +193,6 @@ gulp.task('clean', () => {
209193
return del('dist')
210194
})
211195

212-
gulp.task('clean-test', () => {
213-
return del('dist/test')
214-
})
215-
216196
gulp.task('default', [
217197
'compile',
218198
'build',
@@ -227,7 +207,7 @@ gulp.task('release', (cb) => {
227207
'build',
228208
'copy',
229209
'test'
230-
], 'clean-test', cb)
210+
], cb)
231211
})
232212

233213
// avoid logging to the console

‎lib/document.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import htmlescape from 'htmlescape'
3-
import pkg from '../../package.json'
3+
import readPkgUp from 'read-pkg-up'
4+
5+
const pkg = readPkgUp.sync({normalize: false}).pkg
46

57
export default ({ head, css, html, data, dev, staticMarkup, cdn }) => {
68
return <html>

‎package.json

+38-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,35 @@
1616
},
1717
"scripts": {
1818
"build": "gulp",
19-
"test": "npm run lint && gulp test",
19+
"pretest": "npm run lint",
20+
"test": "gulp test",
2021
"lint": "standard && standard bin/*",
22+
"html-report": "nyc report --reporter=html",
23+
"coveralls": "nyc report --reporter=text-lcov | coveralls",
2124
"prepublish": "gulp release",
2225
"precommit": "npm run lint"
2326
},
24-
"ava": {
25-
"babel": {}
27+
"nyc": {
28+
"require": [
29+
"babel-register"
30+
],
31+
"exclude": [
32+
"gulpfile.js",
33+
"css.js",
34+
"link.js",
35+
"head.js",
36+
"client/**",
37+
"**/pages/**",
38+
"**/coverage/**",
39+
"**/client/**",
40+
"**/test/**",
41+
"**/dist/**",
42+
"**/examples/**",
43+
"**/bench/**"
44+
],
45+
"all": true,
46+
"sourceMap": false,
47+
"instrument": false
2648
},
2749
"standard": {
2850
"parser": "babel-eslint"
@@ -54,11 +76,14 @@
5476
"react": "15.4.0",
5577
"react-dom": "15.4.0",
5678
"react-hot-loader": "3.0.0-beta.6",
79+
"read-pkg-up": "2.0.0",
5780
"send": "0.14.1",
81+
"sockjs-client": "1.1.1",
5882
"strip-ansi": "3.0.1",
5983
"url": "0.11.0",
6084
"webpack": "1.13.3",
6185
"webpack-dev-server": "1.16.2",
86+
<<<<<<< HEAD
6287
"sockjs-client": "1.1.1",
6388
"write-file-webpack-plugin": "3.4.2"
6489
},
@@ -67,13 +92,23 @@
6792
"babel-eslint": "7.1.1",
6893
"babel-plugin-transform-remove-strict-mode": "0.0.2",
6994
"benchmark": "2.1.2",
95+
"write-file-webpack-plugin": "3.3.0"
96+
},
97+
"devDependencies": {
98+
"ava": "0.16.0",
99+
"babel-eslint": "7.0.0",
100+
"babel-plugin-istanbul": "3.0.0",
101+
"babel-plugin-transform-remove-strict-mode": "0.0.2",
102+
"benchmark": "2.1.1",
103+
"coveralls": "2.11.15",
70104
"gulp": "3.9.1",
71105
"gulp-ava": "0.15.0",
72106
"gulp-babel": "6.1.2",
73107
"gulp-benchmark": "1.1.1",
74108
"gulp-cached": "1.1.1",
75109
"gulp-notify": "2.2.0",
76110
"husky": "0.11.9",
111+
"nyc": "9.0.1",
77112
"run-sequence": "1.2.2",
78113
"standard": "8.5.0",
79114
"webpack-stream": "3.2.0"

‎test/fixtures/basic/pages/head.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import React from 'react'
32
import Head from 'next/head'
43

‎test/fixtures/basic/pages/link.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
import Link from 'next/link'
3+
export default () => (
4+
<div>Hello World. <Link href='/about'>About</Link></div>
5+
)

‎test/index.js ‎test/integration.test.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,40 @@ const dir = join(__dirname, 'fixtures', 'basic')
77

88
test.before(() => build(dir))
99

10-
test(async t => {
10+
test('renders a stateless component', async t => {
1111
const html = await render('/stateless')
1212
t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
1313
t.true(html.includes('<h1>My component!</h1>'))
1414
})
1515

16-
test(async t => {
17-
const html = await render('/css')
18-
t.true(html.includes('.css-im3wl1'))
19-
t.true(html.includes('<div class="css-im3wl1">This is red</div>'))
20-
})
21-
22-
test(async t => {
16+
test('renders a stateful component', async t => {
2317
const html = await render('/stateful')
2418
t.true(html.includes('<div><p>The answer is 42</p></div>'))
2519
})
2620

27-
test(async t => {
21+
test('header helper renders header information', async t => {
2822
const html = await (render('/head'))
2923
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
3024
t.true(html.includes('<meta content="my meta" class="next-head"/>'))
3125
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
3226
})
3327

34-
test(async t => {
28+
test('css helper renders styles', async t => {
29+
const html = await render('/css')
30+
t.true(html.includes('.css-im3wl1'))
31+
t.true(html.includes('<div class="css-im3wl1">This is red</div>'))
32+
})
33+
34+
test('renders properties populated asynchronously', async t => {
3535
const html = await render('/async-props')
3636
t.true(html.includes('<p>Diego Milito</p>'))
3737
})
3838

39+
test('renders a link component', async t => {
40+
const html = await render('/link')
41+
t.true(html.includes('<a href="/about">About</a>'))
42+
})
43+
3944
function render (url, ctx) {
4045
return _render(url, ctx, { dir, staticMarkup: true })
4146
}

‎test/lib/shallow-equals.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import test from 'ava'
2+
import shallowEquals from '../../lib/shallow-equals'
3+
4+
test('returns true if all key/value pairs match', t => {
5+
t.true(shallowEquals({
6+
a: 1,
7+
b: 2,
8+
c: 99
9+
}, {
10+
a: 1,
11+
b: 2,
12+
c: 99
13+
}))
14+
})
15+
16+
test('returns false if any key/value pair is different', t => {
17+
t.false(shallowEquals({
18+
a: 1,
19+
b: 2,
20+
c: 99
21+
}, {
22+
a: 1,
23+
b: 2,
24+
c: 99,
25+
d: 33
26+
}))
27+
})
28+
29+
test('returns false if nested objects are contained', t => {
30+
t.false(shallowEquals({
31+
a: 1,
32+
b: 2,
33+
c: {}
34+
}, {
35+
a: 1,
36+
b: 2,
37+
c: {}
38+
}))
39+
})

0 commit comments

Comments
 (0)
Please sign in to comment.