Skip to content

Commit 9c3aaaa

Browse files
author
Gerald Yeo
committed
fix: tweak jest setting and code style
1 parent ea7297e commit 9c3aaaa

5 files changed

Lines changed: 72 additions & 78 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
[![npm][npm-badge]][npm-link]
66
[![Build Status][circle-badge]][circle-link]
7+
[![Coverage Status][codecov-badge]][codecov-link]
78
[![PRs Welcome][pr-welcome-badge]][pr-welcome-link]
89

910
This webpack plugin allows you to filter the list of output files before
@@ -107,3 +108,5 @@ For more info, check out the [usage.spec.js](./src/usage.spec.js) for more info.
107108
[multimatch-package]: https://github.com/sindresorhus/multimatch
108109
[pr-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
109110
[pr-welcome-link]: https://github.com/yeojz/filter-chunk-webpack-plugin/blob/master/CONTRIBUTING.md
111+
[codecov-badge]: https://img.shields.io/codecov/c/github/yeojz/filter-chunk-webpack-plugin/master.svg?style=flat-square
112+
[codecov-link]: https://codecov.io/gh/yeojz/filter-chunk-webpack-plugin

package-lock.json

Lines changed: 4 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"url": "https://github.com/yeojz/filter-chunk-webpack-plugin/issues"
3030
},
3131
"devDependencies": {
32-
"ajv": "^5.5.2",
3332
"babel-cli": "^6.26.0",
3433
"babel-preset-env": "^1.6.1",
3534
"codecov": "^3.0.0",
@@ -53,6 +52,7 @@
5352
"<rootDir>/index.js"
5453
],
5554
"resetMocks": true,
55+
"testEnvironment": "node",
5656
"testPathIgnorePatterns": [
5757
"/node_modules/",
5858
"/dist/",

src/index.spec.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
import FilterChunkWebpackPlugin from './index';
22

3-
describe('FilterChunkWebpackPlugin', function() {
4-
const PATTERN_ERROR = 'The "patterns" option should be an array';
3+
const PATTERN_ERROR = 'The "patterns" option should be an array';
54

6-
it('should set options from constructor', function() {
7-
const plugin = new FilterChunkWebpackPlugin({
8-
select: true,
9-
patterns: ['**/**']
10-
});
11-
12-
expect(plugin.options.select).toBe(true);
13-
expect(plugin.options.patterns).toEqual(['**/**']);
5+
test('should set options from constructor', () => {
6+
const plugin = new FilterChunkWebpackPlugin({
7+
select: true,
8+
patterns: ['**/**']
149
});
1510

16-
it('should set defaults from constructor', function() {
17-
const plugin = new FilterChunkWebpackPlugin();
11+
expect(plugin.options.select).toBe(true);
12+
expect(plugin.options.patterns).toEqual(['**/**']);
13+
});
1814

19-
expect(plugin.options.select).toEqual(false);
20-
expect(plugin.options.patterns).toEqual([]);
21-
});
15+
test('should set defaults from constructor', () => {
16+
const plugin = new FilterChunkWebpackPlugin();
2217

23-
it('should throw an Error when patterns is not array', function() {
24-
const plugin = () =>
25-
new FilterChunkWebpackPlugin({
26-
patterns: 'test'
27-
});
18+
expect(plugin.options.select).toEqual(false);
19+
expect(plugin.options.patterns).toEqual([]);
20+
});
2821

29-
expect(plugin).toThrow(PATTERN_ERROR);
30-
});
22+
test('should throw an Error when patterns is not array', () => {
23+
const plugin = () =>
24+
new FilterChunkWebpackPlugin({
25+
patterns: 'test'
26+
});
27+
28+
expect(plugin).toThrow(PATTERN_ERROR);
3129
});

src/usage.spec.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,63 @@ import FilterChunkWebpackPlugin from './index';
66
const OUTPUT_ROOT = path.join(path.resolve(__dirname), '..', '.spec_output');
77
const INPUT_ROOT = path.join(path.resolve(__dirname), '..', 'fixtures');
88

9-
describe('Webpack with FilterChunkWebpackPlugin', function() {
10-
it('[1] should not modify assets by default', function(done) {
11-
const config = generateWebpackConfiguration('it-1');
9+
jest.setTimeout(10000);
1210

13-
webpack(config, function(err, stats) {
14-
const assets = Object.keys(stats.compilation.assets);
11+
test('[1] should not modify assets by default', done => {
12+
const config = generateWebpackConfiguration('it-1');
1513

16-
expect(err).toBeFalsy();
17-
expect(stats.compilation.warnings.length).toEqual(0);
18-
expect(assets).toHaveLength(4);
14+
const compiler = webpack(config);
1915

20-
done();
21-
});
16+
compiler.run((err, stats) => {
17+
const assets = Object.keys(stats.compilation.assets);
18+
19+
expect(err).toBeFalsy();
20+
expect(stats.hasErrors()).toBeFalsy();
21+
expect(stats.hasWarnings()).toBeFalsy();
22+
expect(assets).toHaveLength(4);
23+
24+
done();
2225
});
26+
});
2327

24-
it('[2] should omit all relevant matches', function(done) {
25-
const config = generateWebpackConfiguration('it-2', {
26-
patterns: ['assets/**', '!assets/css/**']
27-
});
28+
test('[2] should omit all relevant matches', done => {
29+
const config = generateWebpackConfiguration('it-2', {
30+
patterns: ['assets/**', '!assets/css/**']
31+
});
2832

29-
webpack(config, function(err, stats) {
30-
const assets = Object.keys(stats.compilation.assets);
33+
const compiler = webpack(config);
34+
compiler.run((err, stats) => {
35+
const assets = Object.keys(stats.compilation.assets);
3136

32-
expect(err).toBeFalsy();
33-
expect(stats.compilation.warnings.length).toEqual(0);
34-
expect(assets).toHaveLength(2);
35-
expect(assets).toContain('app.js');
36-
expect(assets).toContain('assets/css/app.css');
37+
expect(err).toBeFalsy();
38+
expect(stats.hasErrors()).toBeFalsy();
39+
expect(stats.hasWarnings()).toBeFalsy();
40+
expect(assets).toHaveLength(2);
41+
expect(assets).toContain('app.js');
42+
expect(assets).toContain('assets/css/app.css');
3743

38-
done();
39-
});
44+
done();
4045
});
46+
});
4147

42-
it('[3] should pick all relevant matches', function(done) {
43-
const config = generateWebpackConfiguration('it-3', {
44-
select: true,
45-
patterns: ['assets/**', '!assets/css/**']
46-
});
48+
test('[3] should pick all relevant matches', done => {
49+
const config = generateWebpackConfiguration('it-3', {
50+
select: true,
51+
patterns: ['assets/**', '!assets/css/**']
52+
});
4753

48-
webpack(config, function(err, stats) {
49-
const assets = Object.keys(stats.compilation.assets);
54+
const compiler = webpack(config);
55+
compiler.run((err, stats) => {
56+
const assets = Object.keys(stats.compilation.assets);
5057

51-
expect(err).toBeFalsy();
52-
expect(stats.compilation.warnings.length).toEqual(0);
53-
expect(assets).toHaveLength(2);
54-
expect(assets).toContain('assets/images/png.png');
55-
expect(assets).toContain('assets/images/svg.svg');
58+
expect(err).toBeFalsy();
59+
expect(stats.hasErrors()).toBeFalsy();
60+
expect(stats.hasWarnings()).toBeFalsy();
61+
expect(assets).toHaveLength(2);
62+
expect(assets).toContain('assets/images/png.png');
63+
expect(assets).toContain('assets/images/svg.svg');
5664

57-
done();
58-
});
65+
done();
5966
});
6067
});
6168

0 commit comments

Comments
 (0)