1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2025-03-31 14:20:59 +00:00

checks update

This commit is contained in:
Aparna Jyothi 2025-02-27 18:20:13 +05:30
parent d61dc50c40
commit dd2fa9d9f8
5 changed files with 5 additions and 141 deletions

View file

@ -82,8 +82,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
node-version:
[20.11.0-nightly202312211a0be537da, 21-nightly, 18.0.0-nightly]
node-version: [20.12.0-nightly, 21-nightly, 18.0.0-nightly]
steps:
- uses: actions/checkout@v4
- name: Setup Node

View file

@ -14,12 +14,6 @@ import * as main from '../src/main';
import * as util from '../src/util';
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
import * as installerFactory from '../src/distributions/installer-factory';
jest.mock('../src/distributions/installer-factory', () => ({
getNodejsDistribution: jest.fn()
}));
import {validateMirrorURL} from '../src/util';
describe('main tests', () => {
let inputs = {} as any;
let os = {} as any;
@ -44,8 +38,6 @@ describe('main tests', () => {
let setupNodeJsSpy: jest.SpyInstance;
let validateMirrorUrlSpy: jest.SpyInstance;
beforeEach(() => {
inputs = {};
@ -173,45 +165,6 @@ describe('main tests', () => {
});
});
describe('getNodeVersionFromFile', () => {
each`
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'lts/*'} | ${'lts/*'}
${'nodejs 12.3.4'} | ${'12.3.4'}
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
${''} | ${''}
${'unknown format'} | ${'unknown format'}
${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => {
const existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(filePath => {
if (
typeof filePath === 'string' &&
path.basename(filePath) === 'package.json'
) {
// Special case for volta.extends
return '{"volta": {"node": "18.0.0"}}';
}
return contents;
});
expect(util.getNodeVersionFromFile('file')).toBe(expected);
});
});
describe('node-version-file flag', () => {
beforeEach(() => {
delete inputs['node-version'];
@ -327,41 +280,4 @@ describe('main tests', () => {
);
});
});
describe('mirror-url parameter', () => {
beforeEach(() => {
inputs['mirror-url'] = 'https://custom-mirror-url.com';
validateMirrorUrlSpy = jest.spyOn(main, 'run');
validateMirrorUrlSpy.mockImplementation(() => {});
});
afterEach(() => {
validateMirrorUrlSpy.mockRestore();
});
it('Read mirror-url if mirror-url is provided', async () => {
// Arrange
inputs['mirror-url'] = 'https://custom-mirror-url.com';
// Act
await main.run();
// Assert
expect(inputs['mirror-url']).toBeDefined();
});
it('should throw an error if mirror-url is empty', async () => {
// Arrange
inputs['mirror-url'] = ' ';
// Mock log and setFailed
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); // Mock the log function
// Act & Assert
expect(() => validateMirrorURL(inputs['mirror-url'])).toThrow(
'Mirror URL is empty. Please provide a valid mirror URL.'
);
});
});
});

View file

@ -831,52 +831,7 @@ describe('setup-node', () => {
);
});
describe('mirror-url parameter', () => {
it('Download mirror url if mirror-url is provided', async () => {
// Set up test inputs and environment
os.platform = 'linux';
os.arch = 'x64';
inputs['check-latest'] = 'true';
const mirrorURL = (inputs['mirror-url'] =
'https://custom-mirror-url.com');
inputs['token'] = 'faketoken';
// Mock that the version is not in cache (simulate a fresh download)
findSpy.mockImplementation(() => '');
// Mock implementations for other dependencies
const toolPath = path.normalize('/cache/node/11.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
const dlmirrorSpy = jest.fn(); // Create a spy to track the download logic
const mockDownloadNodejs = jest
.spyOn(OfficialBuilds.prototype as any, 'downloadFromMirrorURL')
.mockImplementation(async () => {
dlmirrorSpy();
});
// Run the main method or your logic that invokes `downloadFromMirrorURL`
await main.run(); // This should internally call `downloadFromMirrorURL`
// Prepare the expected path after download
const expPath = path.join(toolPath, 'bin');
// Assert that the spy was called, meaning the download logic was triggered
expect(dlmirrorSpy).toHaveBeenCalled(); // This verifies that the download occurred
// Other assertions to verify the flow
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download from ${mirrorURL}...`
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
// Clean up mocks after the test
mockDownloadNodejs.mockRestore(); // Ensure to restore the original method after the test
});
it('fallback to default if mirror url is not provided', async () => {
it('default if mirror url is not provided', async () => {
os.platform = 'linux';
os.arch = 'x64';

3
dist/setup/index.js vendored
View file

@ -100870,8 +100870,7 @@ function run() {
if (!arch) {
arch = os_1.default.arch();
}
const mirrorurl = core.getInput('mirror-url');
const mirrorURL = (0, util_1.validateMirrorURL)(mirrorurl);
const mirrorURL = core.getInput('mirror-url');
if (version) {
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;

View file

@ -7,11 +7,7 @@ import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory';
import {
getNodeVersionFromFile,
printEnvDetailsAndSetOutput,
validateMirrorURL
} from './util';
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
import {State} from './constants';
export async function run() {
@ -37,8 +33,7 @@ export async function run() {
arch = os.arch();
}
const mirrorurl = core.getInput('mirror-url');
const mirrorURL = validateMirrorURL(mirrorurl);
const mirrorURL = core.getInput('mirror-url');
if (version) {
const token = core.getInput('token');