Skip to content

Commit

Permalink
fix(jest-util): pass more globals through
Browse files Browse the repository at this point in the history
passing a set of commong globals through to the env to ensure instanceof checks work as expected.

Fixes jestjs#4422
  • Loading branch information
dignifiedquire committed Sep 5, 2017
1 parent 9075ecf commit e758423
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions integration_tests/test-environment/__tests__/globals.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @jest-environment node
*/
'use strict';
/* eslint-env node */

test('globals', () => {
const buf = Buffer.from('hello');
expect(buf instanceof Uint8Array).toEqual(true);
});
18 changes: 18 additions & 0 deletions packages/jest-util/src/install_common_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ module.exports = (global: Global, globals: ConfigGlobals) => {
// Forward some APIs
global.Buffer = Buffer;

global.ArrayBuffer = ArrayBuffer;
global.DataView = DataView;

global.Uint8Array = Uint8Array;
global.Uint8ClampedArray = Uint8ClampedArray;
global.Uint16Array = Uint16Array;
global.Uint32Array = Uint32Array;
global.Int8Array = Int8Array;
global.Int16Array = Int16Array;
global.Int32Array = Int32Array;
global.Float32Array = Float32Array;
global.Float64Array = Float64Array;

global.Map = Map;
global.Set = Set;

global.Promise = Promise;

// `global.process` is mutated by FakeTimers. Make a copy of the
// object for the jsdom environment to prevent memory leaks.
// Overwrite toString to make it look like the real process object
Expand Down

0 comments on commit e758423

Please sign in to comment.