mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
ember-qunit no longer uses ember-cli-test-loader relevant files: https://github.com/emberjs/ember-qunit/blob/main/addon/src/test-loader.js https://github.com/ember-cli/ember-exam/blob/main/addon-test-support/-private/ember-exam-test-loader.js <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/emberjs/ember-qunit/releases">ember-qunit's releases</a>.</em></p> <blockquote> <h2>Release 9.0.1</h2> <h4>🐛 Bug Fix</h4> <ul> <li><a href="https://redirect.github.com/emberjs/ember-qunit/pull/1183">#1183</a> Export TestLoader (<a href="https://github.com/ef4"><code>@ef4</code></a>)</li> </ul> <h4>Committers: 1</h4> <ul> <li>Edward Faulkner (<a href="https://github.com/ef4"><code>@ef4</code></a>)</li> </ul> <h2>Release 9.0.0</h2> <h4>💥 Breaking Change</h4> <ul> <li><a href="https://redirect.github.com/emberjs/ember-qunit/pull/1182">#1182</a> Require explicit calls to loadTests and setupEmberOnerrorValidation (<a href="https://github.com/ef4"><code>@ef4</code></a>)</li> </ul> <h4>🏠 Internal</h4> <ul> <li><a href="https://redirect.github.com/emberjs/ember-qunit/pull/1181">#1181</a> Remove unused babel plugins (<a href="https://github.com/ef4"><code>@ef4</code></a>)</li> </ul> <h4>Committers: 1</h4> <ul> <li>Edward Faulkner (<a href="https://github.com/ef4"><code>@ef4</code></a>)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/emberjs/ember-qunit/commit/48779a91acf9538efc8da01c29a36cd6c8bc5ace"><code>48779a9</code></a> Release 9.0.1</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/a70adfdf58c2845084b405b5d0230fd073367dd4"><code>a70adfd</code></a> Merge pull request <a href="https://redirect.github.com/emberjs/ember-qunit/issues/1183">#1183</a> from emberjs/export-test-loader</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/25e2a6f4b3e1132dbdfa4b82d9cf2573fb3b49fe"><code>25e2a6f</code></a> Export TestLoader</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/a039eda038190b0f002f3660866e606214ac9643"><code>a039eda</code></a> Release 9.0.0</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/18d5ca9543c4354d37b86e168c5d3ed08ff7619f"><code>18d5ca9</code></a> Merge pull request <a href="https://redirect.github.com/emberjs/ember-qunit/issues/1182">#1182</a> from emberjs/isolate-test-loading</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/e4a9efd750dbeab67a03a6032a6613fc1dc40ff7"><code>e4a9efd</code></a> fix missing type</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/634761bc1eb7785879ed915dab32eb130e1eeb34"><code>634761b</code></a> separate onerror validation too</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/d716b61cfd32a184aab82006ecfdebfd742ab7d3"><code>d716b61</code></a> Separate test loading from start</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/3428b769dc432449ff940760e08a96698b20d33f"><code>3428b76</code></a> Inline ember-cli-test-loader implementation</li> <li><a href="https://github.com/emberjs/ember-qunit/commit/da520e06840d9ab5bba3f6c5b9072fd75f787aed"><code>da520e0</code></a> Merge pull request <a href="https://redirect.github.com/emberjs/ember-qunit/issues/1181">#1181</a> from emberjs/unused-babel-plugins</li> <li>Additional commits viewable in <a href="https://github.com/emberjs/ember-qunit/compare/v8.1.1...v9.0.1">compare view</a></li> </ul> </details> <br />
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
import loadEmberExam from "ember-exam/test-support/load";
|
|
import { setupEmberOnerrorValidation, start } from "ember-qunit";
|
|
import * as QUnit from "qunit";
|
|
import { setup } from "qunit-dom";
|
|
import setupTests from "discourse/tests/setup-tests";
|
|
import config from "../config/environment";
|
|
|
|
document.addEventListener("discourse-init", () => {
|
|
if (!window.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?`
|
|
);
|
|
}
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const target = params.get("target") || "core";
|
|
const testingTheme = !!document.querySelector("script[data-theme-id]");
|
|
const disableAutoStart = params.get("qunit_disable_auto_start") === "1";
|
|
const hasThemeJs = !!document.querySelector("script[data-theme-id]");
|
|
|
|
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>
|
|
`
|
|
);
|
|
|
|
const testingCore = !testingTheme && target === "core";
|
|
if (testingCore) {
|
|
setupEmberOnerrorValidation();
|
|
}
|
|
|
|
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.shouldLoadModule = function (name) {
|
|
if (!/[-_]test$/.test(name)) {
|
|
return false;
|
|
}
|
|
|
|
const isPlugin = name.match(/\/plugins\//);
|
|
const isTheme = name.match(/\/theme-\d+\//);
|
|
const isCore = !isPlugin && !isTheme;
|
|
const pluginName = name.match(/\/plugins\/([\w-]+)\//)?.[1];
|
|
|
|
const loadCore = target === "core" || target === "all";
|
|
const loadAllPlugins = target === "plugins" || target === "all";
|
|
|
|
if (hasThemeJs) {
|
|
return isTheme;
|
|
} else if (isCore && !loadCore) {
|
|
return false;
|
|
} else if (isPlugin && !(loadAllPlugins || pluginName === target)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
loader.loadModules();
|
|
|
|
start({
|
|
setupTestContainer: false,
|
|
startTests: !disableAutoStart,
|
|
setupEmberOnerrorValidation: testingCore,
|
|
setupTestIsolationValidation: true,
|
|
});
|
|
});
|
|
|
|
window.EmberENV.TESTS_FILE_LOADED = true;
|