mirror of
https://github.com/actions/setup-java.git
synced 2026-04-07 15:38:53 +00:00
Fix JetBrains test: mock HttpClient.prototype.head to avoid real network calls
Agent-Logs-Url: https://github.com/nbauma109/setup-java/sessions/22657daf-3cd6-46b6-b816-d32ff0c775e6 Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
This commit is contained in:
parent
d44c72fc6c
commit
7f63f5d619
@ -3,10 +3,10 @@ import {HttpClient} from '@actions/http-client';
|
|||||||
import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer';
|
import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer';
|
||||||
|
|
||||||
import manifestData from '../data/jetbrains.json';
|
import manifestData from '../data/jetbrains.json';
|
||||||
import os from 'os';
|
|
||||||
|
|
||||||
describe('getAvailableVersions', () => {
|
describe('getAvailableVersions', () => {
|
||||||
let spyHttpClient: jest.SpyInstance;
|
let spyHttpClient: jest.SpyInstance;
|
||||||
|
let spyHttpClientHead: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||||
@ -15,6 +15,10 @@ describe('getAvailableVersions', () => {
|
|||||||
headers: {},
|
headers: {},
|
||||||
result: []
|
result: []
|
||||||
});
|
});
|
||||||
|
spyHttpClientHead = jest.spyOn(HttpClient.prototype, 'head');
|
||||||
|
spyHttpClientHead.mockReturnValue({
|
||||||
|
message: {statusCode: 200}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -40,9 +44,8 @@ describe('getAvailableVersions', () => {
|
|||||||
const availableVersions = await distribution['getAvailableVersions']();
|
const availableVersions = await distribution['getAvailableVersions']();
|
||||||
expect(availableVersions).not.toBeNull();
|
expect(availableVersions).not.toBeNull();
|
||||||
|
|
||||||
const length =
|
// manifestData items + 2 hidden versions (always included when head is mocked to return 200)
|
||||||
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
expect(availableVersions.length).toBe(manifestData.length + 2);
|
||||||
expect(availableVersions.length).toBe(length);
|
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user