Skip to content

Commit 16ebdb5

Browse files
committed
96 browser tests are in included in automated tests too
1 parent b0f5575 commit 16ebdb5

File tree

126 files changed

+741
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+741
-589
lines changed

test/TestCases.test.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
var should = require("should");
2+
var path = require("path");
3+
var fs = require("fs");
4+
var vm = require("vm");
5+
var Test = require("mocha/lib/Test");
6+
7+
var webpack = require("../lib/webpack");
8+
9+
describe("TestCases", function() {
10+
var casesPath = path.join(__dirname, "cases");
11+
var categories = fs.readdirSync(casesPath);
12+
categories = categories.map(function(cat) {
13+
return {
14+
name: cat,
15+
tests: fs.readdirSync(path.join(casesPath, cat)).filter(function(folder) {
16+
return folder.indexOf("_") < 0;
17+
})
18+
};
19+
});
20+
categories.forEach(function(category) {
21+
describe(category.name, function() {
22+
category.tests.forEach(function(testName) {
23+
var suite = describe(testName, function() {});
24+
it("should compile " + testName, function(done) {
25+
var testDirectory = path.join(casesPath, category.name, testName);
26+
var outputDirectory = path.join(__dirname, "js", category.name, testName);
27+
webpack({
28+
context: casesPath,
29+
entry: "./" + category.name + "/" + testName +"/index",
30+
target: "async-node",
31+
devtool: "eval",
32+
output: {
33+
pathinfo: true,
34+
path: outputDirectory,
35+
filename: "bundle.js"
36+
},
37+
module: {
38+
loaders: [
39+
{ test: /\.json$/, loader: "json" },
40+
{ test: /\.coffee$/, loader: "coffee" },
41+
{ test: /\.jade$/, loader: "jade" }
42+
]
43+
}
44+
}, function(err, stats) {
45+
if(err) return done(err);
46+
var jsonStats = stats.toJson();
47+
if(checkArrayExpectation(testDirectory, jsonStats, "error", "Error", done)) return;
48+
if(checkArrayExpectation(testDirectory, jsonStats, "warning", "Warning", done)) return;
49+
var exportedTest = 0;
50+
function _it(title, fn) {
51+
var test = new Test(title, fn);
52+
suite.addTest(test);
53+
exportedTest++;
54+
return test;
55+
}
56+
function _require(module) {
57+
if(module.substr(0, 2) === "./") {
58+
var p = path.join(outputDirectory, module);
59+
var fn = vm.runInThisContext("(function(require, module, exports, __dirname, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
60+
var module = { exports: {} };
61+
fn.call(module.exports, _require, module, module.exports, outputDirectory, _it);
62+
return module.exports;
63+
} else return require(module);
64+
}
65+
_require("./bundle.js");
66+
if(exportedTest === 0) return done(new Error("No tests exported by test case"));
67+
done();
68+
});
69+
});
70+
});
71+
});
72+
});
73+
function checkArrayExpectation(testDirectory, object, kind, upperCaseKind, done) {
74+
var array = object[kind+"s"].slice().sort();
75+
if(fs.existsSync(path.join(testDirectory, kind+ "s.js"))) {
76+
var expected = require(path.join(testDirectory, kind + "s.js"));
77+
if(expected.length < array.length)
78+
return done(new Error("More " + kind + "s while compiling than expected:\n\n" + array.join("\n\n"))), true;
79+
else if(expected.length > array.length)
80+
return done(new Error("Less " + kind + "s while compiling than expected:\n\n" + array.join("\n\n"))), true;
81+
for(var i = 0; i < array.length; i++) {
82+
if(Array.isArray(expected[i])) {
83+
for(var j = 0; j < expected[i].length; j++) {
84+
if(!expected[i][j].test(array[i]))
85+
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i][j].toString())), true;
86+
}
87+
} else if(!expected[i].test(array[i]))
88+
return done(new Error(upperCaseKind + " " + i + ": " + array[i] + " doesn't match " + expected[i].toString())), true;
89+
}
90+
} else if(array.length > 0) {
91+
return done(new Error(upperCaseKind + "s while compiling:\n\n" + array.join("\n\n"))), true;
92+
}
93+
}
94+
});

0 commit comments

Comments
 (0)