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

110 lines
3.1 KiB
JavaScript
Raw Normal View History

// Chunked File library
var library2commonValue = library2common;
describe("library2", function() {
2012-10-29 05:44:32 +08:00
var tickExtra, tickEmpty, tickMerged;
var extraValue, testValue;
2018-01-31 04:03:23 +08:00
beforeAll(function(done) {
2012-10-29 05:44:32 +08:00
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();
});
});
2016-02-04 21:29:51 +08:00
Promise.resolve().then(function() {}).then(function() {}).then(function() {
2015-07-07 06:11:13 +08:00
sameTick2 = false;
});
});
2016-02-04 21:29:51 +08:00
Promise.resolve().then(function() {}).then(function() {}).then(function() {
2015-07-07 06:11:13 +08:00
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
it("should run after common", function() {
2018-01-24 23:00:43 +08:00
expect(library2commonValue).toEqual({ok2: true});
});
2012-10-29 05:44:32 +08:00
it("should load stuff with require.ensure asynchron", function() {
2018-01-24 23:00:43 +08:00
expect(tickExtra).toBe(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() {
2018-01-24 23:00:43 +08:00
expect(tickEmpty).toBe(true);
expect(extraValue).toBe("Lib2 extra2 with post loader");
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 merge chunks if maxChunks specified", function() {
2018-01-24 23:00:43 +08:00
expect(tickEmpty).toBe(true);
expect(testValue).toBe("test module");
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 require.amd from options", function() {
2018-01-24 23:00:43 +08:00
expect(require.amd.fromOptions).toBe(true);
2012-10-29 05:44:32 +08:00
});
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;
});
2016-02-04 21:29:51 +08:00
Promise.resolve().then(function() {}).then(function() {}).then(function() {
2018-01-24 23:00:43 +08:00
expect(emptyRequire).toBe(true);
2015-07-07 06:11:13 +08:00
done();
});
2012-03-10 20:11:23 +08:00
});
2013-02-11 03:37:30 +08:00
it("should provide free variables", function() {
2018-01-24 23:00:43 +08:00
expect(s3()).toBe("submodule3");
2013-02-11 03:37:30 +08:00
});
2013-09-24 21:23:05 +08:00
it("should define values", function() {
2018-01-24 23:00:43 +08:00
expect(CONST_UNDEFINED === undefined).toBe(true);
expect(CONST_NULL === null).toBe(true);
expect(CONST_TRUE).toBe(true);
expect(CONST_FALSE).toBe(false);
expect(CONST_FUNCTION()).toBe("ok");
expect(CONST_NUMBER).toBe(123);
expect(CONST_NUMBER_EXPR).toBe(123);
expect(typeof CONST_TYPEOF).toBe("typeof");
2013-09-24 21:23:05 +08:00
var o = CONST_OBJECT;
2018-01-24 23:00:43 +08:00
expect(CONST_OBJECT.A).toBe(1);
expect(CONST_OBJECT.B).toBe("B");
expect(CONST_OBJECT.C()).toBe("C");
expect(o.A).toBe(1);
expect(o.B).toBe("B");
expect(o.C()).toBe("C");
2014-01-31 21:09:08 +08:00
(function(o) {
2018-01-24 23:00:43 +08:00
expect(o.A).toBe(1);
expect(o.B).toBe("B");
expect(o.C()).toBe("C");
2014-01-31 21:09:08 +08:00
}(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
2018-01-24 23:00:43 +08:00
// it should not fail if comment in last line