Skip to content

Commit

Permalink
jest-utils: add a getter for process.domain
Browse files Browse the repository at this point in the history
Fixes jestjs#7247: Explicitly copy domain to new process
  • Loading branch information
Idan Attias committed Nov 5, 2019
1 parent 7ece746 commit d17a9cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/jest-util/src/__tests__/createProcessObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {EventEmitter} from 'events';
import * as domain from 'domain';

let createProcessObject;

Expand Down Expand Up @@ -105,3 +106,10 @@ it('checks that process.env works as expected in Windows platforms', () => {
expect(fake.hasOwnProperty('PROP_STRING')).toBe(false);
expect(fake.hasOwnProperty('PROP_string')).toBe(false);
});

test('allows retrieving the current domain', () => {
const aDomain = domain.create();
process.domain = aDomain;

expect(createProcessObject().domain).toEqual(aDomain);
});
6 changes: 6 additions & 0 deletions packages/jest-util/src/createProcessObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ export default function() {
newProcess.env = createProcessEnv();
newProcess.send = () => {};

Object.defineProperty(newProcess, 'domain', {
get() {
return process.domain;
},
});

return newProcess;
}

0 comments on commit d17a9cc

Please sign in to comment.