Skip to content

Commit a8f9c91

Browse files
v-tarasevich-blitz-brainesteban
authored andcommitted
fix(cypress): memory optimizations (#15290)
1 parent 4918e9a commit a8f9c91

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

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("./memoryUsageLogger")(on);
25+
2326
// eslint-disable-next-line global-require
2427
require("cypress-timestamps/plugin")(on);
2528
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @type {Cypress.PluginConfig}
3+
*/
4+
// eslint-disable-next-line no-unused-vars
5+
module.exports = (on, config) => {
6+
// Add a task to log memory usage to the terminal
7+
on("task", {
8+
logMemoryUsage(browserMemoryUsage) {
9+
const formatBytes = (bytes) =>
10+
(bytes / 1024 / 1024 / 1024).toFixed(3) + " GB";
11+
12+
if (browserMemoryUsage) {
13+
console.log("=== Browser Tab Memory Usage ===");
14+
console.log(`Used: ${formatBytes(browserMemoryUsage.usedJSHeapSize)}`);
15+
console.log(
16+
`Total: ${formatBytes(browserMemoryUsage.totalJSHeapSize)}`,
17+
);
18+
console.log(
19+
`Limit: ${formatBytes(browserMemoryUsage.jsHeapSizeLimit)}`,
20+
);
21+
}
22+
23+
const cypressMemoryUsage = process.memoryUsage();
24+
console.log("=== Cypress Memory Usage ===");
25+
console.log(`rss: ${formatBytes(cypressMemoryUsage.rss)}`);
26+
console.log(`heapTotal: ${formatBytes(cypressMemoryUsage.heapTotal)}`);
27+
console.log(`heapUsed: ${formatBytes(cypressMemoryUsage.heapUsed)}`);
28+
console.log(`external: ${formatBytes(cypressMemoryUsage.external)}`);
29+
console.log(
30+
`arrayBuffers: ${formatBytes(cypressMemoryUsage.arrayBuffers)}`,
31+
);
32+
33+
return null;
34+
},
35+
});
36+
};

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ beforeEach(function () {
3939
}
4040
}
4141
});
42+
43+
afterEach(() => {
44+
cy.window().then((win) => {
45+
const browserMemoryUsage = {
46+
usedJSHeapSize: win.performance?.memory?.usedJSHeapSize,
47+
totalJSHeapSize: win.performance?.memory?.totalJSHeapSize,
48+
jsHeapSizeLimit: win.performance?.memory?.jsHeapSizeLimit,
49+
};
50+
51+
cy.task("logMemoryUsage", browserMemoryUsage);
52+
});
53+
});

smoke-test/tests/cypress/integration_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ def test_run_cypress(auth_session):
262262
test_spec_arg = f" --spec '{specs_str}' "
263263

264264
print("Running Cypress tests with command")
265-
node_options = "--max-old-space-size=6000"
266-
command = f'NO_COLOR=1 NODE_OPTIONS="{node_options}" npx cypress run {record_arg} {test_spec_arg} {tag_arg} --config numTestsKeptInMemory=2'
265+
node_options = "--max-old-space-size=500"
266+
electron_args = 'ELECTRON_EXTRA_LAUNCH_ARGS="--js-flags=\'--max-old-space-size=4096 --disable-dev-shm-usage --disable-gpu --no-sandbox"'
267+
command = f'{electron_args} NO_COLOR=1 NODE_OPTIONS="{node_options}" npx cypress run {record_arg} {test_spec_arg} {tag_arg} --config numTestsKeptInMemory=2'
267268
print(command)
268269
# Add --headed --spec '**/mutations/mutations.js' (change spec name)
269270
# in case you want to see the browser for debugging

0 commit comments

Comments
 (0)