This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/testem.js
Jarek Radosz bdd0a98f38
DEV: Fix testem output (#18609)
Failed tests list we're displaying at the end had incorrect ids. e.g

```
(…)
ok 2160 Chrome 106.0 - [54 ms] - Integration | Component | select-kit/category-drop: caretUpIcon
ok 2161 Chrome 106.0 - [20 ms] - Unit | Service | store: find embedded

Used JS Heap Size: 7.304GB

1..2161
# tests 2161
# pass  2152
# skip  7
# todo  0
# fail  2

Failures:

not ok 2162 Chrome 106.0 - [36 ms] - Acceptance: Unknown: Permalink URL to a static page
    ---
        actual: >
            null
        message: >
            Promise rejected during "Permalink URL to a static page": no no
        negative: >
            false
        browser log: |
    ...
not ok 2163 Chrome 106.0 - [238 ms] - Unit | Utility | text: parseAsync
    ---
        actual: >
            null
        message: >
            Promise rejected during "parseAsync": nope
        negative: >
            false
        browser log: |
    ...
Testem finished with non-zero exit code. Tests failed.
```
2022-10-16 19:38:20 +02:00

110 lines
2.9 KiB
JavaScript

const TapReporter = require("testem/lib/reporters/tap_reporter");
const { shouldLoadPluginTestJs } = require("discourse/lib/plugin-js");
class Reporter {
failReports = [];
constructor() {
this._tapReporter = new TapReporter(...arguments);
}
reportMetadata(tag, metadata) {
if (tag === "summary-line") {
process.stdout.write(`\n${metadata.message}\n`);
} else {
this._tapReporter.reportMetadata(...arguments);
}
}
report(prefix, data) {
if (data.failed) {
this.failReports.push([prefix, data, this._tapReporter.id]);
}
this._tapReporter.report(prefix, data);
}
finish() {
this._tapReporter.finish();
if (this.failReports.length > 0) {
process.stdout.write("\nFailures:\n\n");
this.failReports.forEach(([prefix, data, id]) => {
if (process.env.GITHUB_ACTIONS) {
process.stdout.write(`::error ::QUnit Test Failure: ${data.name}\n`);
}
this._tapReporter.id = id;
this._tapReporter.report(prefix, data);
});
}
}
}
module.exports = {
test_page: "tests/index.html?hidepassed",
disable_watching: true,
launch_in_ci: ["Chrome"],
// launch_in_dev: ["Chrome"] // Ember-CLI always launches testem in 'CI' mode
tap_failed_tests_only: false,
parallel: -1,
browser_start_timeout: 120,
browser_args: {
Chrome: [
// --no-sandbox is needed when running Chrome inside a container
process.env.CI ? "--no-sandbox" : null,
"--headless",
"--disable-dev-shm-usage",
"--disable-software-rasterizer",
"--mute-audio",
"--remote-debugging-port=4201",
"--window-size=1440,900",
"--enable-precise-memory-info",
"--js-flags=--max_old_space_size=4096",
].filter(Boolean),
Firefox: ["-headless", "--width=1440", "--height=900"],
},
reporter: Reporter,
};
if (process.env.TESTEM_FIREFOX_PATH) {
module.exports.browser_paths ||= {};
module.exports.browser_paths["Firefox"] = process.env.TESTEM_FIREFOX_PATH;
}
const target = `http://127.0.0.1:${process.env.UNICORN_PORT || "3000"}`;
if (process.argv.includes("-t")) {
// Running testem without ember cli. Probably for theme-qunit
const testPage = process.argv[process.argv.indexOf("-t") + 1];
module.exports.proxies = {};
module.exports.proxies[`/*/theme-qunit`] = {
target: `${target}${testPage}`,
ignorePath: true,
xfwd: true,
};
module.exports.proxies["/*/*"] = { target, xfwd: true };
module.exports.middleware = [
function (app) {
// Make the testem.js file available under /assets
// so it's within the app's CSP
app.get("/assets/testem.js", function (req, res, next) {
req.url = "/testem.js";
next();
});
},
];
} else if (shouldLoadPluginTestJs()) {
// Running with ember cli, but we want to pass through plugin request to Rails
module.exports.proxies = {
"/assets/plugins/*_extra.js": {
target,
},
"/plugins/": {
target,
},
};
}