DEV: Add plugin-related parameters to the QUnit web UI

This commit also hides a number of options which are not used during Discourse development.

Change have been tested on both the legacy `/qunit` route, and the Ember CLI `/tests` route.
This commit is contained in:
David Taylor 2021-09-21 14:38:11 +01:00
parent 402162e18a
commit 4bdeb45727

View File

@ -81,14 +81,50 @@ function createApplication(config, settings) {
return app;
}
function setupToolbar() {
// Most default toolbar items aren't useful for Discourse
QUnit.config.urlConfig = QUnit.config.urlConfig.reject((c) =>
[
"noglobals",
"notrycatch",
"nolint",
"devmode",
"dockcontainer",
"nocontainer",
].includes(c.id)
);
QUnit.config.urlConfig.push({
id: "qunit_skip_core",
label: "Skip Core",
value: "1",
});
QUnit.config.urlConfig.push({
id: "qunit_skip_plugins",
label: "Skip Plugins",
value: "1",
});
const pluginNames = new Set();
Object.keys(requirejs.entries).forEach((moduleName) => {
const found = moduleName.match(/\/plugins\/([\w-]+)\//);
if (found && moduleName.match(/\-test/)) {
pluginNames.add(found[1]);
}
});
QUnit.config.urlConfig.push({
id: "qunit_single_plugin",
label: "Plugin",
value: Array.from(pluginNames),
});
}
function setupTestsCommon(application, container, config) {
QUnit.config.hidepassed = true;
// Let's customize QUnit options a bit
QUnit.config.urlConfig = QUnit.config.urlConfig.filter(
(c) => ["dockcontainer", "nocontainer"].indexOf(c.id) === -1
);
application.rootElement = "#ember-testing";
application.setupForTesting();
application.injectTestHelpers();
@ -315,6 +351,7 @@ function setupTestsCommon(application, container, config) {
// forces 0 as duration for all jquery animations
jQuery.fx.off = true;
setupToolbar();
setApplication(application);
setDefaultOwner(application.__container__);
resetSite();
@ -347,5 +384,17 @@ function replaceUrlParameter(name, value) {
} else {
queryParams.set(name, value);
}
window.location = "?" + queryParams.toString();
history.replaceState(null, null, "?" + queryParams.toString());
QUnit.begin(() => {
QUnit.config[name] = value;
const formElement = document.querySelector(
`#qunit-testrunner-toolbar [name=${name}]`
);
if (formElement?.type === "checkbox") {
formElement.checked = !!value;
} else if (formElement) {
formElement.value = value;
}
});
}