Skip to content

Commit e0ae4c8

Browse files
authored
Merge pull request webpack#4650 from sendilkumarn/checkArrayExpectation
Refactor CheckArrayExpectation to ES6
2 parents 5dacac6 + 364d422 commit e0ae4c8

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

test/checkArrayExpectation.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
var fs = require("fs");
2-
var path = require("path");
1+
"use strict";
2+
const fs = require("fs");
3+
const path = require("path");
34

45
module.exports = function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, done) {
56
if(!done) {
67
done = upperCaseKind;
78
upperCaseKind = filename;
8-
filename = kind + "s";
9+
filename = `${kind}s`;
910
}
10-
var array = object[kind + "s"].slice().sort();
11-
if(kind === "warning") array = array.filter(function(item) {
12-
return !/from UglifyJs/.test(item);
13-
});
14-
if(fs.existsSync(path.join(testDirectory, filename + ".js"))) {
15-
var expectedFilename = path.join(testDirectory, filename + ".js");
16-
var expected = require(expectedFilename);
11+
let array = object[`${kind}s`].slice().sort();
12+
if(kind === "warning") array = array.filter(item => !/from UglifyJs/.test(item));
13+
if(fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
14+
const expectedFilename = path.join(testDirectory, `${filename}.js`);
15+
const expected = require(expectedFilename);
1716
if(expected.length < array.length)
18-
return done(new Error("More " + kind + "s while compiling than expected:\n\n" + array.join("\n\n") + ". Check expected warnings: " + filename)), true;
17+
return done(new Error(`More ${kind}s while compiling than expected:\n\n${array.join("\n\n")}. Check expected warnings: ${filename}`)), true;
1918
else if(expected.length > array.length)
20-
return done(new Error("Less " + kind + "s while compiling than expected:\n\n" + array.join("\n\n") + ". Check expected warnings: " + filename)), true;
21-
for(var i = 0; i < array.length; i++) {
19+
return done(new Error(`Less ${kind}s while compiling than expected:\n\n${array.join("\n\n")}. Check expected warnings: ${filename}`)), true;
20+
for(let i = 0; i < array.length; i++) {
2221
if(Array.isArray(expected[i])) {
23-
for(var j = 0; j < expected[i].length; j++) {
22+
for(let j = 0; j < expected[i].length; j++) {
2423
if(!expected[i][j].test(array[i]))
25-
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i][j].toString())), true;
24+
return done(new Error(`${upperCaseKind} ${i}: ${array[i]} doesn't match ${expected[i][j].toString()}`)), true;
2625
}
2726
} else if(!expected[i].test(array[i]))
28-
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i].toString())), true;
27+
return done(new Error(`${upperCaseKind} ${i}: ${array[i]} doesn't match ${expected[i].toString()}`)), true;
2928
}
3029
} else if(array.length > 0) {
31-
return done(new Error(upperCaseKind + "s while compiling:\n\n" + array.join("\n\n"))), true;
30+
return done(new Error(`${upperCaseKind}s while compiling:\n\n${array.join("\n\n")}`)), true;
3231
}
3332
}

0 commit comments

Comments
 (0)