Skip to content

A platform for community discussion. Free, open, simple.

DEV: Improve testem error (#41975)

Jarek Radosz89b5c86906c6
diff --git a/app/views/qunit/qunit.html.erb b/app/views/qunit/qunit.html.erb
index 2c96a008e66..8ffff4025a8 100644
--- a/app/views/qunit/qunit.html.erb
+++ b/app/views/qunit/qunit.html.erb
@@ -15,6 +15,16 @@
<script nonce="<%= csp_nonce_placeholder %>">
window._discourseQunitPluginNames = <%= Discourse.plugins.map(&:directory_name).to_json.html_safe %>;
+
+ window.onunhandledrejection = (event) => {
+ // reports test boot failures to testem, so the browser doesn't hang forever
+ window.Testem?.emit(
+ "top-level-error",
+ String(event.reason),
+ "qunit.html.erb",
+ "?"
+ );
+ };
</script>
<%= tag.iframe srcdoc: tag.script(
diff --git a/frontend/discourse/app/app.js b/frontend/discourse/app/app.js
index 48b5d91bf1c..428c85a4133 100644
--- a/frontend/discourse/app/app.js
+++ b/frontend/discourse/app/app.js
@@ -87,12 +87,6 @@ async function loadPluginFromModulePreload(link) {
define(`discourse/plugins/${pluginName}/${key}`, () => mod);
}
} catch (error) {
- // eslint-disable-next-line no-console
- console.error(
- `Failed to load plugin ${link.dataset.pluginName} from ${link.href}`,
- String(error)
- );
-
if (DEBUG) {
if (isRailsTesting() || isTesting()) {
throw new Error(error, { cause: error });
@@ -101,6 +95,12 @@ async function loadPluginFromModulePreload(link) {
let { addError } = importSync("discourse/static/development-error");
addError(error, link.dataset.pluginName, link.href);
}
+
+ // eslint-disable-next-line no-console
+ console.error(
+ `Failed to load plugin ${link.dataset.pluginName} from ${link.href}`,
+ String(error)
+ );
}
}
diff --git a/frontend/discourse/testem.js b/frontend/discourse/testem.js
index 34f88ae27d1..a2c64fbfd82 100644
--- a/frontend/discourse/testem.js
+++ b/frontend/discourse/testem.js
@@ -72,17 +72,12 @@ class Reporter extends TapReporter {
this.strictSpecCompliance
);
- const string = this.reformatTapLine(rawString, prefix);
+ let string = this.reformatTapLine(rawString, prefix);
const color = this.colorForResult(result);
- const matches = string.match(/([\S\s]+?)(\n\s+browser\slog:[\S\s]+)/);
+ string = string.replace(/\n\s+---\n\s+browser\slog:[\S\s]+/, "\n");
- if (matches) {
- this.out.write(color(matches[1]));
- this.out.write(colors.cyan(matches[2]));
- } else {
- this.out.write(color(string));
- }
+ this.out.write(color(string));
}
}
@@ -275,6 +270,7 @@ module.exports = {
? parseInt(process.env.QUNIT_BROWSER_START_TIMEOUT, 10)
: 120,
browser_disconnect_timeout: 30,
+ chrome_stderr_info_only: true,
browser_args: {
Chromium: [
// --no-sandbox is needed when running Chromium inside a container or when explicitly requested
diff --git a/frontend/discourse/tests/setup-tests.js b/frontend/discourse/tests/setup-tests.js
index 30e9f8dec00..b0b10dd4ab0 100644
--- a/frontend/discourse/tests/setup-tests.js
+++ b/frontend/discourse/tests/setup-tests.js
@@ -213,16 +213,6 @@ export default async function setupTests(config) {
QUnit.config.hidepassed = true;
QUnit.config.testTimeout = 60_000;
- window.onunhandledrejection = (event) => {
- // reports test boot failures to testem, so the browser doesn't hang forever
- window.Testem?.emit(
- "top-level-error",
- String(event.reason),
- window.location.href,
- "0"
- );
- };
-
// Stop the message bus so we don't get ajax calls
window.MessageBus.stop();