1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

chore: add test coverage

This commit is contained in:
Benjamin Coe 2016-11-15 00:24:20 -08:00
parent 462c12ba06
commit c56fde89c3
No known key found for this signature in database
GPG key ID: 60AB1C1D478E1286
11 changed files with 131 additions and 45 deletions

14
.babelrc Normal file
View file

@ -0,0 +1,14 @@
{
"presets": ["es2015", "react"],
"plugins": [
"transform-async-to-generator",
"transform-object-rest-spread",
"transform-class-properties",
"transform-runtime"
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}

4
.gitignore vendored
View file

@ -10,3 +10,7 @@ npm-debug.log
# other
.next
# coverage
.nyc_output
coverage

View file

@ -6,3 +6,4 @@ node_js:
cache:
directories:
- node_modules
after_script: npm run coveralls

View file

@ -1,6 +1,8 @@
<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">
[![Build Status](https://travis-ci.org/zeit/next.js.svg?branch=master)](https://travis-ci.org/zeit/next.js)
[![Coverage Status](https://coveralls.io/repos/zeit/next.js/badge.svg?branch=master)](https://coveralls.io/r/zeit/next.js?branch=master)
[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat)
Next.js is a minimalistic framework for server-rendered React applications.

View file

@ -1,3 +1,4 @@
const fs = require('fs')
const gulp = require('gulp')
const babel = require('gulp-babel')
const cache = require('gulp-cached')
@ -8,15 +9,7 @@ const sequence = require('run-sequence')
const webpack = require('webpack-stream')
const del = require('del')
const babelOptions = {
presets: ['es2015', 'react'],
plugins: [
'transform-async-to-generator',
'transform-object-rest-spread',
'transform-class-properties',
'transform-runtime'
]
}
const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'))
gulp.task('compile', [
'compile-bin',
@ -57,14 +50,6 @@ gulp.task('compile-client', () => {
.pipe(notify('Compiled client files'))
})
gulp.task('compile-test', () => {
return gulp.src('test/*.js')
.pipe(cache('test'))
.pipe(babel(babelOptions))
.pipe(gulp.dest('dist/test'))
.pipe(notify('Compiled test files'))
})
gulp.task('copy', ['copy-pages'])
gulp.task('copy-pages', () => {
@ -72,11 +57,6 @@ gulp.task('copy-pages', () => {
.pipe(gulp.dest('dist/pages'))
})
gulp.task('copy-test-fixtures', () => {
return gulp.src('test/fixtures/**/*')
.pipe(gulp.dest('dist/test/fixtures'))
})
gulp.task('compile-bench', () => {
return gulp.src('bench/*.js')
.pipe(cache('bench'))
@ -153,9 +133,13 @@ gulp.task('build-client', ['compile-lib', 'compile-client'], () => {
.pipe(notify('Built release client'))
})
gulp.task('test', ['compile', 'copy', 'compile-test', 'copy-test-fixtures'], () => {
return gulp.src('dist/test/*.js')
.pipe(ava())
gulp.task('test', () => {
process.env.NODE_ENV = 'test'
return gulp.src('test/**/**.test.js')
.pipe(ava({
verbose: true,
nyc: true
}))
})
gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => {
@ -209,10 +193,6 @@ gulp.task('clean', () => {
return del('dist')
})
gulp.task('clean-test', () => {
return del('dist/test')
})
gulp.task('default', [
'compile',
'build',
@ -227,7 +207,7 @@ gulp.task('release', (cb) => {
'build',
'copy',
'test'
], 'clean-test', cb)
], cb)
})
// avoid logging to the console

View file

@ -1,6 +1,8 @@
import React from 'react'
import htmlescape from 'htmlescape'
import pkg from '../../package.json'
import readPkgUp from 'read-pkg-up'
const pkg = readPkgUp.sync({normalize: false}).pkg
export default ({ head, css, html, data, dev, staticMarkup, cdn }) => {
return <html>

View file

@ -16,13 +16,35 @@
},
"scripts": {
"build": "gulp",
"test": "npm run lint && gulp test",
"pretest": "npm run lint",
"test": "gulp test",
"lint": "standard && standard bin/*",
"html-report": "nyc report --reporter=html",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"prepublish": "gulp release",
"precommit": "npm run lint"
},
"ava": {
"babel": {}
"nyc": {
"require": [
"babel-register"
],
"exclude": [
"gulpfile.js",
"css.js",
"link.js",
"head.js",
"client/**",
"**/pages/**",
"**/coverage/**",
"**/client/**",
"**/test/**",
"**/dist/**",
"**/examples/**",
"**/bench/**"
],
"all": true,
"sourceMap": false,
"instrument": false
},
"standard": {
"parser": "babel-eslint"
@ -54,11 +76,14 @@
"react": "15.4.0",
"react-dom": "15.4.0",
"react-hot-loader": "3.0.0-beta.6",
"read-pkg-up": "2.0.0",
"send": "0.14.1",
"sockjs-client": "1.1.1",
"strip-ansi": "3.0.1",
"url": "0.11.0",
"webpack": "1.13.3",
"webpack-dev-server": "1.16.2",
<<<<<<< HEAD
"sockjs-client": "1.1.1",
"write-file-webpack-plugin": "3.4.2"
},
@ -67,6 +92,15 @@
"babel-eslint": "7.1.1",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"benchmark": "2.1.2",
"write-file-webpack-plugin": "3.3.0"
},
"devDependencies": {
"ava": "0.16.0",
"babel-eslint": "7.0.0",
"babel-plugin-istanbul": "3.0.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"benchmark": "2.1.1",
"coveralls": "2.11.15",
"gulp": "3.9.1",
"gulp-ava": "0.15.0",
"gulp-babel": "6.1.2",
@ -74,6 +108,7 @@
"gulp-cached": "1.1.1",
"gulp-notify": "2.2.0",
"husky": "0.11.9",
"nyc": "9.0.1",
"run-sequence": "1.2.2",
"standard": "8.5.0",
"webpack-stream": "3.2.0"

View file

@ -1,4 +1,3 @@
import React from 'react'
import Head from 'next/head'

5
test/fixtures/basic/pages/link.js vendored Normal file
View file

@ -0,0 +1,5 @@
import React from 'react'
import Link from 'next/link'
export default () => (
<div>Hello World. <Link href='/about'>About</Link></div>
)

View file

@ -7,35 +7,40 @@ const dir = join(__dirname, 'fixtures', 'basic')
test.before(() => build(dir))
test(async t => {
test('renders a stateless component', async t => {
const html = await render('/stateless')
t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
t.true(html.includes('<h1>My component!</h1>'))
})
test(async t => {
const html = await render('/css')
t.true(html.includes('.css-im3wl1'))
t.true(html.includes('<div class="css-im3wl1">This is red</div>'))
})
test(async t => {
test('renders a stateful component', async t => {
const html = await render('/stateful')
t.true(html.includes('<div><p>The answer is 42</p></div>'))
})
test(async t => {
test('header helper renders header information', async t => {
const html = await (render('/head'))
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
t.true(html.includes('<meta content="my meta" class="next-head"/>'))
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})
test(async t => {
test('css helper renders styles', async t => {
const html = await render('/css')
t.true(html.includes('.css-im3wl1'))
t.true(html.includes('<div class="css-im3wl1">This is red</div>'))
})
test('renders properties populated asynchronously', async t => {
const html = await render('/async-props')
t.true(html.includes('<p>Diego Milito</p>'))
})
test('renders a link component', async t => {
const html = await render('/link')
t.true(html.includes('<a href="/about">About</a>'))
})
function render (url, ctx) {
return _render(url, ctx, { dir, staticMarkup: true })
}

View file

@ -0,0 +1,39 @@
import test from 'ava'
import shallowEquals from '../../lib/shallow-equals'
test('returns true if all key/value pairs match', t => {
t.true(shallowEquals({
a: 1,
b: 2,
c: 99
}, {
a: 1,
b: 2,
c: 99
}))
})
test('returns false if any key/value pair is different', t => {
t.false(shallowEquals({
a: 1,
b: 2,
c: 99
}, {
a: 1,
b: 2,
c: 99,
d: 33
}))
})
test('returns false if nested objects are contained', t => {
t.false(shallowEquals({
a: 1,
b: 2,
c: {}
}, {
a: 1,
b: 2,
c: {}
}))
})