Skip to content

Commit 567f73c

Browse files
adjust logging
1 parent 39e6d82 commit 567f73c

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

smoke-test/tests/cypress/cypress.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ module.exports = defineConfig({
1616
// We've imported your old cypress plugins here.
1717
// You may want to clean this up later by importing these.
1818
setupNodeEvents(on, config) {
19-
// eslint-disable-next-line no-unused-vars
20-
on("after:spec", (spec, results) => {
21-
console.log(`Completed spec: ${spec.relative}`);
22-
console.log(`Memory usage: ${JSON.stringify(process.memoryUsage())}`);
23-
});
24-
2519
// eslint-disable-next-line global-require
2620
return require("./cypress/plugins/index")(on, config);
2721
},

smoke-test/tests/cypress/cypress/plugins/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module.exports = (on, config) => {
2020
// `on` is used to hook into various events Cypress emits
2121
// `config` is the resolved Cypress config
2222

23+
// eslint-disable-next-line global-require
24+
require("./memoryUsage")(on);
25+
2326
// eslint-disable-next-line global-require
2427
require("cypress-timestamps/plugin")(on);
2528
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
23+
// Add a task to log to the terminal
24+
on("task", {
25+
logMemoryUsage(browserMemoryUsage) {
26+
const formatBytes = (bytes) =>
27+
(bytes / 1024 / 1024 / 1024).toFixed(3) + " GB";
28+
29+
if (browserMemoryUsage) {
30+
console.log("=== Browser Tab Memory Usage ===");
31+
console.log(`Used: ${formatBytes(browserMemoryUsage.usedJSHeapSize)}`);
32+
console.log(
33+
`Total: ${formatBytes(browserMemoryUsage.totalJSHeapSize)}`,
34+
);
35+
console.log(
36+
`Limit: ${formatBytes(browserMemoryUsage.jsHeapSizeLimit)}`,
37+
);
38+
}
39+
40+
const cypressMemoryUsage = process.memoryUsage();
41+
console.log("=== Cypress Memory Usage ===");
42+
console.log(`rss: ${formatBytes(cypressMemoryUsage.rss)}`);
43+
console.log(`heapTotal: ${formatBytes(cypressMemoryUsage.heapTotal)}`);
44+
console.log(`heapUsed: ${formatBytes(cypressMemoryUsage.heapUsed)}`);
45+
console.log(`external: ${formatBytes(cypressMemoryUsage.external)}`);
46+
console.log(
47+
`arrayBuffers: ${formatBytes(cypressMemoryUsage.arrayBuffers)}`,
48+
);
49+
50+
return null;
51+
},
52+
});
53+
};

smoke-test/tests/cypress/cypress/support/e2e.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,12 @@ beforeEach(function () {
4242

4343
afterEach(() => {
4444
cy.window().then((win) => {
45-
if (win.performance && win.performance.memory) {
46-
const mem = win.performance.memory;
47-
const formatBytes = (bytes) =>
48-
(bytes / 1024 / 1024 / 1024).toFixed(3) + " GB";
45+
const browserMemoryUsage = {
46+
usedJSHeapSize: win.performance?.memory?.usedJSHeapSize,
47+
totalJSHeapSize: win.performance?.memory?.totalJSHeapSize,
48+
jsHeapSizeLimit: win.performance?.memory?.jsHeapSizeLimit,
49+
};
4950

50-
cy.log("=== Browser Tab Memory ===");
51-
cy.log(`Used: ${formatBytes(mem.usedJSHeapSize)}`);
52-
cy.log(`Total: ${formatBytes(mem.totalJSHeapSize)}`);
53-
cy.log(`Limit: ${formatBytes(mem.jsHeapSizeLimit)}`);
54-
55-
console.log("=== Browser Tab Memory ===");
56-
console.log(`Used: ${formatBytes(mem.usedJSHeapSize)}`);
57-
console.log(`Total: ${formatBytes(mem.totalJSHeapSize)}`);
58-
console.log(`Limit: ${formatBytes(mem.jsHeapSizeLimit)}`);
59-
} else {
60-
cy.log("Browser memory API not available");
61-
console.log("Browser memory API not available");
62-
}
51+
cy.task("logMemoryUsage", browserMemoryUsage);
6352
});
6453
});

0 commit comments

Comments
 (0)