Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ const debug = require('debug')('codeceptjs:event')
const events = require('events')
const { error } = require('./output')

Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAX_LISTENERS constant should include a comment explaining why 200 was chosen as the limit and under what conditions this value might need adjustment.

Suggested change
// The MAX_LISTENERS constant sets the maximum number of event listeners for the dispatcher and process.
// The value 200 was chosen to prevent EventEmitter memory leak warnings in large test suites,
// where many plugins, hooks, or reporters may register listeners. Adjust this value if you encounter
// warnings about possible memory leaks, or if your project requires more listeners due to additional
// extensions or integrations.

Copilot uses AI. Check for mistakes.

const MAX_LISTENERS = 200

const dispatcher = new events.EventEmitter()

dispatcher.setMaxListeners(50)
dispatcher.setMaxListeners(MAX_LISTENERS)

// Increase process max listeners to prevent warnings for beforeExit and other events
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional check and process configuration should include a comment explaining why it's necessary and what specific warnings it prevents.

Suggested change
// Increase process max listeners to prevent warnings for beforeExit and other events
// Set process max listeners to avoid "MaxListenersExceededWarning" when many listeners are attached to process events (e.g., "beforeExit").
// This is necessary in large test suites to prevent Node.js from emitting warnings about possible memory leaks.

Copilot uses AI. Check for mistakes.

if (typeof process.setMaxListeners === 'function') {
process.setMaxListeners(MAX_LISTENERS)
}


/**
* @namespace
* @alias event
*/

module.exports = {
/**
* @type {NodeJS.EventEmitter}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"@pollyjs/core": "6.0.6",
"@types/chai": "5.2.2",
"@types/inquirer": "9.0.9",
"@types/node": "24.6.0",
"@types/node": "^24.6.0",
"@wdio/sauce-service": "9.12.5",
"@wdio/selenium-standalone-service": "8.15.0",
"@wdio/utils": "9.19.2",
Expand Down