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

91 lines
2.6 KiB
JavaScript
Raw Normal View History

// Chunked File library
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();
});
});
sameTick2 = false;
2012-10-26 06:47:51 +08:00
});
2012-10-29 05:44:32 +08:00
sameTick1 = false;
});
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() {
should.exist(tickExtra);
tickExtra.should.be.eql(false);
});
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() {
should.exist(tickEmpty);
tickEmpty.should.be.eql(true);
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() {
should.exist(tickEmpty);
tickEmpty.should.be.eql(true);
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
2012-10-29 05:44:32 +08:00
it("should run empty AMD require", function() {
var emptyRequire = false;
require([], function() {
emptyRequire = true;
});
emptyRequire.should.be.eql(true);
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);
CONST_NUMBER_EXPR.should.be.eql(123);
var o = CONST_OBJECT;
CONST_OBJECT.A.should.be.eql(1);
o.A.should.be.eql(1);
CONST_OBJECT.B.should.be.eql("B");
o.B.should.be.eql("B");
CONST_OBJECT.C().should.be.eql("C");
o.C().should.be.eql("C");
if(CONST_FALSE) require("fail");
if(!CONST_TRUE) require("fail");
if(!CONST_NUMBER) require("fail");
if(!CONST_NUMBER_EXPR) require("fail");
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.ok = true;
2013-02-11 03:37:30 +08:00
// it should not fail if comment in last line