-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathhttpUtils.test.ts
29 lines (23 loc) · 1.09 KB
/
httpUtils.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
import {jest, describe, beforeEach, it, expect} from '@jest/globals';
import process from 'node:process';
import {fetchAsJson as httpFetchAsJson} from '../sources/httpUtils';
describe(`httpUtils`, () => {
beforeEach(() => {
jest.resetAllMocks();
globalThis.fetch = jest.fn(() => Promise.resolve( {
ok: true,
json: () => Promise.resolve({})
}));
});
it(`adds authorization header if COREPACK_NPM_TOKEN is set with custom COREPACK_NPM_REGISTRY`, async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_NPM_TOKEN = `foo`;
process.env.COREPACK_NPM_REGISTRY = `https://registry.example.org/with-path/npm`
await httpFetchAsJson(`${process.env.COREPACK_NPM_REGISTRY}/package-name`);
expect(globalThis.fetch).toBeCalled();
expect(globalThis.fetch).lastCalledWith(new URL(`${process.env.COREPACK_NPM_REGISTRY}/package-name`), {
headers: {
authorization: `Bearer ${process.env.COREPACK_NPM_TOKEN}`,
}});
});
});