|
| 1 | +var should = require("should"); |
| 2 | + |
| 3 | +it("should parse fancy function calls with arrow functions", function() { |
| 4 | + ("function"==typeof define && define.amd ? |
| 5 | + define : |
| 6 | + (e,t) => {return t()} |
| 7 | + )(["./constructor"], (c) => { |
| 8 | + return new c(1324); |
| 9 | + }); |
| 10 | + module.exports.should.have.property("value").be.eql(1324); |
| 11 | + (("function"==typeof define && define.amd ? |
| 12 | + define : |
| 13 | + (e,t) => {return t()} |
| 14 | + )(["./constructor"], (c) => { |
| 15 | + return new c(4231); |
| 16 | + })); |
| 17 | + module.exports.should.have.property("value").be.eql(4231); |
| 18 | +}); |
| 19 | + |
| 20 | +it("should parse fancy AMD calls with arrow functions", function() { |
| 21 | + require("./constructor ./a".split(" ")); |
| 22 | + require("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), (require, module, exports, constructor, a) => { |
| 23 | + (typeof require).should.be.eql("function"); |
| 24 | + (typeof module).should.be.eql("object"); |
| 25 | + (typeof exports).should.be.eql("object"); |
| 26 | + (typeof require("./constructor")).should.be.eql("function"); |
| 27 | + (typeof constructor).should.be.eql("function"); |
| 28 | + a.should.be.eql("a"); |
| 29 | + }); |
| 30 | + define("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), (require, module, exports, constructor, a) => { |
| 31 | + (typeof require).should.be.eql("function"); |
| 32 | + (typeof module).should.be.eql("object"); |
| 33 | + (typeof exports).should.be.eql("object"); |
| 34 | + (typeof require("./constructor")).should.be.eql("function"); |
| 35 | + (typeof constructor).should.be.eql("function"); |
| 36 | + a.should.be.eql("a"); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +it("should be able to use AMD-style require with arrow functions", function(done) { |
| 41 | + var template = "b"; |
| 42 | + require(["./circular", "./templates/" + template, true ? "./circular" : "fail"], (circular, testTemplate, circular2) => { |
| 43 | + circular.should.be.eql(1); |
| 44 | + circular2.should.be.eql(1); |
| 45 | + testTemplate.should.be.eql("b"); |
| 46 | + done(); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +it("should be able to use require.js-style define with arrow functions", function(done) { |
| 51 | + define("name", ["./circular"], (circular) => { |
| 52 | + circular.should.be.eql(1); |
| 53 | + done(); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +it("should be able to use require.js-style define, optional dependancies, not exist, with arrow function", function(done) { |
| 58 | + define("name", ["./optional"], (optional) => { |
| 59 | + should(optional.b).not.exist; |
| 60 | + done(); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +it("should be able to use require.js-style define, special string, with arrow function", function(done) { |
| 65 | + define(["require"], (require) => { |
| 66 | + require("./circular").should.be.eql(1); |
| 67 | + done(); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +it("should be able to use require.js-style define, without name, with arrow function", function(done) { |
| 72 | + true && define(["./circular"], (circular) => { |
| 73 | + circular.should.be.eql(1); |
| 74 | + done(); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +it("should be able to use require.js-style define, with empty dependencies, with arrow function", function(done) { |
| 79 | + define("name", [], () => { |
| 80 | + done(); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +it("should be able to use require.js-style define, without dependencies, with arrow function", function(done) { |
| 85 | + true && define("name", () => { |
| 86 | + done(); |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +it("should offer AMD-style define for CommonJs with arrow function", function(done) { |
| 91 | + var _test_exports = exports; |
| 92 | + var _test_module = module; |
| 93 | + define((require, exports, module) => { |
| 94 | + (typeof require).should.be.eql("function"); |
| 95 | + exports.should.be.equal(_test_exports); |
| 96 | + module.should.be.equal(_test_module); |
| 97 | + require("./circular").should.be.eql(1); |
| 98 | + done(); |
| 99 | + }); |
| 100 | +}); |
| 101 | + |
| 102 | +it("should pull in all dependencies of an AMD module with arrow function", function(done) { |
| 103 | + define((require) => { |
| 104 | + require("./amdmodule").should.be.eql("a"); |
| 105 | + done(); |
| 106 | + }); |
| 107 | +}); |
| 108 | + |
| 109 | +it("should create a chunk for require.js require, with arrow function", function(done) { |
| 110 | + var sameTick = true; |
| 111 | + require(["./c"], (c) => { |
| 112 | + sameTick.should.be.eql(false); |
| 113 | + c.should.be.eql("c"); |
| 114 | + require("./d").should.be.eql("d"); |
| 115 | + done(); |
| 116 | + }); |
| 117 | + sameTick = false; |
| 118 | +}); |
0 commit comments