discourse/app/assets/javascripts/discourse/tests/test-boot-ember-cli.js
David Taylor 3b1a46ff37
DEV: Skip loading plugin JS when running only core tests (#18047)
Plugins often change core behavior, and thereby cause core's tests to fail. In CI, we work around this problem by running core CI without any plugins loaded.

In development, the only option to safely run the core tests is to uninstall all plugins, which is clearly a bad developer experience. This commit aims to improve that experience.

The `qunit_skip_plugins=1` flag would previously prevent the plugin **tests** from running. This commit extends that flag to also affect the plugin's application JS.
2022-08-23 10:25:07 +01:00

68 lines
2.0 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", () => {
// eslint-disable-next-line no-undef
if (!EmberENV.TESTS_FILE_LOADED) {
throw new Error(
'The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js".'
);
}
const script = document.getElementById("plugin-test-script");
if (script && !requirejs.entries["discourse/tests/plugin-tests"]) {
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 (QUnit.config.seed === undefined) {
// If we're running in browser, default to random order. Otherwise, let Ember Exam
// handle randomization.
QUnit.config.seed = Math.random().toString(36).slice(2);
} else {
// Don't reorder when specifying a seed
QUnit.config.reorder = false;
}
loader.loadModules();
start({
setupTestContainer: false,
loadTests: false,
startTests: !disableAutoStart,
setupEmberOnerrorValidation: !skipCore,
});
});
window.EmberENV.TESTS_FILE_LOADED = true;