When `EMBER_CLI_PLUGIN_ASSETS=1`, plugin application JS will be compiled via Ember CLI. In this mode, the existing `register_asset` API will cause any registered JS files to be made available in `/plugins/{plugin-name}_extra.js`. These 'extra' files will be loaded immediately after the plugin app JS file, so this should not affect functionality.
Plugin compilation in Ember CLI is implemented as an addon, similar to the existing 'admin' addon. We bypass the normal Ember CLI compilation process (which would add the JS to the main app bundle), and reroute the addon Broccoli tree into a separate JS file per-plugin. Previously, Sprockets would add compiled templates directly to `Ember.TEMPLATES`. Under Ember CLI, they are compiled into es6 modules. Some new logic in `discourse-boot.js` takes care of remapping the new module names into the old-style `Ember.TEMPLATES`.
This change has been designed to be a like-for-like replacement of the old plugin compilation system, so we do not expect any breakage. Even so, the environment variable flag will allow us to test this in a range of environments before enabling it by default.
A manual silence implementation is added for the build-time `ember-glimmer.link-to.positional-arguments` deprecation while we work on a better story for plugins.
61 lines
1.8 KiB
JavaScript
61 lines
1.8 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/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;
|