mirror of
https://github.com/actions/setup-node
synced 2025-04-09 10:25:52 +00:00
Clean up from review and add nock for test validation
This commit is contained in:
parent
3d0361d465
commit
c08e62dd1d
9 changed files with 137 additions and 8 deletions
BIN
__tests__/__fixtures__/mock-node-v8.8.0-linux-x86.tar.gz
Normal file
BIN
__tests__/__fixtures__/mock-node-v8.8.0-linux-x86.tar.gz
Normal file
Binary file not shown.
BIN
__tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z
Normal file
BIN
__tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z
Normal file
Binary file not shown.
BIN
__tests__/__fixtures__/mock-node-v8.9.1-linux-x64.tar.gz
Normal file
BIN
__tests__/__fixtures__/mock-node-v8.9.1-linux-x64.tar.gz
Normal file
Binary file not shown.
BIN
__tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z
Normal file
BIN
__tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z
Normal file
Binary file not shown.
|
@ -1,5 +1,6 @@
|
|||
import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import nock = require('nock');
|
||||
import os = require('os');
|
||||
import path = require('path');
|
||||
|
||||
|
@ -36,6 +37,10 @@ describe('installer tests', () => {
|
|||
await io.rmRF(tempDir);
|
||||
}, 100000);
|
||||
|
||||
beforeEach(() => {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('Acquires version of node if no matching version is installed', async () => {
|
||||
await installer.getNode('10.16.0');
|
||||
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());
|
||||
|
@ -123,9 +128,25 @@ describe('installer tests', () => {
|
|||
|
||||
it('Acquires specified x86 version of node if no matching version is installed', async () => {
|
||||
const arch = 'x86';
|
||||
await installer.getNode('8.8.1', arch);
|
||||
const nodeDir = path.join(toolDir, 'node', '8.8.1', arch);
|
||||
const version = '8.8.0';
|
||||
const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz';
|
||||
const platform = {
|
||||
linux: 'linux',
|
||||
darwin: 'darwin',
|
||||
win32: 'win'
|
||||
}[process.platform];
|
||||
const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`;
|
||||
const pathOnNodeJs = `/dist/v${version}/${fileName}`;
|
||||
const scope = nock('https://nodejs.org')
|
||||
.get(pathOnNodeJs)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
|
||||
);
|
||||
await installer.getNode(version, arch);
|
||||
const nodeDir = path.join(toolDir, 'node', version, arch);
|
||||
|
||||
expect(scope.isDone()).toBe(true);
|
||||
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
|
||||
|
@ -136,9 +157,25 @@ describe('installer tests', () => {
|
|||
|
||||
it('Acquires specified x64 version of node if no matching version is installed', async () => {
|
||||
const arch = 'x64';
|
||||
await installer.getNode('8.8.1', arch);
|
||||
const nodeDir = path.join(toolDir, 'node', '8.8.1', arch);
|
||||
const version = '8.9.1';
|
||||
const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz';
|
||||
const platform = {
|
||||
linux: 'linux',
|
||||
darwin: 'darwin',
|
||||
win32: 'win'
|
||||
}[process.platform];
|
||||
const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`;
|
||||
const pathOnNodeJs = `/dist/v${version}/${fileName}`;
|
||||
const scope = nock('https://nodejs.org')
|
||||
.get(pathOnNodeJs)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
|
||||
);
|
||||
await installer.getNode(version, arch);
|
||||
const nodeDir = path.join(toolDir, 'node', version, arch);
|
||||
|
||||
expect(scope.isDone()).toBe(true);
|
||||
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
|
||||
|
|
|
@ -31,8 +31,8 @@ function run() {
|
|||
if (!version) {
|
||||
version = core.getInput('node-version');
|
||||
}
|
||||
const osArch = core.getInput('node-arch') || os.arch();
|
||||
if (version) {
|
||||
const osArch = core.getInput('node-arch') || os.arch();
|
||||
// TODO: installer doesn't support proxy
|
||||
yield installer.getNode(version, osArch);
|
||||
}
|
||||
|
|
90
package-lock.json
generated
90
package-lock.json
generated
|
@ -821,6 +821,12 @@
|
|||
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=",
|
||||
"dev": true
|
||||
},
|
||||
"assertion-error": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
|
||||
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
|
||||
"dev": true
|
||||
},
|
||||
"assign-symbols": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz",
|
||||
|
@ -1149,6 +1155,20 @@
|
|||
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=",
|
||||
"dev": true
|
||||
},
|
||||
"chai": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
|
||||
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assertion-error": "^1.1.0",
|
||||
"check-error": "^1.0.2",
|
||||
"deep-eql": "^3.0.1",
|
||||
"get-func-name": "^2.0.0",
|
||||
"pathval": "^1.1.0",
|
||||
"type-detect": "^4.0.5"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
||||
|
@ -1160,6 +1180,12 @@
|
|||
"supports-color": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"check-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
|
||||
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
|
||||
"dev": true
|
||||
},
|
||||
"ci-info": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
|
||||
|
@ -1403,6 +1429,15 @@
|
|||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
||||
"dev": true
|
||||
},
|
||||
"deep-eql": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
|
||||
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"type-detect": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"deep-is": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
|
||||
|
@ -2423,6 +2458,12 @@
|
|||
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
||||
"dev": true
|
||||
},
|
||||
"get-func-name": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
|
||||
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
|
||||
"dev": true
|
||||
},
|
||||
"get-stdin": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-7.0.0.tgz",
|
||||
|
@ -3895,6 +3936,37 @@
|
|||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
||||
},
|
||||
"nock": {
|
||||
"version": "11.3.5",
|
||||
"resolved": "https://registry.npmjs.org/nock/-/nock-11.3.5.tgz",
|
||||
"integrity": "sha512-6WGeZcWc3RExkBcMSYSrUm/5YukDo52m/jhwniQyrnuiCnKRljBwwje9vTwJyEi4J6m2bq0Aj6C1vzuM6iuaeg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chai": "^4.1.2",
|
||||
"debug": "^4.1.0",
|
||||
"json-stringify-safe": "^5.0.1",
|
||||
"lodash": "^4.17.13",
|
||||
"mkdirp": "^0.5.0",
|
||||
"propagate": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
|
@ -4236,6 +4308,12 @@
|
|||
"pify": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"pathval": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
|
||||
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
|
||||
"dev": true
|
||||
},
|
||||
"performance-now": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||
|
@ -4363,6 +4441,12 @@
|
|||
"sisteransi": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"propagate": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz",
|
||||
"integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==",
|
||||
"dev": true
|
||||
},
|
||||
"psl": {
|
||||
"version": "1.1.33",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.33.tgz",
|
||||
|
@ -5247,6 +5331,12 @@
|
|||
"prelude-ls": "~1.1.2"
|
||||
}
|
||||
},
|
||||
"type-detect": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
|
||||
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
|
||||
"dev": true
|
||||
},
|
||||
"type-fest": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.4.1.tgz",
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
"@actions/github": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/tool-cache": "^1.0.0",
|
||||
"typed-rest-client": "^1.5.0",
|
||||
"semver": "^6.1.1"
|
||||
"semver": "^6.1.1",
|
||||
"typed-rest-client": "^1.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
|
@ -36,6 +36,7 @@
|
|||
"husky": "^2.3.0",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"nock": "^11.3.5",
|
||||
"prettier": "^1.17.1",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.5.1"
|
||||
|
|
|
@ -14,8 +14,9 @@ async function run() {
|
|||
if (!version) {
|
||||
version = core.getInput('node-version');
|
||||
}
|
||||
const osArch = core.getInput('node-arch') || os.arch();
|
||||
|
||||
if (version) {
|
||||
const osArch = core.getInput('node-arch') || os.arch();
|
||||
// TODO: installer doesn't support proxy
|
||||
await installer.getNode(version, osArch);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue