mirror of
https://github.com/actions/setup-java.git
synced 2026-04-07 06:48: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 manifestData from '../data/jetbrains.json';
|
||||
import os from 'os';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyHttpClientHead: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -15,6 +15,10 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: []
|
||||
});
|
||||
spyHttpClientHead = jest.spyOn(HttpClient.prototype, 'head');
|
||||
spyHttpClientHead.mockReturnValue({
|
||||
message: {statusCode: 200}
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -40,9 +44,8 @@ describe('getAvailableVersions', () => {
|
||||
const availableVersions = await distribution['getAvailableVersions']();
|
||||
expect(availableVersions).not.toBeNull();
|
||||
|
||||
const length =
|
||||
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
|
||||
expect(availableVersions.length).toBe(length);
|
||||
// manifestData items + 2 hidden versions (always included when head is mocked to return 200)
|
||||
expect(availableVersions.length).toBe(manifestData.length + 2);
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user