-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
installCommonGlobals.test.ts
40 lines (30 loc) · 1.13 KB
/
installCommonGlobals.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {createContext, runInContext} from 'vm';
let installCommonGlobals: typeof import('../installCommonGlobals').default;
let fake: jest.Mock;
function getGlobal(): typeof globalThis {
return runInContext('this', createContext());
}
beforeEach(() => {
fake = jest.fn();
// @ts-expect-error
globalThis.DTRACE_NET_SERVER_CONNECTION = fake;
installCommonGlobals = require('../installCommonGlobals').default;
});
it('returns the passed object', () => {
const myGlobal = getGlobal();
expect(installCommonGlobals(myGlobal, {})).toBe(myGlobal);
});
it('turns a V8 global object into a Node global object', () => {
const myGlobal = installCommonGlobals(getGlobal(), {});
expect(myGlobal.process).toBeDefined();
expect(myGlobal.DTRACE_NET_SERVER_CONNECTION).toBeDefined();
expect(myGlobal.DTRACE_NET_SERVER_CONNECTION).not.toBe(fake);
myGlobal.DTRACE_NET_SERVER_CONNECTION();
expect(fake.mock.calls.length).toBe(1);
});