{:uriI"file:///Users/izik/www/sparse/izi_lightup/spec/javascripts/crit-utils/mini_require_spec.js?type=application/javascript&pipeline=self&id=1c97b63bf08d1d27db8c581ad8131eb7ce3d1c117e1d711bf6ea9a43895a5255: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"W 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 resolve at minium time if already 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).toBeLessThan(100); }); 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"%?,w:#:wz,o: lengthiW :dependencies_digest"%D.[ fFXlm|mHhK:idI"E1c97b63bf08d1d27db8c581ad8131eb7ce3d1c117e1d711bf6ea9a43895a5255;F: mtimel+@]b