Skip to content

Commit 8e884b1

Browse files
committed
refacotr(ES6): Errors.test.js
1 parent d9ac043 commit 8e884b1

1 file changed

Lines changed: 34 additions & 32 deletions

File tree

‎test/Errors.test.js‎

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
"use strict";
2+
13
/*globals describe it */
2-
var should = require("should");
3-
var path = require("path");
4+
const should = require("should");
5+
const path = require("path");
46

5-
var webpack = require("../lib/webpack");
7+
const webpack = require("../lib/webpack");
68

7-
var base = path.join(__dirname, "fixtures", "errors");
9+
const base = path.join(__dirname, "fixtures", "errors");
810

9-
describe("Errors", function() {
11+
describe("Errors", () => {
1012
function customOutputFilesystem(c) {
11-
var files = {};
13+
const files = {};
1214
c.outputFileSystem = {
1315
join: path.join.bind(path),
1416
mkdirp: function(path, callback) {
@@ -24,9 +26,9 @@ describe("Errors", function() {
2426

2527
function getErrors(options, callback) {
2628
options.context = base;
27-
var c = webpack(options);
29+
const c = webpack(options);
2830
customOutputFilesystem(c);
29-
c.run(function(err, stats) {
31+
c.run((err, stats) => {
3032
if(err) throw err;
3133
should.strictEqual(typeof stats, "object");
3234
stats = stats.toJson({
@@ -40,14 +42,14 @@ describe("Errors", function() {
4042
callback(stats.errors, stats.warnings);
4143
});
4244
}
43-
it("should throw an error if file doesn't exist", function(done) {
45+
it("should throw an error if file doesn't exist", (done) => {
4446
getErrors({
4547
entry: "./missingFile"
46-
}, function(errors, warnings) {
48+
}, (errors, warnings) => {
4749
errors.length.should.be.eql(2);
4850
warnings.length.should.be.eql(0);
4951
errors.sort();
50-
var lines = errors[0].split("\n");
52+
let lines = errors[0].split("\n");
5153
lines[0].should.match(/missingFile.js/);
5254
lines[1].should.match(/^Module not found/);
5355
lines[1].should.match(/\.\/dir\/missing2/);
@@ -60,25 +62,25 @@ describe("Errors", function() {
6062
done();
6163
});
6264
});
63-
it("should report require.extensions as unsupported", function(done) {
65+
it("should report require.extensions as unsupported", (done) => {
6466
getErrors({
6567
entry: "./require.extensions"
66-
}, function(errors, warnings) {
68+
}, (errors, warnings) => {
6769
errors.length.should.be.eql(0);
6870
warnings.length.should.be.eql(1);
69-
var lines = warnings[0].split("\n");
71+
const lines = warnings[0].split("\n");
7072
lines[0].should.match(/require.extensions\.js/);
7173
lines[1].should.match(/require.extensions is not supported by webpack/);
7274
done();
7375
});
7476
});
75-
it("should warn about case-sensitive module names", function(done) {
77+
it("should warn about case-sensitive module names", (done) => {
7678
getErrors({
7779
entry: "./case-sensitive"
78-
}, function(errors, warnings) {
80+
}, (errors, warnings) => {
7981
if(errors.length === 0) {
8082
warnings.length.should.be.eql(1);
81-
var lines = warnings[0].split("\n");
83+
const lines = warnings[0].split("\n");
8284
lines[4].should.match(/FILE\.js/);
8385
lines[5].should.match(/Used by/);
8486
lines[6].should.match(/case-sensitive/);
@@ -92,15 +94,15 @@ describe("Errors", function() {
9294
done();
9395
});
9496
});
95-
it("should warn about NoErrorsPlugin being deprecated in favor of NoEmitOnErrorsPlugin", function(done) {
97+
it("should warn about NoErrorsPlugin being deprecated in favor of NoEmitOnErrorsPlugin", (done) => {
9698
getErrors({
9799
entry: "./no-errors-deprecate",
98100
plugins: [
99101
new webpack.NoErrorsPlugin()
100102
]
101-
}, function(errors, warnings) {
103+
}, (errors, warnings) => {
102104
warnings.length.should.be.eql(1);
103-
var lines = warnings[0].split("\n");
105+
const lines = warnings[0].split("\n");
104106
lines[0].should.match(/webpack/);
105107
lines[0].should.match(/NoErrorsPlugin/);
106108
lines[0].should.match(/deprecated/);
@@ -109,29 +111,29 @@ describe("Errors", function() {
109111
done();
110112
});
111113
});
112-
it("should not warn if the NoEmitOnErrorsPlugin is used over the NoErrorsPlugin", function(done) {
114+
it("should not warn if the NoEmitOnErrorsPlugin is used over the NoErrorsPlugin", (done) => {
113115
getErrors({
114116
entry: "./no-errors-deprecate",
115117
plugins: [
116118
new webpack.NoEmitOnErrorsPlugin()
117119
]
118-
}, function(errors, warnings) {
120+
}, (errors, warnings) => {
119121
errors.length.should.be.eql(0);
120122
warnings.length.should.be.eql(0);
121123
done();
122124
});
123125
});
124-
it("should not not emit if NoEmitOnErrorsPlugin is used and there is an error", function(done) {
126+
it("should not not emit if NoEmitOnErrorsPlugin is used and there is an error", (done) => {
125127
getErrors({
126128
entry: "./missingFile",
127129
plugins: [
128130
new webpack.NoEmitOnErrorsPlugin()
129131
]
130-
}, function(errors, warnings) {
132+
}, (errors, warnings) => {
131133
errors.length.should.be.eql(2);
132134
warnings.length.should.be.eql(0);
133135
errors.sort();
134-
var lines = errors[0].split("\n");
136+
let lines = errors[0].split("\n");
135137
lines[0].should.match(/missingFile.js/);
136138
lines[1].should.match(/^Module not found/);
137139
lines[1].should.match(/\.\/dir\/missing2/);
@@ -144,7 +146,7 @@ describe("Errors", function() {
144146
done();
145147
});
146148
});
147-
it("should throw an error when using incorrect CommonsChunkPlugin configuration", function(done) {
149+
it("should throw an error when using incorrect CommonsChunkPlugin configuration", (done) => {
148150
getErrors({
149151
entry: {
150152
a: "./entry-point",
@@ -166,16 +168,16 @@ describe("Errors", function() {
166168
minChunks: Infinity
167169
})
168170
]
169-
}, function(errors, warnings) {
171+
}, (errors, warnings) => {
170172
errors.length.should.be.eql(1);
171173
warnings.length.should.be.eql(0);
172-
var lines = errors[0].split("\n");
174+
const lines = errors[0].split("\n");
173175
lines[0].should.match(/CommonsChunkPlugin/);
174176
lines[0].should.match(/non-entry/);
175177
done();
176178
});
177179
});
178-
it("should throw an error when trying to use [chunkhash] when it's invalid", function(done) {
180+
it("should throw an error when trying to use [chunkhash] when it's invalid", (done) => {
179181
getErrors({
180182
entry: {
181183
a: "./entry-point",
@@ -188,11 +190,11 @@ describe("Errors", function() {
188190
plugins: [
189191
new webpack.HotModuleReplacementPlugin()
190192
]
191-
}, function(errors, warnings) {
193+
}, (errors, warnings) => {
192194
errors.length.should.be.eql(3);
193195
warnings.length.should.be.eql(0);
194-
errors.forEach(function(error) {
195-
var lines = error.split("\n");
196+
errors.forEach((error) => {
197+
const lines = error.split("\n");
196198
lines[0].should.match(/chunk (a|b|c)/);
197199
lines[2].should.match(/\[chunkhash\].js/);
198200
lines[2].should.match(/use \[hash\] instead/);

0 commit comments

Comments
 (0)