mirror of https://github.com/actions/setup-node
unit tests
This commit is contained in:
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 path = __importStar(__webpack_require__(622));
|
||||||
const semver = __importStar(__webpack_require__(280));
|
const semver = __importStar(__webpack_require__(280));
|
||||||
const fs = __webpack_require__(747);
|
const fs = __webpack_require__(747);
|
||||||
|
const installer = __importStar(__webpack_require__(923));
|
||||||
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Store manifest data to avoid multiple calls
|
// 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`);
|
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (['current', 'latest', 'node'].includes(versionSpec)) {
|
if (isLatestSyntax(versionSpec)) {
|
||||||
versionSpec = yield queryDistForMatch(versionSpec, arch);
|
versionSpec = yield queryDistForMatch(versionSpec, arch);
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
}
|
}
|
||||||
|
@ -62590,10 +62591,8 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||||
}
|
}
|
||||||
let versions = [];
|
let versions = [];
|
||||||
let nodeVersions = yield getVersionsFromDist();
|
let nodeVersions = yield installer.getVersionsFromDist();
|
||||||
if (versionSpec === 'current' ||
|
if (isLatestSyntax(versionSpec)) {
|
||||||
versionSpec === 'latest' ||
|
|
||||||
versionSpec === 'node') {
|
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
return nodeVersions[0].version;
|
return nodeVersions[0].version;
|
||||||
}
|
}
|
||||||
|
@ -62692,6 +62691,9 @@ function parseNodeVersionFile(contents) {
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
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 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
|
||||||
|
@ -66,7 +67,7 @@ export async function getNode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(['current', 'latest', 'node'].includes(versionSpec)) {
|
if (isLatestSyntax(versionSpec)) {
|
||||||
versionSpec = await queryDistForMatch(versionSpec, arch);
|
versionSpec = await queryDistForMatch(versionSpec, arch);
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
}
|
}
|
||||||
|
@ -376,13 +377,9 @@ async function queryDistForMatch(
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions: string[] = [];
|
let versions: string[] = [];
|
||||||
let nodeVersions = await getVersionsFromDist();
|
let nodeVersions = await installer.getVersionsFromDist();
|
||||||
|
|
||||||
if (
|
if (isLatestSyntax(versionSpec)) {
|
||||||
versionSpec === 'current' ||
|
|
||||||
versionSpec === 'latest' ||
|
|
||||||
versionSpec === 'node'
|
|
||||||
) {
|
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
return nodeVersions[0].version;
|
return nodeVersions[0].version;
|
||||||
}
|
}
|
||||||
|
@ -487,3 +484,7 @@ export function parseNodeVersionFile(contents: string): string {
|
||||||
}
|
}
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLatestSyntax(versionSpec): boolean {
|
||||||
|
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue