2016-12-30 14:38:43 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/* globals describe it */
|
|
|
|
const should = require("should");
|
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
2017-01-03 05:02:49 +08:00
|
|
|
const defaultArgs = require("./binCases/ARGUMENTS.json");
|
2016-12-30 14:38:43 +08:00
|
|
|
|
2017-01-03 05:02:49 +08:00
|
|
|
describe("BinTestCases", function() {
|
2016-12-30 14:38:43 +08:00
|
|
|
const casesPath = path.join(__dirname, "binCases");
|
2017-01-03 05:02:49 +08:00
|
|
|
let categories = fs.readdirSync(casesPath).filter((folder) => {
|
|
|
|
return fs.statSync(path.join(casesPath, folder)).isDirectory()
|
|
|
|
});
|
2016-12-30 14:38:43 +08:00
|
|
|
categories = categories.map(cat => {
|
|
|
|
return {
|
|
|
|
name: cat,
|
|
|
|
tests: fs.readdirSync(path.join(casesPath, cat)).filter(function(folder) {
|
2017-01-03 05:02:49 +08:00
|
|
|
return folder.indexOf("_") < 0 || folder.indexOf("ARGUMENTS") < 0;
|
2016-12-30 14:38:43 +08:00
|
|
|
})
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
categories.forEach(category => {
|
2017-01-03 05:02:49 +08:00
|
|
|
describe(category.name, function() {
|
|
|
|
|
2016-12-30 14:38:43 +08:00
|
|
|
category.tests.forEach(testName => {
|
2017-01-03 05:02:49 +08:00
|
|
|
let suite = describe(testName, function() {});
|
|
|
|
let testArgs = defaultArgs;
|
|
|
|
let outputPath = path.join(path.resolve("../../js/bin"), category.name, testName);
|
|
|
|
const testDirectory = path.join(casesPath, category.name, testName);
|
|
|
|
const execHandler = require(path.join(testDirectory, "test.js"));
|
|
|
|
const execOptions = {
|
|
|
|
cwd: `${path.resolve("./", testDirectory)}`
|
|
|
|
};
|
|
|
|
|
|
|
|
try { // check if test specfic args exist
|
|
|
|
testArgs = Object.assign(
|
|
|
|
testArgs, require(path.join(testDirectory, "ARGUMENTS.json"))
|
|
|
|
);
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
execHandler(`${path.resolve(process.cwd(), "bin/webpack.js")}`, argsToArray(testArgs).concat(["--output-path", `${outputPath}`]), execOptions);
|
2016-12-30 14:38:43 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-01-03 05:02:49 +08:00
|
|
|
|
|
|
|
function argsToArray(argsObject) {
|
|
|
|
const argsArray = [];
|
|
|
|
|
|
|
|
for(let argKey in argsObject) {
|
|
|
|
argsArray.push(argKey);
|
|
|
|
argsArray.push(argsObject[argKey]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return argsArray;
|
|
|
|
}
|