Skip to content

Commit 5910ddd

Browse files
onurtemizkanlobsterkatie
authored andcommitted
ref(tests): Suppress unconstructive listener and open handle warnings. (#4951)
Removes warnings that we can't address at the moment from Jest logs. 1 - `MaxEventListener` warning is about a potential memory leak when more than 10 event listeners are assigned inside a single thread. As we're running all our integration tests on a single Jest thread, after 10th Sentry initialization, this warning starts polluting logs. Still, it's not great to have unregistered handles around. But we know it's limited to the number of test scenarios here. So IMO this workaround is safe to use for these tests. 2 - `detectOpenHandles` warns about uncleared intervals from `session` tests (where we're hackily replacing flush interval), which we are eventually clearing but can't set a reliable timeout, and we're also using `--forceExit` that does that on exit.
1 parent fbf89c2 commit 5910ddd

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const baseConfig = require('../../jest.config.js');
22

33
module.exports = {
4+
globalSetup: '<rootDir>/setup-tests.ts',
45
...baseConfig,
56
testMatch: ['**/test.ts'],
67
};

packages/node-integration-tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
1212
"lint:prettier": "prettier --check \"{suites,utils}/**/*.ts\"",
1313
"type-check": "tsc",
14-
"test": "jest --detectOpenHandles --runInBand --forceExit",
14+
"test": "jest --runInBand --forceExit",
1515
"test:watch": "yarn test --watch"
1616
},
1717
"dependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import EventEmitter from 'events';
2+
3+
const setup = async (): Promise<void> => {
4+
// Node warns about a potential memory leak
5+
// when more than 10 event listeners are assigned inside a single thread.
6+
// Initializing Sentry for each test triggers these warnings after 10th test inside Jest thread.
7+
// As we know that it's not a memory leak and number of listeners are limited to the number of tests,
8+
// removing the limit on listener count here.
9+
EventEmitter.defaultMaxListeners = 0;
10+
};
11+
12+
export default setup;

0 commit comments

Comments
 (0)