mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 00:42:46 +08:00
![David Taylor](/assets/img/avatar_default.png)
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.
68 lines
2.0 KiB
JavaScript
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;
|