babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
Invalid variable access: process
Whitelisted objects: Array, ArrayBuffer, Boolean, DataView, Date, Error, EvalError, Float32Array, Float64Array, Function, Generator, GeneratorFunction, Infinity, Int16Array, Int32Array, Int8Array, InternalError, Intl, JSON, Map, Math, NaN, Number, Object, Promise, Proxy, RangeError, ReferenceError, Reflect, RegExp, Set, String, Symbol, SyntaxError, TypeError, URIError, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray, WeakMap, WeakSet, arguments, console, expect, isNaN, jest, parseFloat, parseInt, require, undefined, global, clearInterval, clearTimeout, setInterval, setTimeout, queueMicrotask, clearImmediate, setImmediate.
Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable names prefixed with `mock` (case insensitive) are permitted.
It is expected for jest to know about globals.
🐛 Bug Report
In the v12 of NodeJS, they changed the list of enumerable globals. Most notably
processandBufferare no longer enumerable. So this makes tests fail if global mock implementations use any of them.To Reproduce
Steps to reproduce the behavior:
Upgrade to the latest node:
> npm install -g nodeCreate a test file
test.jslike:npx jest ./test.jsThis will fail with
Expected behavior
It is expected for jest to know about globals.
Run
npx envinfo --preset jestPaste the results here:
System: OS: macOS Mojave 10.14.4 CPU: (4) x64 Intel(R) Core(TM) i7-6660U CPU @ 2.40GHz Binaries: Node: 12.1.0 - /usr/local/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm npmPackages: jest: file:../../../node_modules/jest => 24.8.0Suggested fix
I can suggest a quick and fair IMO fix. In https://github.com/facebook/jest/blob/master/packages/babel-plugin-jest-hoist/src/index.ts instead of
do
A PR #8429 submitted.
Quick workaround
For referencing
processorBufferin mock, you can usegloballike