{:uriI"Èfile:///Users/izik/www/sparse/izi_lightup/spec/javascripts/crit-utils/mini_require_spec.js?type=application/javascript&pipeline=self&id=f87adbd209ba21d460f6192daf494f0b10a023ff7e041dcc39ee95172a78fc32:ET:load_pathI"8/Users/izik/www/sparse/izi_lightup/spec/javascripts;T: filenameI"X/Users/izik/www/sparse/izi_lightup/spec/javascripts/crit-utils/mini_require_spec.js;T: nameI"!crit-utils/mini_require_spec;T:logical_pathI")crit-utils/mini_require_spec.self.js;T:content_typeI"application/javascript;T: sourceI"@ describe("miniRequire", function () { function $$clean() { for (var key in window.__required) { if (__required[key].node) __required[key].node.remove(); delete(__required[key]); } } afterEach(function () { $$clean(); }); it("should exists as global function", function () { expect(miniRequire).toBeDefined(); expect(typeof miniRequire).toBe("function"); }); it("should inject new script", function () { var cnt = document.scripts.length; miniRequire("todo", "/assets/application.js"); expect(document.scripts.length - cnt).toBe(1); }); it("should inject only one script tag", function () { var cnt = document.scripts.length; miniRequire("todo", "/assets/application.js"); miniRequire("todo", "/assets/application.js"); miniRequire("todo", "/assets/application.js"); expect(document.scripts.length - cnt).toBe(1); }); it("should return subscription", function () { var sub = miniRequire("todo", "/assets/application.js"); expect(sub).toBePresent(); expect(sub.started).toBeTruthy(); expect(sub.loaded).toBeFalsy(); expect(sub.node).toBeDefined(); }); it("should call callback once script loaded", function () { return new Promise(function (resolve) { delete window["APPLICATION_JS"]; var sub = miniRequire("todo", "/assets/application.js", function () { expect(sub.started).toBeTruthy(); expect(sub.loaded).toBeTruthy(); expect(window["APPLICATION_JS"]).toBe("TODO"); resolve(); }); }); }); it("should add subscription only if no src provided", function () { return new Promise(function (resolve) { delete window["APPLICATION_JS"]; var cnt = document.scripts.length; // add subscription miniRequire("todo", undefined, function () { expect(window["APPLICATION_JS"]).toBe("TODO"); resolve(); }); expect(document.scripts.length - cnt).toBe(0); // and require script later setTimeout(function () { miniRequire("todo", "/assets/application.js"); expect(document.scripts.length - cnt).toBe(1); }, 10); }); }); it("should immediate resolve on loaded", function () { return new Promise(function (resolve) { var loaded1, loaded2; miniRequire("todo", "/assets/application.js", function () { expect(window["APPLICATION_JS"]).toBe("TODO"); loaded1 = (new Date()).getTime(); miniRequire("todo", "/assets/application.js", function () { loaded2 = (new Date()).getTime(); expect(loaded2 - loaded1).toBe(0); }); resolve(); }); }); }); }); describe("miniPreload", function () { it("should exists as global function", function () { expect(miniPreload).toBeDefined(); expect(typeof miniPreload).toBe("function"); }); }); ;T: metadata{ :dependencieso:Set: @hash} I"environment-version;TTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"ffile-digest:///Users/izik/www/sparse/izi_lightup/spec/javascripts/crit-utils/mini_require_spec.js;TTF: requiredo;;}F: stubbedo;;}F: linkso;;}F: charsetI" utf-8;F: digest"%§0€3顨ё¡¤¯¹«f{NÓää»”Ÿ­[9ë&€^: lengthi@ :dependencies_digest"%ðõU%¥ØõÏÚ³’â—ã€!øC0K‰UË Ý¾G:idI"Ef87adbd209ba21d460f6192daf494f0b10a023ff7e041dcc39ee95172a78fc32;F: mtimel+™]b