unit tests
parent
9a03ebd9cc
commit
fd1b409bc3
|
@ -913,4 +913,31 @@ describe('setup-node', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('latest alias syntax from cache', () => {
|
||||
it.each(['latest', 'current', 'node'])(
|
||||
'download the %s version if alias is provided',
|
||||
async inputVersion => {
|
||||
// Arrange
|
||||
inputs['node-version'] = inputVersion;
|
||||
const expectedVersion = nodeTestDist[0];
|
||||
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
|
||||
const toolPath = path.normalize(
|
||||
`/cache/node/${expectedVersion.version}/x64`
|
||||
);
|
||||
findSpy.mockReturnValue(toolPath);
|
||||
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
// assert
|
||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -62339,6 +62339,7 @@ const tc = __importStar(__webpack_require__(533));
|
|||
const path = __importStar(__webpack_require__(622));
|
||||
const semver = __importStar(__webpack_require__(280));
|
||||
const fs = __webpack_require__(747);
|
||||
const installer = __importStar(__webpack_require__(923));
|
||||
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Store manifest data to avoid multiple calls
|
||||
|
@ -62362,7 +62363,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
|||
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
||||
}
|
||||
}
|
||||
if (['current', 'latest', 'node'].includes(versionSpec)) {
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
versionSpec = yield queryDistForMatch(versionSpec, arch);
|
||||
core.info(`getting latest node version...`);
|
||||
}
|
||||
|
@ -62590,10 +62591,8 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
|
|||
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||
}
|
||||
let versions = [];
|
||||
let nodeVersions = yield getVersionsFromDist();
|
||||
if (versionSpec === 'current' ||
|
||||
versionSpec === 'latest' ||
|
||||
versionSpec === 'node') {
|
||||
let nodeVersions = yield installer.getVersionsFromDist();
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
core.info(`getting latest node version...`);
|
||||
return nodeVersions[0].version;
|
||||
}
|
||||
|
@ -62692,6 +62691,9 @@ function parseNodeVersionFile(contents) {
|
|||
return nodeVersion;
|
||||
}
|
||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||
function isLatestSyntax(versionSpec) {
|
||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -7,6 +7,7 @@ import * as tc from '@actions/tool-cache';
|
|||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import fs = require('fs');
|
||||
import * as installer from './installer';
|
||||
|
||||
//
|
||||
// Node versions interface
|
||||
|
@ -66,7 +67,7 @@ export async function getNode(
|
|||
}
|
||||
}
|
||||
|
||||
if(['current', 'latest', 'node'].includes(versionSpec)) {
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
versionSpec = await queryDistForMatch(versionSpec, arch);
|
||||
core.info(`getting latest node version...`);
|
||||
}
|
||||
|
@ -376,13 +377,9 @@ async function queryDistForMatch(
|
|||
}
|
||||
|
||||
let versions: string[] = [];
|
||||
let nodeVersions = await getVersionsFromDist();
|
||||
let nodeVersions = await installer.getVersionsFromDist();
|
||||
|
||||
if (
|
||||
versionSpec === 'current' ||
|
||||
versionSpec === 'latest' ||
|
||||
versionSpec === 'node'
|
||||
) {
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
core.info(`getting latest node version...`);
|
||||
return nodeVersions[0].version;
|
||||
}
|
||||
|
@ -487,3 +484,7 @@ export function parseNodeVersionFile(contents: string): string {
|
|||
}
|
||||
return nodeVersion;
|
||||
}
|
||||
|
||||
function isLatestSyntax(versionSpec): boolean {
|
||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue