This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/lib/load-script-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

44 lines
1.2 KiB
JavaScript

import { skip } from "qunit";
import { test, module } from "qunit";
import { loadScript, cacheBuster } from "discourse/lib/load-script";
import { PUBLIC_JS_VERSIONS as jsVersions } from "discourse/lib/public-js-versions";
module("lib:load-script");
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"
);
});
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"
);
});
test("generates URLs with version number in the query params", (assert) => {
assert.equal(
cacheBuster("/javascripts/pikaday.js"),
`/javascripts/${jsVersions["pikaday.js"]}`
);
assert.equal(
cacheBuster("/javascripts/ace/ace.js"),
`/javascripts/${jsVersions["ace/ace.js"]}`
);
});