2013-04-02 15:14:19 +08:00
|
|
|
// Should not break it...
|
|
|
|
|
if(typeof require !== "function")
|
|
|
|
|
var require = require("amdrequire");
|
|
|
|
|
if(typeof define != "function")
|
|
|
|
|
var define = require("amdefine");
|
2012-03-21 19:41:03 +08:00
|
|
|
|
2012-10-29 05:44:32 +08:00
|
|
|
function test(cond, message) {
|
|
|
|
|
if(!cond) throw new Error(message);
|
2012-03-14 23:33:46 +08:00
|
|
|
}
|
2012-10-29 05:44:32 +08:00
|
|
|
|
2012-11-06 00:38:57 +08:00
|
|
|
// load tests from library1, with script loader
|
|
|
|
|
require("script!../js/library1.js");
|
2012-10-29 05:44:32 +08:00
|
|
|
|
|
|
|
|
// Buildin 'style' loader adds css to document
|
2013-12-16 06:10:41 +08:00
|
|
|
require("./stylesheet.css");
|
|
|
|
|
require("./stylesheet.less");
|
2012-10-29 05:44:32 +08:00
|
|
|
|
2013-10-16 04:33:11 +08:00
|
|
|
var should = require("should");
|
2013-12-16 06:10:41 +08:00
|
|
|
if(!should.exist) should.exist = function(x) { should.strictEqual(x === undefined, false); should.strictEqual(x === null, false); }
|
2012-10-29 05:44:32 +08:00
|
|
|
|
|
|
|
|
describe("main", function() {
|
2012-11-06 00:38:57 +08:00
|
|
|
it("should load library1 with script-loader", function() {
|
|
|
|
|
should.exist(window.library1);
|
|
|
|
|
window.library1.should.be.eql(true);
|
2012-03-15 21:38:55 +08:00
|
|
|
});
|
2012-10-29 05:44:32 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
it("should load library2 exported as global", function() {
|
2015-07-25 21:00:05 +08:00
|
|
|
should.exist(window.library2common);
|
|
|
|
|
should.exist(window.library2common.ok2);
|
|
|
|
|
window.library2common.ok2.should.be.eql(true);
|
2012-11-06 00:38:57 +08:00
|
|
|
should.exist(window.library2);
|
|
|
|
|
should.exist(window.library2.ok);
|
|
|
|
|
window.library2.ok.should.be.eql(true);
|
2012-03-15 21:38:55 +08:00
|
|
|
});
|
2013-12-16 06:10:41 +08:00
|
|
|
|
|
|
|
|
describe("web resolving", function() {
|
2012-10-29 05:44:32 +08:00
|
|
|
it("should load index.web.js instead of index.js", function() {
|
|
|
|
|
true.should.be.eql(true);
|
|
|
|
|
});
|
2012-04-03 22:26:08 +08:00
|
|
|
|
2012-10-29 05:44:32 +08:00
|
|
|
it("should load correct replacements for files", function(done) {
|
|
|
|
|
require.ensure(["subcontent"], function(require) {
|
|
|
|
|
// Comments work!
|
|
|
|
|
exports.ok = true;
|
|
|
|
|
test(require("subcontent") === "replaced", "node_modules should be replaced with web_modules");
|
|
|
|
|
test(require("subcontent2/file.js") === "orginal", "node_modules should still work when web_modules exists");
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
|
should.exist(exports.ok);
|
|
|
|
|
exports.ok.should.be.eql(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2012-08-08 02:52:48 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
describe("web runtime", function() {
|
2013-02-13 21:57:00 +08:00
|
|
|
it("should have support for require.main", function() {
|
|
|
|
|
var value = require.main === module;
|
|
|
|
|
var otherModuleValue = require("./testRequireMain");
|
|
|
|
|
value.should.be.eql(true);
|
|
|
|
|
otherModuleValue.should.be.eql(false);
|
|
|
|
|
});
|
2012-10-29 05:44:32 +08:00
|
|
|
});
|
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
describe("web polyfilling", function() {
|
2012-10-29 05:44:32 +08:00
|
|
|
var sum2;
|
|
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
|
sum2 = 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should polyfill process and module", function(done) {
|
2013-10-16 04:33:11 +08:00
|
|
|
module.id.should.have.type("number");
|
2012-10-29 05:44:32 +08:00
|
|
|
require.ensure([], function(require) {
|
2013-02-25 18:34:33 +08:00
|
|
|
test(Array.isArray(process.argv), "process.argv should be an array");
|
2012-10-29 05:44:32 +08:00
|
|
|
process.nextTick(function() {
|
|
|
|
|
sum2++;
|
2012-10-29 06:12:17 +08:00
|
|
|
sum2.should.be.eql(2);
|
|
|
|
|
done();
|
2012-10-29 05:44:32 +08:00
|
|
|
});
|
2014-03-19 05:34:35 +08:00
|
|
|
sum2++;
|
2012-10-29 05:44:32 +08:00
|
|
|
test(global === window, "global === window");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
describe("web loaders", function() {
|
|
|
|
|
it("should handle the file loader correctly", function() {
|
|
|
|
|
require("!file!../img/image.png").should.match(/js\/.+\.png$/);
|
|
|
|
|
document.getElementById("image").src = require("file?prefix=img/!../img/image.png");
|
2013-06-12 22:16:06 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-24 18:20:51 +08:00
|
|
|
describe("chunk error handling", function() {
|
|
|
|
|
it("should be able to handle chunk loading errors and try again", function(done) {
|
|
|
|
|
var old = __webpack_public_path__;
|
|
|
|
|
__webpack_public_path__ += "wrong/";
|
|
|
|
|
System.import("./three").then(function() {
|
|
|
|
|
done(new Error("Chunk shouldn't be loaded"));
|
|
|
|
|
}).catch(function(err) {
|
|
|
|
|
err.should.be.instanceOf(Error);
|
|
|
|
|
__webpack_public_path__ = old;
|
|
|
|
|
System.import("./three").then(function(three) {
|
|
|
|
|
three.should.be.eql(3);
|
|
|
|
|
done();
|
|
|
|
|
}).catch(function(err) {
|
|
|
|
|
done(new Error("Shouldn't result in an chunk loading error"));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-24 17:38:00 +08:00
|
|
|
var testCasesContext = require.context("../../cases", true, /^\.\/[^\/_]+\/[^\/_]+\/index$/);
|
|
|
|
|
var testCasesMap = testCasesContext.keys().map(function(key) {
|
|
|
|
|
return key.substring(2, key.length - "/index".length).split("/");
|
|
|
|
|
}).reduce(function(map, x) {
|
|
|
|
|
if(!map[x[0]]) map[x[0]] = [x[1]];
|
|
|
|
|
else map[x[0]].push(x[1]);
|
|
|
|
|
return map;
|
|
|
|
|
}, {});
|
|
|
|
|
Object.keys(testCasesMap).forEach(function(category) {
|
|
|
|
|
describe(category, function() {
|
|
|
|
|
testCasesMap[category].forEach(function(name) {
|
|
|
|
|
describe(name, function() {
|
|
|
|
|
testCasesContext("./" + category + "/" + name + "/index");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2012-10-29 05:44:32 +08:00
|
|
|
});
|
2013-06-20 04:31:12 +08:00
|
|
|
|
|
|
|
|
if(module.hot) {
|
|
|
|
|
module.hot.accept();
|
|
|
|
|
module.hot.dispose(function() {
|
|
|
|
|
mocha.suite.suites.length = 0;
|
|
|
|
|
var stats = document.getElementById("stats");
|
|
|
|
|
stats.parentNode.removeChild(stats);
|
|
|
|
|
});
|
|
|
|
|
if(module.data) {
|
|
|
|
|
mocha.run();
|
|
|
|
|
}
|
|
|
|
|
}
|