From d17a9cc0d8affb9e22950c5c5c9673accc7492f8 Mon Sep 17 00:00:00 2001 From: Idan Attias Date: Tue, 5 Nov 2019 13:06:06 +0200 Subject: [PATCH] jest-utils: add a getter for process.domain Fixes #7247: Explicitly copy domain to new process --- .../jest-util/src/__tests__/createProcessObject.test.ts | 8 ++++++++ packages/jest-util/src/createProcessObject.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/packages/jest-util/src/__tests__/createProcessObject.test.ts b/packages/jest-util/src/__tests__/createProcessObject.test.ts index c1658f793983..1af70c531084 100644 --- a/packages/jest-util/src/__tests__/createProcessObject.test.ts +++ b/packages/jest-util/src/__tests__/createProcessObject.test.ts @@ -6,6 +6,7 @@ */ import {EventEmitter} from 'events'; +import * as domain from 'domain'; let createProcessObject; @@ -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); +}); diff --git a/packages/jest-util/src/createProcessObject.ts b/packages/jest-util/src/createProcessObject.ts index 53d18dd43cb5..e04f48a5a3b5 100644 --- a/packages/jest-util/src/createProcessObject.ts +++ b/packages/jest-util/src/createProcessObject.ts @@ -112,5 +112,11 @@ export default function() { newProcess.env = createProcessEnv(); newProcess.send = () => {}; + Object.defineProperty(newProcess, 'domain', { + get() { + return process.domain; + }, + }); + return newProcess; }