webpack/test/browsertest/node_modules/library2/lib/main.js

103 lines
2.9 KiB
JavaScript
Raw Normal View History

// Chunked File library
2013-10-16 04:33:11 +08:00
var should = require("should");
describe("library2", function() {
2012-10-29 05:44:32 +08:00
var tickExtra, tickEmpty, tickMerged;
var extraValue, testValue;
before(function(done) {
var asnycOk = false, asnycOk2 = false;
var sameTick1 = true;
2013-01-31 01:49:25 +08:00
require.ensure(["./extra"], function(require) {
2012-10-29 05:44:32 +08:00
asnycOk = true;
tickExtra = sameTick1;
var sameTick2 = true;
require.ensure([], function(require) {
asnycOk2 = true;
extraValue = require("./extra");
tickEmpty = sameTick2;
require.ensure(["./test.js"], function(require) {
tickMerged = sameTick2;
testValue = require("./test.js");
done();
});
});
2015-07-07 06:11:13 +08:00
setImmediate(function() {
sameTick2 = false;
});
});
setImmediate(function() {
sameTick1 = false;
2012-10-26 06:47:51 +08:00
});
2012-10-29 05:44:32 +08:00
});
2013-02-11 03:37:30 +08:00
2012-10-29 05:44:32 +08:00
it("should load stuff with require.ensure asynchron", function() {
2013-10-16 04:33:11 +08:00
should.strictEqual(tickExtra, false);
2012-10-29 05:44:32 +08:00
});
2013-02-11 03:37:30 +08:00
2012-10-29 05:44:32 +08:00
it("should load not include stuff from parent, remove empty chunks and apply a post loader", function() {
2013-10-16 04:33:11 +08:00
should.strictEqual(tickEmpty, true);
2012-10-29 05:44:32 +08:00
extraValue.should.be.eql("Lib2 extra2 with post loader");
});
2013-02-11 03:37:30 +08:00
2012-10-29 05:44:32 +08:00
it("should merge chunks if maxChunks specified", function() {
2013-10-16 04:33:11 +08:00
should.strictEqual(tickEmpty, true);
2012-10-29 05:44:32 +08:00
testValue.should.be.eql("test module");
});
2013-02-11 03:37:30 +08:00
2012-10-29 05:44:32 +08:00
it("should load require.amd from options", function() {
require.amd.should.have.property("fromOptions").be.eql(true);
});
2013-02-11 03:37:30 +08:00
2015-07-07 06:11:13 +08:00
it("should run empty AMD require", function(done) {
2012-10-29 05:44:32 +08:00
var emptyRequire = false;
require([], function() {
emptyRequire = true;
});
2015-07-07 06:11:13 +08:00
process.nextTick(function() {
emptyRequire.should.be.eql(true);
done();
});
2012-03-10 20:11:23 +08:00
});
2013-02-11 03:37:30 +08:00
it("should provide free variables", function() {
s3().should.be.eql("submodule3");
});
2013-09-24 21:23:05 +08:00
it("should define values", function() {
2013-10-15 04:21:23 +08:00
(CONST_UNDEFINED === undefined).should.be.eql(true);
(CONST_NULL === null).should.be.eql(true);
2013-09-24 21:23:05 +08:00
CONST_TRUE.should.be.eql(true);
CONST_FALSE.should.be.eql(false);
(CONST_FUNCTION()).should.be.eql("ok");
(CONST_NUMBER).should.be.eql(123);
2013-09-24 21:23:05 +08:00
CONST_NUMBER_EXPR.should.be.eql(123);
(typeof CONST_TYPEOF).should.be.eql("typeof");
2013-09-24 21:23:05 +08:00
var o = CONST_OBJECT;
(CONST_OBJECT.A).should.be.eql(1);
2013-09-24 21:23:05 +08:00
CONST_OBJECT.B.should.be.eql("B");
CONST_OBJECT.C().should.be.eql("C");
2014-01-31 21:09:08 +08:00
o.A.should.be.eql(1);
o.B.should.be.eql("B");
2013-09-24 21:23:05 +08:00
o.C().should.be.eql("C");
2014-01-31 21:09:08 +08:00
(function(o) {
o.A.should.be.eql(1);
o.B.should.be.eql("B");
o.C().should.be.eql("C");
}(CONST_OBJECT));
2013-09-24 21:23:05 +08:00
if(CONST_FALSE) require("fail");
if(!CONST_TRUE) require("fail");
if(!CONST_NUMBER) require("fail");
if(!CONST_NUMBER_EXPR) require("fail");
if(typeof CONST_TYPEOF !== "typeof") require("fail");
2013-09-24 21:23:05 +08:00
if(typeof CONST_FALSE !== "boolean") require("fail");
if(typeof CONST_FUNCTION !== "function") require("fail");
if(typeof CONST_OBJECT !== "object") require("fail");
if(!CONST_OBJECT.A) require("fail");
if(typeof CONST_OBJECT.A !== "number") require("fail");
});
2012-03-10 20:11:23 +08:00
});
exports.library2 = {ok: true};
2013-02-11 03:37:30 +08:00
2015-07-07 06:11:13 +08:00
// it should not fail if comment in last line