Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for the Jest process.emit binding bug. #373

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,11 @@ export default {
`${TESTER_DIR}/lib/node_modules/jest-extended/all`,
`${TESTER_DIR}/lib/code/node_modules/@this/main-tester`
]
},

// Test harness options.
...{
// maxConcurrency: 1,
// maxWorkers: 1
}
};
11 changes: 11 additions & 0 deletions src/main-tester/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ process.on('warning', (warning) => {

console.log('%s: %s\n', warning.name, warning.message);
});

// This works around a bug in Jest's wrapping of `process`: `process.emit` is
// normally inherited from `EventEmitter`, but `source-map-support` directly
// adds an `emit` binding to `process`. _Sometimes_ this happens when Jest is in
// the middle of creating a `SyntheticModule` wrapper for `process`, and if that
// happens at just the wrong time, Node will throw `ReferenceError: Export
// 'emit' is not defined in module`. By putting a direct binding of
// `process.emit` here, we avoid the race (though there is still arguably an
// underlying problem). See this issue in Jest:
// <https://github.com/jestjs/jest/issues/15077>
process.emit = process.emit; // eslint-disable-line no-self-assign