1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
"use strict";
const fs = require("fs");
const path = require("path");
module.exports = function checkArrayExpectation(
testDirectory,
object,
kind,
filename,
upperCaseKind,
done
) {
if (!done) {
done = upperCaseKind;
upperCaseKind = filename;
filename = `${kind}s`;
}
let array = object[`${kind}s`].slice().sort();
if (kind === "warning")
array = array.filter(item => !/from UglifyJs/.test(item));
if (fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
const expectedFilename = path.join(testDirectory, `${filename}.js`);
const expected = require(expectedFilename);
if (expected.length < array.length)
return (
done(
new Error(
`More ${kind}s while compiling than expected:\n\n${array.join(
"\n\n"
)}. Check expected warnings: ${filename}`
)
),
true
);
else if (expected.length > array.length)
return (
done(
new Error(
`Less ${kind}s while compiling than expected:\n\n${array.join(
"\n\n"
)}. Check expected warnings: ${filename}`
)
),
true
);
for (let i = 0; i < array.length; i++) {
if (Array.isArray(expected[i])) {
for (let 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
);
}
};
|