|
1 | | -var fs = require("fs"); |
2 | | -var path = require("path"); |
| 1 | +"use strict"; |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
3 | 4 |
|
4 | 5 | module.exports = function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, done) { |
5 | 6 | if(!done) { |
6 | 7 | done = upperCaseKind; |
7 | 8 | upperCaseKind = filename; |
8 | | - filename = kind + "s"; |
| 9 | + filename = `${kind}s`; |
9 | 10 | } |
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); |
17 | 16 | 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; |
19 | 18 | 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++) { |
22 | 21 | 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++) { |
24 | 23 | 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; |
26 | 25 | } |
27 | 26 | } 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; |
29 | 28 | } |
30 | 29 | } 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; |
32 | 31 | } |
33 | 32 | } |
0 commit comments