mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: Print usedJSHeapSize to the console after QUnit run (#14462)
This is `console.log`'d to the browser console. run-qunit will print this to stdout. testem will not, so a custom reporter is implemented to print this message. The `--enable-precise-memory-info` is added so that chrome provides high-resolution memory information. This API is not supported by firefox. The logic will degrade gracefully.
This commit is contained in:
parent
4dc14e3a3f
commit
4fa296c3ec
|
@ -1,3 +1,27 @@
|
||||||
|
const TapReporter = require("testem/lib/reporters/tap_reporter");
|
||||||
|
|
||||||
|
class Reporter {
|
||||||
|
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) {
|
||||||
|
this._tapReporter.report(prefix, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
finish() {
|
||||||
|
this._tapReporter.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
test_page: "tests/index.html?hidepassed",
|
test_page: "tests/index.html?hidepassed",
|
||||||
disable_watching: true,
|
disable_watching: true,
|
||||||
|
@ -15,6 +39,7 @@ module.exports = {
|
||||||
"--mute-audio",
|
"--mute-audio",
|
||||||
"--remote-debugging-port=4201",
|
"--remote-debugging-port=4201",
|
||||||
"--window-size=1440,900",
|
"--window-size=1440,900",
|
||||||
|
"--enable-precise-memory-info",
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
Firefox: ["-headless", "--width=1440", "--height=900"],
|
Firefox: ["-headless", "--width=1440", "--height=900"],
|
||||||
"Headless Firefox": ["--width=1440", "--height=900"],
|
"Headless Firefox": ["--width=1440", "--height=900"],
|
||||||
|
@ -22,4 +47,5 @@ module.exports = {
|
||||||
browser_paths: {
|
browser_paths: {
|
||||||
"Headless Firefox": "/opt/firefox-evergreen/firefox",
|
"Headless Firefox": "/opt/firefox-evergreen/firefox",
|
||||||
},
|
},
|
||||||
|
reporter: Reporter,
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,6 +127,32 @@ function setupToolbar() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reportMemoryUsageAfterTests() {
|
||||||
|
QUnit.done(() => {
|
||||||
|
const usageBytes = performance.memory?.usedJSHeapSize;
|
||||||
|
let result;
|
||||||
|
if (usageBytes) {
|
||||||
|
result = `${(usageBytes / Math.pow(2, 30)).toFixed(3)}GB`;
|
||||||
|
} else {
|
||||||
|
result = "(performance.memory api unavailable)";
|
||||||
|
}
|
||||||
|
|
||||||
|
writeSummaryLine(`Used JS Heap Size: ${result}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeSummaryLine(message) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`\n${message}\n`);
|
||||||
|
if (window.Testem) {
|
||||||
|
window.Testem.useCustomAdapter(function (socket) {
|
||||||
|
socket.emit("test-metadata", "summary-line", {
|
||||||
|
message: message,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupTestsCommon(application, container, config) {
|
function setupTestsCommon(application, container, config) {
|
||||||
QUnit.config.hidepassed = true;
|
QUnit.config.hidepassed = true;
|
||||||
|
|
||||||
|
@ -353,6 +379,7 @@ function setupTestsCommon(application, container, config) {
|
||||||
jQuery.fx.off = true;
|
jQuery.fx.off = true;
|
||||||
|
|
||||||
setupToolbar();
|
setupToolbar();
|
||||||
|
reportMemoryUsageAfterTests();
|
||||||
setApplication(application);
|
setApplication(application);
|
||||||
setDefaultOwner(application.__container__);
|
setDefaultOwner(application.__container__);
|
||||||
resetSite();
|
resetSite();
|
||||||
|
|
|
@ -42,6 +42,7 @@ async function runAllTests() {
|
||||||
"--disable-dev-shm-usage",
|
"--disable-dev-shm-usage",
|
||||||
"--mute-audio",
|
"--mute-audio",
|
||||||
"--window-size=1440,900",
|
"--window-size=1440,900",
|
||||||
|
"--enable-precise-memory-info",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user