Skip to content

Commit 5652cad

Browse files
committed
feat(test): ⭐️ remove Bun specific imports, so that the tests can be using both Jest and Bun as they are automatically imported in the global scope. However, a Jest polyfill is required in the jest.setup.js because the global Request API (part of the Fetch API) is not available (or not properly configured?)
1 parent 5ef1e6a commit 5652cad

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

jest.setup.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ const crypto = require('crypto');
33
global.TextEncoder = require('util').TextEncoder;
44
global.TextDecoder = require('util').TextDecoder;
55
global.crypto = crypto;
6+
7+
// If this is not included, you will get the following error when running it in Jest:
8+
// (Error) Details: Request is not defined
9+
// The problem is that Jest is running in a Node.js environment where the global Request API (part of the Fetch API) might not be available or properly configured. Bun, on the other hand, has this API built into its runtime by default, which is why it works.
10+
const { default: fetch, Request, Response } = require('node-fetch');
11+
global.fetch = fetch;
12+
global.Request = Request;
13+
global.Response = Response;

packages/networks/src/lib/networks/vNaga/common/LitChainClient/apis/rawContractApis/staking/getActiveUnkickedValidatorStructsAndCounts.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { beforeAll, describe, expect, test } from 'bun:test';
21
import { networkContext, NetworkContext } from '../../../_config';
32
import { getActiveUnkickedValidatorStructsAndCounts } from './getActiveUnkickedValidatorStructsAndCounts';
43

0 commit comments

Comments
 (0)