2020-09-11 13:53:56 -04:00
|
|
|
import { loadScript, cacheBuster } from "discourse/lib/load-script";
|
|
|
|
import { PUBLIC_JS_VERSIONS as jsVersions } from "discourse/lib/public-js-versions";
|
2018-09-30 22:06:01 -04:00
|
|
|
|
|
|
|
QUnit.module("lib:load-script");
|
|
|
|
|
2019-06-27 04:57:40 -04:00
|
|
|
QUnit.skip(
|
2018-09-30 22:06:01 -04:00
|
|
|
"load with a script tag, and callbacks are only executed after script is loaded",
|
|
|
|
async (assert) => {
|
2019-06-27 04:19:55 -04:00
|
|
|
assert.ok(
|
|
|
|
typeof window.ace === "undefined",
|
|
|
|
"ensures ace is not previously loaded"
|
|
|
|
);
|
|
|
|
|
2018-09-30 22:06:01 -04:00
|
|
|
const src = "/javascripts/ace/ace.js";
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
await loadScript(src);
|
|
|
|
assert.ok(
|
|
|
|
typeof window.ace !== "undefined",
|
|
|
|
"callbacks should only be executed after the script has fully loaded"
|
|
|
|
);
|
2018-09-30 22:06:01 -04:00
|
|
|
}
|
|
|
|
);
|
2020-09-11 13:53:56 -04:00
|
|
|
|
|
|
|
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"),
|
2020-09-21 15:06:56 -04:00
|
|
|
`/javascripts/${jsVersions["pikaday.js"]}`
|
2020-09-11 13:53:56 -04:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
cacheBuster("/javascripts/ace/ace.js"),
|
2020-09-21 15:06:56 -04:00
|
|
|
`/javascripts/${jsVersions["ace/ace.js"]}`
|
2020-09-11 13:53:56 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|