mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 17:26:27 +00:00
add unit tests
This commit is contained in:
parent
983e751c52
commit
fdd541042b
2 changed files with 48 additions and 6 deletions
|
@ -909,4 +909,44 @@ describe('setup-node', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('latest alias syntax', () => {
|
||||||
|
it.each(['latest', 'current', 'node'])('download the %s version if alias is provided', async (inputVersion) => {
|
||||||
|
// Arrange
|
||||||
|
inputs['node-version'] = inputVersion;
|
||||||
|
|
||||||
|
os.platform = 'darwin';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
const expectedVersion = nodeTestDist[0];
|
||||||
|
|
||||||
|
let expectedUrl = `https://nodejs.org/dist/${expectedVersion.version}/node-${expectedVersion.version}-${os.platform}-${os.arch}.tar.gz`;
|
||||||
|
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
getManifestSpy.mockImplementation(() => {
|
||||||
|
throw new Error('Unable to download manifest');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Attempting to download ${inputVersion}...`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Unable to download manifest'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'getting latest node version...'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Acquiring ${expectedVersion.version.substring(1, expectedVersion.version.length)} - ${os.arch} from ${expectedUrl}`
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ import * as tc from '@actions/tool-cache';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
|
import * as installer from './installer';
|
||||||
|
|
||||||
//
|
//
|
||||||
// Node versions interface
|
// Node versions interface
|
||||||
|
@ -237,7 +238,7 @@ function resolveLtsAliasFromManifest(
|
||||||
return release.version.split('.')[0];
|
return release.version.split('.')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInfoFromManifest(
|
export async function getInfoFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined,
|
||||||
|
@ -263,7 +264,7 @@ async function getInfoFromManifest(
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInfoFromDist(
|
export async function getInfoFromDist(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string = os.arch()
|
arch: string = os.arch()
|
||||||
): Promise<INodeVersionInfo | null> {
|
): Promise<INodeVersionInfo | null> {
|
||||||
|
@ -320,7 +321,7 @@ async function resolveVersionFromManifest(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
||||||
function evaluateVersions(versions: string[], versionSpec: string): string {
|
export function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
let version = '';
|
let version = '';
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
versions = versions.sort((a, b) => {
|
versions = versions.sort((a, b) => {
|
||||||
|
@ -347,7 +348,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queryDistForMatch(
|
export async function queryDistForMatch(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string = os.arch()
|
arch: string = os.arch()
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
@ -371,10 +372,11 @@ async function queryDistForMatch(
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions: string[] = [];
|
let versions: string[] = [];
|
||||||
let nodeVersions = await getVersionsFromDist();
|
let nodeVersions = await installer.getVersionsFromDist();
|
||||||
|
|
||||||
if (versionSpec === 'current' || versionSpec === 'latest' || versionSpec === 'node') {
|
if (versionSpec === 'current' || versionSpec === 'latest' || versionSpec === 'node') {
|
||||||
return nodeVersions[0].version
|
core.info(`getting latest node version...`);
|
||||||
|
return nodeVersions[0].version;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue