2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-09 12:21:04 +08:00
discourse/test/javascripts/lib/load-script-test.js
jbrw 033cebf978
DEV - versions of JS files written to a JS file to be included by loa… (#10649)
* DEV - versions of JS files written to a JS file to be included by load-script and appended as params to URLs

* Formatting

* Incorporate feedback from PR

* Update filename of public-js-versions
2020-09-11 13:53:56 -04:00

47 lines
1.2 KiB
JavaScript

import { loadScript, cacheBuster } from "discourse/lib/load-script";
import { PUBLIC_JS_VERSIONS as jsVersions } from "discourse/lib/public-js-versions";
QUnit.module("lib:load-script");
QUnit.skip(
"load with a script tag, and callbacks are only executed after script is loaded",
async (assert) => {
assert.ok(
typeof window.ace === "undefined",
"ensures ace is not previously loaded"
);
const src = "/javascripts/ace/ace.js";
await loadScript(src);
assert.ok(
typeof window.ace !== "undefined",
"callbacks should only be executed after the script has fully loaded"
);
}
);
QUnit.test("works when a value is not present", (assert) => {
assert.equal(
cacheBuster("/javascripts/my-script.js"),
"/javascripts/my-script.js"
);
assert.equal(
cacheBuster("/javascripts/my-project/script.js"),
"/javascripts/my-project/script.js"
);
});
QUnit.test(
"generates URLs with version number in the query params",
(assert) => {
assert.equal(
cacheBuster("/javascripts/pikaday.js"),
`/javascripts/pikaday.js?v=${jsVersions["pikaday.js"]}`
);
assert.equal(
cacheBuster("/javascripts/ace/ace.js"),
`/javascripts/ace/ace.js?v=${jsVersions["ace"]}`
);
}
);