Skip to content

Commit

Permalink
Workaround for the Jest process.emit binding bug. (#373)
Browse files Browse the repository at this point in the history
This PR is the result of like a day and a half of research, even though
the actual effective diff is a single line, and a trivial-looking one at
that! To wit:

```js
process.emit = process.emit;
```

But what a difference it makes! See
<jestjs/jest#15077>, which I filed on Jest,
for the gory details.
  • Loading branch information
danfuzz authored May 20, 2024
2 parents c68a035 + 31111c7 commit a9e2daa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit a9e2daa

Please sign in to comment.