Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Commit 88eee91

Browse files
committed
Move to jest
1 parent 48f1247 commit 88eee91

File tree

10 files changed

+893
-1467
lines changed

10 files changed

+893
-1467
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "ava"
7+
"test": "jest"
88
},
99
"files": [
1010
"src",
1111
"index.js"
1212
],
1313
"keywords": [
14-
"awesome",
15-
"react",
16-
"cli"
14+
"friendly",
15+
"errors",
16+
"webpack",
17+
"plugin"
1718
],
1819
"author": "Geoffroy Warin",
1920
"repository": {
@@ -26,8 +27,6 @@
2627
"homepage": "http://geowarin.github.io/friendly-errors-webpack-plugin",
2728
"license": "MIT",
2829
"devDependencies": {
29-
"assert-diff": "^1.1.0",
30-
"ava": "^0.16.0",
3130
"babel-core": "^6.13.2",
3231
"babel-eslint": "^6.1.2",
3332
"babel-loader": "^6.2.5",
@@ -36,6 +35,8 @@
3635
"eslint": "^3.3.1",
3736
"eslint-loader": "^1.5.0",
3837
"expect": "^1.20.2",
38+
"jest": "^18.1.0",
39+
"memory-fs": "^0.4.1",
3940
"webpack": "^2.1.0-beta.21"
4041
},
4142
"ava": {
@@ -45,7 +46,6 @@
4546
},
4647
"dependencies": {
4748
"chalk": "^1.1.3",
48-
"error-stack-parser": "^1.3.6",
49-
"memory-fs": "^0.4.1"
49+
"error-stack-parser": "^1.3.6"
5050
}
5151
}

test/integration.spec.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const test = require('ava');
21
const output = require('../src/output');
32
const deasync = require('deasync');
4-
const assert = require('assert-diff');
53
const webpack = require('webpack');
64
const FriendlyErrorsWebpackPlugin = require('../src/friendly-errors-plugin');
75
const MemoryFileSystem = require('memory-fs');
@@ -17,26 +15,23 @@ const syncWebpackWithPlugin = deasync(function(config, fn) {
1715
return compiler;
1816
});
1917

20-
test('integration : success', t => {
18+
it('integration : success', () => {
2119

22-
var logs = output.captureLogs(() => {
20+
const logs = output.captureLogs(() => {
2321
syncWebpack(require('./fixtures/success/webpack.config'));
2422
});
2523

26-
assert(
27-
/DONE Compiled successfully in (.\d*)ms/.test(logs),
28-
'Expected logs to include \'DONE Compiled successfully in {{number}}ms\''
29-
);
24+
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/);
3025
});
3126

3227

33-
test('integration : module-errors', t => {
28+
it('integration : module-errors', () => {
3429

35-
var logs = output.captureLogs(() => {
30+
const logs = output.captureLogs(() => {
3631
syncWebpack(require('./fixtures/module-errors/webpack.config.js'));
3732
});
3833

39-
assert.deepEqual(logs, [
34+
expect(logs).toEqual([
4035
' ERROR Failed to compile with 2 errors',
4136
'',
4237
'These dependencies were not found in node_modules:',
@@ -48,16 +43,16 @@ test('integration : module-errors', t => {
4843
]);
4944
});
5045

51-
test('integration : should display eslint warnings', t => {
46+
it('integration : should display eslint warnings', () => {
5247

53-
var logs = output.captureLogs(() => {
48+
const logs = output.captureLogs(() => {
5449
syncWebpack(require('./fixtures/eslint-warnings/webpack.config.js'));
5550
});
5651

57-
assert.deepEqual(logs, [
52+
expect(logs).toEqual([
5853
' WARNING Compiled with 1 warnings',
5954
'',
60-
' warning in ./fixtures/eslint-warnings/index.js',
55+
' warning in ./test/fixtures/eslint-warnings/index.js',
6156
'',
6257
`${__dirname}/fixtures/eslint-warnings/index.js
6358
1:7 warning 'unused' is assigned a value but never used no-unused-vars
@@ -71,16 +66,16 @@ test('integration : should display eslint warnings', t => {
7166
]);
7267
});
7368

74-
test('integration : babel syntax error', t => {
69+
it('integration : babel syntax error', () => {
7570

76-
var logs = output.captureLogs(() => {
71+
const logs = output.captureLogs(() => {
7772
syncWebpack(require('./fixtures/babel-syntax/webpack.config'));
7873
});
7974

80-
assert.deepEqual(logs, [
75+
expect(logs).toEqual([
8176
' ERROR Failed to compile with 1 errors',
8277
'',
83-
' error in ./fixtures/babel-syntax/index.js',
78+
' error in ./test/fixtures/babel-syntax/index.js',
8479
'',
8580
`SyntaxError: Unexpected token (5:11)
8681
@@ -94,25 +89,22 @@ test('integration : babel syntax error', t => {
9489
]);
9590
});
9691

97-
test('integration : webpack multi compiler : success', t => {
92+
it('integration : webpack multi compiler : success', () => {
9893

99-
var logs = output.captureLogs(() => {
94+
const logs = output.captureLogs(() => {
10095
syncWebpackWithPlugin(require('./fixtures/multi-compiler-success/webpack.config'));
10196
});
10297

103-
assert(
104-
/DONE Compiled successfully in (.\d*)ms/.test(logs),
105-
'Expected logs to include \'DONE Compiled successfully in {{number}}ms\''
106-
);
98+
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/)
10799
});
108100

109-
test('integration : webpack multi compiler : module-errors', t => {
101+
it('integration : webpack multi compiler : module-errors', () => {
110102

111-
var logs = output.captureLogs(() => {
103+
const logs = output.captureLogs(() => {
112104
syncWebpackWithPlugin(require('./fixtures/multi-compiler-module-errors/webpack.config'));
113105
});
114106

115-
assert.deepEqual(logs, [
107+
expect(logs).toEqual([
116108
' ERROR Failed to compile with 2 errors',
117109
'',
118110
'These dependencies were not found in node_modules:',

test/unit/formatErrors.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const formatErrors = require('../../src/core/formatErrors');
22
const expect = require('expect');
3-
const test = require('ava');
43

54
const simple = (errors) => errors
65
.filter(({ type }) => !type).map(({ message }) => message);
@@ -13,7 +12,7 @@ const notFound = (errors) => errors
1312

1413
const formatters = [allCaps];
1514

16-
test('formats the error based on the matching formatters', () => {
15+
it('formats the error based on the matching formatters', () => {
1716
const errors = [
1817
{ message: 'Error 1', type: undefined },
1918
{ message: 'Error 2', type: 'other' },
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const defaultError = require('../../../src/formatters/defaultError');
22
const expect = require('expect');
3-
const test = require('ava');
43
const chalk = require('chalk');
54

65
const noColor = (arr) => arr.map(chalk.stripColor);
76
const error = { message: 'Error message', file: './src/index.js' };
87

9-
test('Formats errors with no type', () => {
8+
it('Formats errors with no type', () => {
109
expect(noColor(defaultError([error], 'Warning'))).toEqual([
1110
' Warning in ./src/index.js',
1211
'',
@@ -15,7 +14,7 @@ test('Formats errors with no type', () => {
1514
]);
1615
});
1716

18-
test('Does not format other errors', () => {
19-
const otherError = { ...error, type: 'other-error' };
17+
it('Does not format other errors', () => {
18+
const otherError = { type: 'other-error' };
2019
expect(noColor(defaultError([otherError], 'Error'))).toEqual([]);
2120
});

test/unit/formatters/moduleNotFound.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const moduleNotFound = require('../../../src/formatters/moduleNotFound');
22
const expect = require('expect');
3-
const test = require('ava');
43

5-
test('Formats module-not-found errors', () => {
4+
it('Formats module-not-found errors', () => {
65
const error = { type: 'module-not-found', module: 'redux' };
76
expect(moduleNotFound([error])).toEqual([
87
'This dependency was not found in node_modules:',
@@ -13,7 +12,7 @@ test('Formats module-not-found errors', () => {
1312
]);
1413
});
1514

16-
test('Groups all module-not-found into one', () => {
15+
it('Groups all module-not-found into one', () => {
1716
const reduxError = { type: 'module-not-found', module: 'redux' };
1817
const reactError = { type: 'module-not-found', module: 'react' };
1918
expect(moduleNotFound([reduxError, reactError])).toEqual([
@@ -26,7 +25,7 @@ test('Groups all module-not-found into one', () => {
2625
]);
2726
});
2827

29-
test('Does not format other errors', () => {
28+
it('Does not format other errors', () => {
3029
const otherError = { type: 'other-error', module: 'foo' };
3130
expect(moduleNotFound([otherError])).toEqual([]);
3231
});

test/unit/plugin/friendlyErrors.spec.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
11
const expect = require('expect');
2-
const test = require('ava');
32
const EventEmitter = require('events');
43
const Stats = require('webpack/lib/Stats');
54
const Module = require('webpack/lib/Module');
65
EventEmitter.prototype.plugin = EventEmitter.prototype.on;
7-
var assert = require('assert-diff');
86

97
const output = require("../../../src/output");
108
const FriendlyErrorsPlugin = require("../../../index");
119

1210
const notifierPlugin = new FriendlyErrorsPlugin();
13-
var mockCompiler = new EventEmitter();
11+
const mockCompiler = new EventEmitter();
1412
notifierPlugin.apply(mockCompiler);
1513

16-
test('friendlyErrors : capture invalid message', t => {
14+
it('friendlyErrors : capture invalid message', () => {
1715

18-
var logs = output.captureLogs(() => {
16+
const logs = output.captureLogs(() => {
1917
mockCompiler.emit('invalid');
2018
});
2119

22-
assert.deepEqual(logs, [
20+
expect(logs).toEqual([
2321
' WAIT Compiling...',
2422
''
25-
]
26-
);
23+
]);
2724
});
2825

29-
test('friendlyErrors : capture compilation without errors', t => {
26+
it('friendlyErrors : capture compilation without errors', () => {
3027

31-
var stats = successfulCompilationStats();
32-
var logs = output.captureLogs(() => {
28+
const stats = successfulCompilationStats();
29+
const logs = output.captureLogs(() => {
3330
mockCompiler.emit('done', stats);
3431
});
3532

36-
assert.deepEqual(logs, [
33+
expect(logs).toEqual([
3734
' DONE Compiled successfully in 100ms',
3835
''
3936
]);
4037
});
4138

42-
test('friendlyErrors : default clearConsole option', t => {
39+
it('friendlyErrors : default clearConsole option', () => {
4340
const plugin = new FriendlyErrorsPlugin();
44-
assert.strictEqual(plugin.shouldClearConsole, true)
41+
expect(plugin.shouldClearConsole).toBeTruthy()
4542
});
4643

47-
test('friendlyErrors : clearConsole option', t => {
44+
it('friendlyErrors : clearConsole option', () => {
4845
const plugin = new FriendlyErrorsPlugin({ clearConsole: false });
49-
assert.strictEqual(plugin.shouldClearConsole, false)
46+
expect(plugin.shouldClearConsole).toBeFalsy()
5047
});
5148

5249
function successfulCompilationStats() {
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
const babelSyntax = require('../../../src/transformers/babelSyntax');
22
const expect = require('expect');
3-
const test = require('ava');
43

5-
test('Sets severity to 1000', () => {
4+
it('Sets severity to 1000', () => {
65
const error = { name: 'ModuleBuildError', message: 'SyntaxError' };
76
expect(babelSyntax(error).severity).toEqual(1000);
87
});
98

10-
test('Does not set type (it should be handle by the default formatter)', () => {
9+
it('Does not set type (it should be handle by the default formatter)', () => {
1110
const error = { name: 'ModuleBuildError', message: 'SyntaxError' };
1211
expect(babelSyntax(error).type).toEqual(undefined);
1312
});
1413

15-
test('Ignores other errors', () => {
14+
it('Ignores other errors', () => {
1615
const error = { name: 'OtherError' };
1716
expect(babelSyntax(error)).toEqual(error);
1817
});
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const moduleNotFound = require('../../../src/transformers/moduleNotFound');
22
const expect = require('expect');
3-
const test = require('ava');
43

54
const error = {
65
name: 'ModuleNotFoundError',
@@ -10,20 +9,20 @@ const error = {
109
},
1110
};
1211

13-
test('Sets severity to 900', () => {
12+
it('Sets severity to 900', () => {
1413
expect(moduleNotFound(error).severity).toEqual(900);
1514
});
1615

17-
test('Sets module name', () => {
16+
it('Sets module name', () => {
1817
expect(moduleNotFound(error).module).toEqual('redux');
1918
});
2019

21-
test('Sets the appropiate message', () => {
20+
it('Sets the appropiate message', () => {
2221
const message = 'Module not found redux';
2322
expect(moduleNotFound(error).message).toEqual(message);
2423
});
2524

26-
test('Sets the appropiate message', () => {
25+
it('Sets the appropiate message', () => {
2726
const message = 'Module not found redux';
2827
expect(moduleNotFound({
2928
name: 'ModuleNotFoundError',
@@ -32,7 +31,7 @@ test('Sets the appropiate message', () => {
3231
}).type).toEqual('module-not-found');
3332
});
3433

35-
test('Ignores other errors', () => {
34+
it('Ignores other errors', () => {
3635
const error = { name: 'OtherError' };
3736
expect(moduleNotFound(error)).toEqual(error);
3837
});

test/unit/utils/utils.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
const utils = require('../../../src/utils');
2-
const test = require('ava');
3-
const assert = require('assert-diff');
42

53
const concat = utils.concat;
64
const uniqueBy = utils.uniqueBy;
75

8-
test('concat should concat removing undefined and null values', () => {
6+
it('concat should concat removing undefined and null values', () => {
97
const result = concat(1, undefined, '', null);
10-
assert.deepEqual(result,
8+
expect(result).toEqual(
119
[1, '']
1210
);
1311
});
1412

15-
test('concat should handle arrays', () => {
13+
it('concat should handle arrays', () => {
1614
const result = concat(1, [2, 3], null);
17-
assert.deepEqual(result,
15+
expect(result).toEqual(
1816
[1, 2, 3]
1917
);
2018
});
2119

22-
test('uniqueBy should dedupe based on criterion returned from iteratee function', () => {
20+
it('uniqueBy should dedupe based on criterion returned from iteratee function', () => {
2321
const result = uniqueBy([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 3 }], function(val) {
2422
return val.id;
2523
});
26-
assert.deepEqual(result, [{ id: 1 }, { id: 2 }, { id: 3 }]);
24+
expect(result).toEqual([{ id: 1 }, { id: 2 }, { id: 3 }]);
2725
});

0 commit comments

Comments
 (0)