2014-06-18 04:34:30 +08:00
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
|
|
|
|
2016-07-03 19:13:01 +08:00
|
|
|
module.exports = function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, done) {
|
|
|
|
if(!done) {
|
|
|
|
done = upperCaseKind;
|
|
|
|
upperCaseKind = filename;
|
|
|
|
filename = kind + "s";
|
|
|
|
}
|
2015-08-09 18:42:43 +08:00
|
|
|
var array = object[kind + "s"].slice().sort();
|
|
|
|
if(kind === "warning") array = array.filter(function(item) {
|
|
|
|
return !/from UglifyJs/.test(item);
|
|
|
|
});
|
2016-07-03 19:13:01 +08:00
|
|
|
if(fs.existsSync(path.join(testDirectory, filename + ".js"))) {
|
|
|
|
var expected = require(path.join(testDirectory, filename + ".js"));
|
2014-06-18 04:34:30 +08:00
|
|
|
if(expected.length < array.length)
|
|
|
|
return done(new Error("More " + kind + "s while compiling than expected:\n\n" + array.join("\n\n"))), true;
|
|
|
|
else if(expected.length > array.length)
|
|
|
|
return done(new Error("Less " + kind + "s while compiling than expected:\n\n" + array.join("\n\n"))), true;
|
|
|
|
for(var i = 0; i < array.length; i++) {
|
|
|
|
if(Array.isArray(expected[i])) {
|
|
|
|
for(var j = 0; j < expected[i].length; j++) {
|
|
|
|
if(!expected[i][j].test(array[i]))
|
|
|
|
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i][j].toString())), true;
|
|
|
|
}
|
|
|
|
} else if(!expected[i].test(array[i]))
|
|
|
|
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i].toString())), true;
|
|
|
|
}
|
|
|
|
} else if(array.length > 0) {
|
|
|
|
return done(new Error(upperCaseKind + "s while compiling:\n\n" + array.join("\n\n"))), true;
|
|
|
|
}
|
|
|
|
}
|