|
| 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 | +}; |
0 commit comments