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

chore: switch from ava to jest (#381)

This commit is contained in:
Benjamin E. Coe 2016-12-12 04:31:49 -08:00 committed by Naoyuki Kanezawa
parent 694c8c56c7
commit 0f2979b02b
5 changed files with 97 additions and 109 deletions

View file

@ -5,10 +5,5 @@
"transform-object-rest-spread", "transform-object-rest-spread",
"transform-class-properties", "transform-class-properties",
"transform-runtime" "transform-runtime"
], ]
"env": {
"test": {
"plugins": ["istanbul"]
}
}
} }

View file

@ -3,12 +3,11 @@ const gulp = require('gulp')
const babel = require('gulp-babel') const babel = require('gulp-babel')
const cache = require('gulp-cached') const cache = require('gulp-cached')
const notify_ = require('gulp-notify') const notify_ = require('gulp-notify')
const ava = require('gulp-ava')
const benchmark = require('gulp-benchmark') const benchmark = require('gulp-benchmark')
const sequence = require('run-sequence') const sequence = require('run-sequence')
const webpack = require('webpack-stream') const webpack = require('webpack-stream')
const del = require('del') const del = require('del')
const processEnv = require('gulp-process-env') const jest = require('gulp-jest')
const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8')) const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'))
@ -135,14 +134,18 @@ gulp.task('build-client', ['compile-lib', 'compile-client'], () => {
}) })
gulp.task('test', () => { gulp.task('test', () => {
const env = processEnv({NODE_ENV: 'test'}) return gulp.src('./test')
return gulp.src('test/**/**.test.js') .pipe(jest.default({
.pipe(env) coverage: true,
.pipe(ava({
verbose: true, verbose: true,
nyc: true config: {
rootDir: './test',
testEnvironment: 'node',
coveragePathIgnorePatterns: [
'test/.*'
]
}
})) }))
.pipe(env.restore())
}) })
gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => { gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => {

View file

@ -18,35 +18,13 @@
"build": "gulp", "build": "gulp",
"pretest": "npm run lint", "pretest": "npm run lint",
"test": "gulp test", "test": "gulp test",
"html-report": "nyc report --reporter=html", "html-report": "nyc report --temp-directory=./coverage --reporter=html",
"ava": "cross-env NODE_ENV=test nyc ava --verbose", "jest": "jest --coverage",
"coveralls": "nyc report --reporter=text-lcov | coveralls", "coveralls": "nyc report --temp-directory=./coverage --reporter=text-lcov | coveralls",
"lint": "standard && standard bin/*", "lint": "standard && standard bin/*",
"prepublish": "gulp release", "prepublish": "gulp release",
"precommit": "npm run lint" "precommit": "npm run lint"
}, },
"nyc": {
"require": [
"babel-core/register"
],
"exclude": [
"gulpfile.js",
"css.js",
"link.js",
"head.js",
"client/**",
"**/pages/**",
"**/coverage/**",
"**/client/**",
"**/test/**",
"**/dist/**",
"**/examples/**",
"**/bench/**"
],
"all": false,
"sourceMap": false,
"instrument": false
},
"standard": { "standard": {
"parser": "babel-eslint" "parser": "babel-eslint"
}, },
@ -92,24 +70,24 @@
"write-file-webpack-plugin": "3.4.2" "write-file-webpack-plugin": "3.4.2"
}, },
"devDependencies": { "devDependencies": {
"ava": "0.17.0",
"babel-eslint": "7.1.1", "babel-eslint": "7.1.1",
"babel-plugin-istanbul": "3.0.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2", "babel-plugin-transform-remove-strict-mode": "0.0.2",
"benchmark": "2.1.2", "benchmark": "2.1.2",
"coveralls": "2.11.15", "coveralls": "2.11.15",
"cross-env": "3.1.3",
"gulp": "3.9.1", "gulp": "3.9.1",
"gulp-ava": "0.15.0",
"gulp-babel": "6.1.2", "gulp-babel": "6.1.2",
"gulp-benchmark": "1.1.1", "gulp-benchmark": "1.1.1",
"gulp-cached": "1.1.1", "gulp-cached": "1.1.1",
"gulp-jest": "^0.6.0",
"gulp-notify": "2.2.0", "gulp-notify": "2.2.0",
"gulp-process-env": "0.0.2",
"husky": "0.11.9", "husky": "0.11.9",
"nyc": "10.0.0", "jest": "^17.0.3",
"nyc": "^10.0.0",
"run-sequence": "1.2.2", "run-sequence": "1.2.2",
"standard": "8.6.0", "standard": "8.6.0",
"webpack-stream": "3.2.0" "webpack-stream": "3.2.0"
},
"jest": {
"testEnvironment": "node"
} }
} }

View file

@ -1,44 +1,51 @@
import test from 'ava' /* global expect, jasmine, describe, test, beforeAll */
import { join } from 'path'
'use strict'
import build from '../server/build' import build from '../server/build'
import { join } from 'path'
import { render as _render } from '../server/render' import { render as _render } from '../server/render'
const dir = join(__dirname, 'fixtures', 'basic') const dir = join(__dirname, 'fixtures', 'basic')
test.before(() => build(dir)) jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
test('renders a stateless component', async t => { describe('integration tests', () => {
beforeAll(() => build(dir))
test('renders a stateless component', async () => {
const html = await render('/stateless') const html = await render('/stateless')
t.true(html.includes('<meta charset="utf-8" class="next-head"/>')) expect(html.includes('<meta charset="utf-8" class="next-head"/>')).toBeTruthy()
t.true(html.includes('<h1>My component!</h1>')) expect(html.includes('<h1>My component!</h1>')).toBeTruthy()
}) })
test('renders a stateful component', async t => { test('renders a stateful component', async () => {
const html = await render('/stateful') const html = await render('/stateful')
t.true(html.includes('<div><p>The answer is 42</p></div>')) expect(html.includes('<div><p>The answer is 42</p></div>')).toBeTruthy()
}) })
test('header helper renders header information', async t => { test('header helper renders header information', async () => {
const html = await (render('/head')) const html = await (render('/head'))
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>')) expect(html.includes('<meta charset="iso-8859-5" class="next-head"/>')).toBeTruthy()
t.true(html.includes('<meta content="my meta" class="next-head"/>')) expect(html.includes('<meta content="my meta" class="next-head"/>')).toBeTruthy()
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>')) expect(html.includes('<div><h1>I can haz meta tags</h1></div>')).toBeTruthy()
}) })
test('css helper renders styles', async t => { test('css helper renders styles', async () => {
const html = await render('/css') const html = await render('/css')
t.regex(html, /\.css-\w+/) expect(/\.css-\w+/.test(html)).toBeTruthy()
t.regex(html, /<div class="css-\w+">This is red<\/div>/) expect(/<div class="css-\w+">This is red<\/div>/.test(html)).toBeTruthy()
}) })
test('renders properties populated asynchronously', async t => { test('renders properties populated asynchronously', async () => {
const html = await render('/async-props') const html = await render('/async-props')
t.true(html.includes('<p>Diego Milito</p>')) expect(html.includes('<p>Diego Milito</p>')).toBeTruthy()
}) })
test('renders a link component', async t => { test('renders a link component', async () => {
const html = await render('/link') const html = await render('/link')
t.true(html.includes('<a href="/about">About</a>')) expect(html.includes('<a href="/about">About</a>')).toBeTruthy()
})
}) })
function render (url, ctx) { function render (url, ctx) {

View file

@ -1,8 +1,12 @@
import test from 'ava' /* global expect, describe, test */
'use strict'
import shallowEquals from '../../lib/shallow-equals' import shallowEquals from '../../lib/shallow-equals'
test('returns true if all key/value pairs match', t => { describe('shallow-equals', () => {
t.true(shallowEquals({ test('returns true if all key/value pairs match', () => {
expect(shallowEquals({
a: 1, a: 1,
b: 2, b: 2,
c: 99 c: 99
@ -10,11 +14,11 @@ test('returns true if all key/value pairs match', t => {
a: 1, a: 1,
b: 2, b: 2,
c: 99 c: 99
})) })).toBeTruthy()
}) })
test('returns false if any key/value pair is different', t => { test('returns false if any key/value pair is different', () => {
t.false(shallowEquals({ expect(shallowEquals({
a: 1, a: 1,
b: 2, b: 2,
c: 99 c: 99
@ -23,11 +27,11 @@ test('returns false if any key/value pair is different', t => {
b: 2, b: 2,
c: 99, c: 99,
d: 33 d: 33
})) })).toBeFalsy()
}) })
test('returns false if nested objects are contained', t => { test('returns false if nested objects are contained', () => {
t.false(shallowEquals({ expect(shallowEquals({
a: 1, a: 1,
b: 2, b: 2,
c: {} c: {}
@ -35,5 +39,6 @@ test('returns false if nested objects are contained', t => {
a: 1, a: 1,
b: 2, b: 2,
c: {} c: {}
})) })).toBeFalsy()
})
}) })