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/test-boot-ember-cli.js
Jarek Radosz 6555f0c11b
DEV: Support qunit_disable_auto_start in ember CLI (#16358)
Required for e.g. `test/run-qunit.js`
2022-04-02 21:15:50 +02:00

57 lines
1.7 KiB
JavaScript

import config from "../config/environment";
import { setEnvironment } from "discourse-common/config/environment";
import { start } from "ember-qunit";
import loadEmberExam from "ember-exam/test-support/load";
import * as QUnit from "qunit";
import { setup } from "qunit-dom";
setEnvironment("testing");
document.addEventListener("discourse-booted", () => {
const script = document.getElementById("plugin-test-script");
if (script && !requirejs.entries["discourse/tests/active-plugins"]) {
throw new Error(
`Plugin JS payload failed to load from ${script.src}. Is the Rails server running?`
);
}
let setupTests = require("discourse/tests/setup-tests").default;
const params = new URLSearchParams(window.location.search);
const skipCore = params.get("qunit_skip_core") === "1";
const disableAutoStart = params.get("qunit_disable_auto_start") === "1";
// eslint-disable-next-line no-undef
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
document.body.insertAdjacentHTML(
"afterbegin",
`
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="ember-testing-container" style="position: fixed">
<div id="ember-testing"></div>
</div>
`
);
setup(QUnit.assert);
setupTests(config.APP);
let loader = loadEmberExam();
if (loader.urlParams.size === 0 && !QUnit.config.seed) {
// If we're running in browser, default to random order. Otherwise, let Ember Exam
// handle randomization.
QUnit.config.seed = true;
}
loader.loadModules();
start({
setupTestContainer: false,
loadTests: false,
startTests: !disableAutoStart,
setupEmberOnerrorValidation: !skipCore,
});
});
window.EmberENV.TESTS_FILE_LOADED = true;