Skip to content

Commit 0f2979b

Browse files
bcoenkzawa
authored andcommitted
chore: switch from ava to jest (vercel#381)
1 parent 694c8c5 commit 0f2979b

File tree

5 files changed

+103
-115
lines changed

5 files changed

+103
-115
lines changed

.babelrc

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@
55
"transform-object-rest-spread",
66
"transform-class-properties",
77
"transform-runtime"
8-
],
9-
"env": {
10-
"test": {
11-
"plugins": ["istanbul"]
12-
}
13-
}
8+
]
149
}

gulpfile.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ const gulp = require('gulp')
33
const babel = require('gulp-babel')
44
const cache = require('gulp-cached')
55
const notify_ = require('gulp-notify')
6-
const ava = require('gulp-ava')
76
const benchmark = require('gulp-benchmark')
87
const sequence = require('run-sequence')
98
const webpack = require('webpack-stream')
109
const del = require('del')
11-
const processEnv = require('gulp-process-env')
10+
const jest = require('gulp-jest')
1211

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

@@ -135,14 +134,18 @@ gulp.task('build-client', ['compile-lib', 'compile-client'], () => {
135134
})
136135

137136
gulp.task('test', () => {
138-
const env = processEnv({NODE_ENV: 'test'})
139-
return gulp.src('test/**/**.test.js')
140-
.pipe(env)
141-
.pipe(ava({
137+
return gulp.src('./test')
138+
.pipe(jest.default({
139+
coverage: true,
142140
verbose: true,
143-
nyc: true
141+
config: {
142+
rootDir: './test',
143+
testEnvironment: 'node',
144+
coveragePathIgnorePatterns: [
145+
'test/.*'
146+
]
147+
}
144148
}))
145-
.pipe(env.restore())
146149
})
147150

148151
gulp.task('bench', ['compile', 'copy', 'compile-bench', 'copy-bench-fixtures'], () => {

package.json

+9-31
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,13 @@
1818
"build": "gulp",
1919
"pretest": "npm run lint",
2020
"test": "gulp test",
21-
"html-report": "nyc report --reporter=html",
22-
"ava": "cross-env NODE_ENV=test nyc ava --verbose",
23-
"coveralls": "nyc report --reporter=text-lcov | coveralls",
21+
"html-report": "nyc report --temp-directory=./coverage --reporter=html",
22+
"jest": "jest --coverage",
23+
"coveralls": "nyc report --temp-directory=./coverage --reporter=text-lcov | coveralls",
2424
"lint": "standard && standard bin/*",
2525
"prepublish": "gulp release",
2626
"precommit": "npm run lint"
2727
},
28-
"nyc": {
29-
"require": [
30-
"babel-core/register"
31-
],
32-
"exclude": [
33-
"gulpfile.js",
34-
"css.js",
35-
"link.js",
36-
"head.js",
37-
"client/**",
38-
"**/pages/**",
39-
"**/coverage/**",
40-
"**/client/**",
41-
"**/test/**",
42-
"**/dist/**",
43-
"**/examples/**",
44-
"**/bench/**"
45-
],
46-
"all": false,
47-
"sourceMap": false,
48-
"instrument": false
49-
},
5028
"standard": {
5129
"parser": "babel-eslint"
5230
},
@@ -92,24 +70,24 @@
9270
"write-file-webpack-plugin": "3.4.2"
9371
},
9472
"devDependencies": {
95-
"ava": "0.17.0",
9673
"babel-eslint": "7.1.1",
97-
"babel-plugin-istanbul": "3.0.0",
9874
"babel-plugin-transform-remove-strict-mode": "0.0.2",
9975
"benchmark": "2.1.2",
10076
"coveralls": "2.11.15",
101-
"cross-env": "3.1.3",
10277
"gulp": "3.9.1",
103-
"gulp-ava": "0.15.0",
10478
"gulp-babel": "6.1.2",
10579
"gulp-benchmark": "1.1.1",
10680
"gulp-cached": "1.1.1",
81+
"gulp-jest": "^0.6.0",
10782
"gulp-notify": "2.2.0",
108-
"gulp-process-env": "0.0.2",
10983
"husky": "0.11.9",
110-
"nyc": "10.0.0",
84+
"jest": "^17.0.3",
85+
"nyc": "^10.0.0",
11186
"run-sequence": "1.2.2",
11287
"standard": "8.6.0",
11388
"webpack-stream": "3.2.0"
89+
},
90+
"jest": {
91+
"testEnvironment": "node"
11492
}
11593
}

test/integration.test.js

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,51 @@
1-
import test from 'ava'
2-
import { join } from 'path'
1+
/* global expect, jasmine, describe, test, beforeAll */
2+
3+
'use strict'
4+
35
import build from '../server/build'
6+
import { join } from 'path'
47
import { render as _render } from '../server/render'
58

69
const dir = join(__dirname, 'fixtures', 'basic')
710

8-
test.before(() => build(dir))
9-
10-
test('renders a stateless component', async t => {
11-
const html = await render('/stateless')
12-
t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
13-
t.true(html.includes('<h1>My component!</h1>'))
14-
})
15-
16-
test('renders a stateful component', async t => {
17-
const html = await render('/stateful')
18-
t.true(html.includes('<div><p>The answer is 42</p></div>'))
19-
})
20-
21-
test('header helper renders header information', async t => {
22-
const html = await (render('/head'))
23-
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
24-
t.true(html.includes('<meta content="my meta" class="next-head"/>'))
25-
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
26-
})
27-
28-
test('css helper renders styles', async t => {
29-
const html = await render('/css')
30-
t.regex(html, /\.css-\w+/)
31-
t.regex(html, /<div class="css-\w+">This is red<\/div>/)
32-
})
33-
34-
test('renders properties populated asynchronously', async t => {
35-
const html = await render('/async-props')
36-
t.true(html.includes('<p>Diego Milito</p>'))
37-
})
38-
39-
test('renders a link component', async t => {
40-
const html = await render('/link')
41-
t.true(html.includes('<a href="/about">About</a>'))
11+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
12+
13+
describe('integration tests', () => {
14+
beforeAll(() => build(dir))
15+
16+
test('renders a stateless component', async () => {
17+
const html = await render('/stateless')
18+
expect(html.includes('<meta charset="utf-8" class="next-head"/>')).toBeTruthy()
19+
expect(html.includes('<h1>My component!</h1>')).toBeTruthy()
20+
})
21+
22+
test('renders a stateful component', async () => {
23+
const html = await render('/stateful')
24+
expect(html.includes('<div><p>The answer is 42</p></div>')).toBeTruthy()
25+
})
26+
27+
test('header helper renders header information', async () => {
28+
const html = await (render('/head'))
29+
expect(html.includes('<meta charset="iso-8859-5" class="next-head"/>')).toBeTruthy()
30+
expect(html.includes('<meta content="my meta" class="next-head"/>')).toBeTruthy()
31+
expect(html.includes('<div><h1>I can haz meta tags</h1></div>')).toBeTruthy()
32+
})
33+
34+
test('css helper renders styles', async () => {
35+
const html = await render('/css')
36+
expect(/\.css-\w+/.test(html)).toBeTruthy()
37+
expect(/<div class="css-\w+">This is red<\/div>/.test(html)).toBeTruthy()
38+
})
39+
40+
test('renders properties populated asynchronously', async () => {
41+
const html = await render('/async-props')
42+
expect(html.includes('<p>Diego Milito</p>')).toBeTruthy()
43+
})
44+
45+
test('renders a link component', async () => {
46+
const html = await render('/link')
47+
expect(html.includes('<a href="/about">About</a>')).toBeTruthy()
48+
})
4249
})
4350

4451
function render (url, ctx) {

test/lib/shallow-equals.test.js

+39-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
import test from 'ava'
1+
/* global expect, describe, test */
2+
3+
'use strict'
4+
25
import shallowEquals from '../../lib/shallow-equals'
36

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-
})
7+
describe('shallow-equals', () => {
8+
test('returns true if all key/value pairs match', () => {
9+
expect(shallowEquals({
10+
a: 1,
11+
b: 2,
12+
c: 99
13+
}, {
14+
a: 1,
15+
b: 2,
16+
c: 99
17+
})).toBeTruthy()
18+
})
1519

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-
})
20+
test('returns false if any key/value pair is different', () => {
21+
expect(shallowEquals({
22+
a: 1,
23+
b: 2,
24+
c: 99
25+
}, {
26+
a: 1,
27+
b: 2,
28+
c: 99,
29+
d: 33
30+
})).toBeFalsy()
31+
})
2832

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-
}))
33+
test('returns false if nested objects are contained', () => {
34+
expect(shallowEquals({
35+
a: 1,
36+
b: 2,
37+
c: {}
38+
}, {
39+
a: 1,
40+
b: 2,
41+
c: {}
42+
})).toBeFalsy()
43+
})
3944
})

0 commit comments

Comments
 (0)