mirror of
https://github.com/actions/setup-java.git
synced 2025-09-30 12:45:50 +00:00
Lint Issue Resolve
This commit is contained in:
parent
70ede9d147
commit
a55d8d1a5e
1 changed files with 15 additions and 18 deletions
|
@ -5,6 +5,7 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
|
import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
|
||||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||||
|
import * as util from '../../src/util';
|
||||||
|
|
||||||
jest.mock('@actions/core');
|
jest.mock('@actions/core');
|
||||||
jest.mock('@actions/tool-cache');
|
jest.mock('@actions/tool-cache');
|
||||||
|
@ -24,18 +25,13 @@ jest.mock('fs', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Ensure we're in test mode
|
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
// Disable any real network calls
|
if (!jest.isMockFunction(http.HttpClient)) {
|
||||||
const HttpClient = require('@actions/http-client').HttpClient;
|
|
||||||
if (!jest.isMockFunction(HttpClient)) {
|
|
||||||
throw new Error('HTTP client must be mocked in tests!');
|
throw new Error('HTTP client must be mocked in tests!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional: Add more safety checks
|
if (!jest.isMockFunction(tc.downloadTool)) {
|
||||||
const toolCache = require('@actions/tool-cache');
|
|
||||||
if (!jest.isMockFunction(toolCache.downloadTool)) {
|
|
||||||
throw new Error('Tool cache downloadTool must be mocked in tests!');
|
throw new Error('Tool cache downloadTool must be mocked in tests!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +57,14 @@ describe('GraalVMDistribution', () => {
|
||||||
mockHttpClient = new http.HttpClient() as jest.Mocked<http.HttpClient>;
|
mockHttpClient = new http.HttpClient() as jest.Mocked<http.HttpClient>;
|
||||||
(distribution as any).http = mockHttpClient;
|
(distribution as any).http = mockHttpClient;
|
||||||
|
|
||||||
const util = require('../../src/util');
|
(util.getDownloadArchiveExtension as jest.Mock).mockReturnValue('tar.gz');
|
||||||
util.getDownloadArchiveExtension.mockReturnValue('tar.gz');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
const HttpClient = require('@actions/http-client').HttpClient;
|
expect(jest.isMockFunction(http.HttpClient)).toBe(true);
|
||||||
expect(jest.isMockFunction(HttpClient)).toBe(true);
|
|
||||||
|
expect(jest.isMockFunction(tc.downloadTool)).toBe(true);
|
||||||
|
expect(jest.isMockFunction(tc.cacheDir)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getPlatform', () => {
|
describe('getPlatform', () => {
|
||||||
|
@ -103,10 +100,11 @@ describe('GraalVMDistribution', () => {
|
||||||
(tc.downloadTool as jest.Mock).mockResolvedValue('/tmp/archive.tar.gz');
|
(tc.downloadTool as jest.Mock).mockResolvedValue('/tmp/archive.tar.gz');
|
||||||
(tc.cacheDir as jest.Mock).mockResolvedValue('/cached/java/path');
|
(tc.cacheDir as jest.Mock).mockResolvedValue('/cached/java/path');
|
||||||
|
|
||||||
const util = require('../../src/util');
|
(util.extractJdkFile as jest.Mock).mockResolvedValue('/tmp/extracted');
|
||||||
util.extractJdkFile.mockResolvedValue('/tmp/extracted');
|
(util.renameWinArchive as jest.Mock).mockImplementation(
|
||||||
util.renameWinArchive.mockImplementation((p: string) => p + '.renamed');
|
(p: string) => p + '.renamed'
|
||||||
util.getDownloadArchiveExtension.mockReturnValue('tar.gz');
|
);
|
||||||
|
(util.getDownloadArchiveExtension as jest.Mock).mockReturnValue('tar.gz');
|
||||||
|
|
||||||
(fs.readdirSync as jest.Mock).mockReturnValue(['graalvm-jdk-17.0.5']);
|
(fs.readdirSync as jest.Mock).mockReturnValue(['graalvm-jdk-17.0.5']);
|
||||||
|
|
||||||
|
@ -120,7 +118,7 @@ describe('GraalVMDistribution', () => {
|
||||||
|
|
||||||
expect(tc.downloadTool).toHaveBeenCalledWith(javaRelease.url);
|
expect(tc.downloadTool).toHaveBeenCalledWith(javaRelease.url);
|
||||||
|
|
||||||
expect(require('../../src/util').extractJdkFile).toHaveBeenCalledWith(
|
expect(util.extractJdkFile).toHaveBeenCalledWith(
|
||||||
'/tmp/archive.tar.gz',
|
'/tmp/archive.tar.gz',
|
||||||
'tar.gz'
|
'tar.gz'
|
||||||
);
|
);
|
||||||
|
@ -146,11 +144,10 @@ describe('GraalVMDistribution', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify Windows-specific rename logic', () => {
|
it('should verify Windows-specific rename logic', () => {
|
||||||
const util = require('../../src/util');
|
|
||||||
const originalPath = '/tmp/archive.tar.gz';
|
const originalPath = '/tmp/archive.tar.gz';
|
||||||
const renamedPath = '/tmp/archive.tar.gz.renamed';
|
const renamedPath = '/tmp/archive.tar.gz.renamed';
|
||||||
|
|
||||||
util.renameWinArchive.mockReturnValue(renamedPath);
|
(util.renameWinArchive as jest.Mock).mockReturnValue(renamedPath);
|
||||||
|
|
||||||
const result = util.renameWinArchive(originalPath);
|
const result = util.renameWinArchive(originalPath);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue