MCPcopy
hub / github.com/jestjs/jest / constructor

Method constructor

packages/jest-environment-node/src/index.ts:100–235  ·  view source on GitHub ↗
(config: JestEnvironmentConfig, _context: EnvironmentContext)

Source from the content-addressed store, hash-verified

98
99 // while `context` is unused, it should always be passed
100 constructor(config: JestEnvironmentConfig, _context: EnvironmentContext) {
101 const {projectConfig} = config;
102
103 const globalsCleanupMode = readGlobalsCleanupConfig(projectConfig);
104 initializeGarbageCollectionUtils(globalThis, globalsCleanupMode);
105
106 this._globalProxy = new GlobalProxy();
107 this.context = createContext(this._globalProxy.proxy());
108 const global = runInContext(
109 'this',
110 Object.assign(this.context, projectConfig.testEnvironmentOptions),
111 ) as Global.Global;
112 this.global = global;
113
114 const contextGlobals = new Set(
115 Object.getOwnPropertyNames(global) as GlobalProperties,
116 );
117 for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
118 if (!storageGlobals.has(nodeGlobalsKey as string)) {
119 protectProperties(globalThis[nodeGlobalsKey]);
120 }
121 if (!contextGlobals.has(nodeGlobalsKey)) {
122 if (storageGlobals.has(nodeGlobalsKey as string)) {
123 Object.defineProperty(global, nodeGlobalsKey, {
124 configurable: true,
125 enumerable: descriptor.enumerable,
126 get: () => globalThis[nodeGlobalsKey],
127 set(value) {
128 Object.defineProperty(global, nodeGlobalsKey, {
129 configurable: true,
130 enumerable: descriptor.enumerable,
131 value,
132 writable: true,
133 });
134 },
135 });
136 } else if (descriptor.configurable) {
137 Object.defineProperty(global, nodeGlobalsKey, {
138 configurable: true,
139 enumerable: descriptor.enumerable,
140 get() {
141 const value = globalThis[nodeGlobalsKey];
142
143 // override lazy getter
144 Object.defineProperty(global, nodeGlobalsKey, {
145 configurable: true,
146 enumerable: descriptor.enumerable,
147 value,
148 writable: true,
149 });
150
151 return value;
152 },
153 set(value: unknown) {
154 // override lazy getter
155 Object.defineProperty(global, nodeGlobalsKey, {
156 configurable: true,
157 enumerable: descriptor.enumerable,

Callers

nothing calls this directly

Calls 9

protectPropertiesFunction · 0.90
installCommonGlobalsFunction · 0.90
readGlobalsCleanupConfigFunction · 0.85
createContextFunction · 0.85
proxyMethod · 0.80
definePropertyMethod · 0.80
forMethod · 0.80
envSetupCompletedMethod · 0.80

Tested by

no test coverage detected