2013-12-16 06:10:41 +08:00
|
|
|
it("should parse fancy function calls", function() {
|
|
|
|
("function"==typeof define && define.amd ?
|
|
|
|
define :
|
|
|
|
function(e,t){return t()}
|
|
|
|
)(["./constructor"], function(c) {
|
|
|
|
return new c(1324);
|
|
|
|
});
|
|
|
|
module.exports.should.have.property("value").be.eql(1324);
|
|
|
|
(("function"==typeof define && define.amd ?
|
|
|
|
define :
|
|
|
|
function(e,t){return t()}
|
|
|
|
)(["./constructor"], function(c) {
|
|
|
|
return new c(4231);
|
|
|
|
}));
|
|
|
|
module.exports.should.have.property("value").be.eql(4231);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse fancy AMD calls", function() {
|
|
|
|
require("./constructor ./a".split(" "));
|
|
|
|
require("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), function(require, module, exports, constructor, a) {
|
2014-01-24 19:22:59 +08:00
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
(typeof module).should.be.eql("object");
|
|
|
|
(typeof exports).should.be.eql("object");
|
2014-03-13 06:03:07 +08:00
|
|
|
(typeof require("./constructor")).should.be.eql("function");
|
2014-01-24 19:22:59 +08:00
|
|
|
(typeof constructor).should.be.eql("function");
|
|
|
|
a.should.be.eql("a");
|
|
|
|
});
|
|
|
|
define("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), function(require, module, exports, constructor, a) {
|
2013-12-16 06:10:41 +08:00
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
(typeof module).should.be.eql("object");
|
|
|
|
(typeof exports).should.be.eql("object");
|
2014-03-13 06:03:07 +08:00
|
|
|
(typeof require("./constructor")).should.be.eql("function");
|
2013-12-16 06:10:41 +08:00
|
|
|
(typeof constructor).should.be.eql("function");
|
|
|
|
a.should.be.eql("a");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to use AMD-style require", function(done) {
|
|
|
|
var template = "b";
|
|
|
|
require(["./circular", "./templates/" + template, true ? "./circular" : "fail"], function(circular, testTemplate, circular2) {
|
|
|
|
circular.should.be.eql(1);
|
|
|
|
circular2.should.be.eql(1);
|
|
|
|
testTemplate.should.be.eql("b");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use require.js-style define", function(done) {
|
|
|
|
define("name", ["./circular"], function(circular) {
|
|
|
|
circular.should.be.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2014-03-13 06:03:07 +08:00
|
|
|
it("should be able to use require.js-style define, special string", function(done) {
|
|
|
|
define(["require"], function(require) {
|
|
|
|
require("./circular").should.be.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use require.js-style define, without name", function(done) {
|
|
|
|
true && define(["./circular"], function(circular) {
|
|
|
|
circular.should.be.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use require.js-style define, with empty dependencies", function(done) {
|
|
|
|
define("name", [], function() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
|
|
|
it("should be able to use require.js-style define, with empty dependencies, with a expression", function(done) {
|
2013-12-29 19:21:14 +08:00
|
|
|
define([], ok);
|
|
|
|
function ok() { done() };
|
2013-12-29 19:11:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to use require.js-style define, with empty dependencies, with a expression and name", function(done) {
|
|
|
|
define("name", [], done);
|
|
|
|
});
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use require.js-style define, without dependencies", function(done) {
|
|
|
|
true && define("name", function() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
|
|
|
it("should be able to use require.js-style define, without dependencies, with a expression", function(done) {
|
2013-12-29 19:21:14 +08:00
|
|
|
true && define("name", ok);
|
|
|
|
function ok() { done() };
|
2013-12-29 19:11:03 +08:00
|
|
|
});
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
var obj = {};
|
|
|
|
it("should be able to use require.js-style define, with an object", function() {
|
2013-12-29 19:11:03 +08:00
|
|
|
module.exports = null;
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
true && define("blaaa", obj);
|
2013-12-29 19:11:03 +08:00
|
|
|
|
|
|
|
module.exports.should.be.equal(obj);
|
|
|
|
module.exports = null;
|
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
define("blaaa", obj);
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
module.exports.should.be.equal(obj);
|
2013-12-29 19:11:03 +08:00
|
|
|
module.exports = null;
|
2013-12-16 06:10:41 +08:00
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should offer AMD-style define for CommonJs", function(done) {
|
|
|
|
var _test_exports = exports;
|
|
|
|
var _test_module = module;
|
|
|
|
define(function(require, exports, module) {
|
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
exports.should.be.equal(_test_exports);
|
|
|
|
module.should.be.equal(_test_module);
|
|
|
|
require("./circular").should.be.eql(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should not crash on require.js require only with array", function() {
|
|
|
|
require(["./circular"]);
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use AMD require without function expression (empty array)", function(done) {
|
2013-12-29 19:21:14 +08:00
|
|
|
require([], ok);
|
|
|
|
function ok() { done() };
|
2013-12-16 06:10:41 +08:00
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should be able to use AMD require without function expression", function(done) {
|
|
|
|
require(["./circular"], fn);
|
|
|
|
function fn(c) {
|
|
|
|
c.should.be.eql(1);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
2013-12-16 06:10:41 +08:00
|
|
|
it("should create a chunk for require.js require", function(done) {
|
|
|
|
var sameTick = true;
|
|
|
|
require(["./c"], function(c) {
|
|
|
|
sameTick.should.be.eql(false);
|
|
|
|
c.should.be.eql("c");
|
|
|
|
require("./d").should.be.eql("d");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
sameTick = false;
|
|
|
|
});
|
2013-12-29 19:11:03 +08:00
|
|
|
|
|
|
|
it("should not fail #138", function(done) {
|
|
|
|
(function (factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define([], factory); // AMD
|
|
|
|
} else if (typeof exports === 'object') {
|
|
|
|
module.exports = factory(); // Node
|
|
|
|
} else {
|
|
|
|
factory(); // Browser global
|
|
|
|
}
|
|
|
|
}(function () { done() }));
|
|
|
|
});
|
2013-12-29 19:21:14 +08:00
|
|
|
|
|
|
|
it("should parse a bound function expression 1", function(done) {
|
|
|
|
define(function(a, require, exports, module) {
|
|
|
|
a.should.be.eql(123);
|
2013-12-31 19:20:06 +08:00
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
require("./a").should.be.eql("a");
|
2013-12-29 19:21:14 +08:00
|
|
|
done();
|
|
|
|
}.bind(null, 123));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse a bound function expression 2", function(done) {
|
|
|
|
define("name", function(a, require, exports, module) {
|
|
|
|
a.should.be.eql(123);
|
2013-12-31 19:20:06 +08:00
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
require("./a").should.be.eql("a");
|
2013-12-29 19:21:14 +08:00
|
|
|
done();
|
|
|
|
}.bind(null, 123));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse a bound function expression 3", function(done) {
|
|
|
|
define(["./a"], function(number, a) {
|
|
|
|
number.should.be.eql(123);
|
|
|
|
a.should.be.eql("a");
|
|
|
|
done();
|
|
|
|
}.bind(null, 123));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse a bound function expression 4", function(done) {
|
|
|
|
define("name", ["./a"], function(number, a) {
|
|
|
|
number.should.be.eql(123);
|
|
|
|
a.should.be.eql("a");
|
|
|
|
done();
|
|
|
|
}.bind(null, 123));
|
|
|
|
});
|
2013-12-31 19:23:58 +08:00
|
|
|
|
|
|
|
it("should not fail issue #138 second", function() {
|
|
|
|
(function(define, global) { 'use strict';
|
|
|
|
define(function (require) {
|
|
|
|
(typeof require).should.be.eql("function");
|
|
|
|
require("./a").should.be.eql("a");
|
|
|
|
return "#138 2.";
|
|
|
|
});
|
|
|
|
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }, this);
|
|
|
|
module.exports.should.be.eql("#138 2.");
|
|
|
|
});
|