test: add arch tests

Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com>

feat: add nock

Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com>
This commit is contained in:
Amin Yahyaabadi 2020-09-03 08:47:25 -05:00
parent 66f3e9f7ce
commit 7a3669aa8a
7 changed files with 83 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,7 @@ import * as main from '../src/main';
import * as im from '../src/installer'; import * as im from '../src/installer';
import * as auth from '../src/authutil'; import * as auth from '../src/authutil';
import {context} from '@actions/github'; import {context} from '@actions/github';
import nock = require('nock');
let nodeTestManifest = require('./data/versions-manifest.json'); let nodeTestManifest = require('./data/versions-manifest.json');
let nodeTestDist = require('./data/node-dist-index.json'); let nodeTestDist = require('./data/node-dist-index.json');
@ -337,6 +338,52 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
}); });
it('Acquires specified x64 or x86 version of node if no matching version is installed', async () => {
const toolDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'tools'
);
os.platform = process.platform;
const IS_WINDOWS = os.platform === 'win32';
for (const {arch, version} of [
{arch: 'x64', version: '12.18.3'},
{arch: 'x86', version: '12.18.3'}
]) {
nock.cleanAll();
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('nodejs.org')
.get(pathOnNodeJs)
.replyWithFile(
200,
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
);
await im.getNode(version, true, true, undefined, 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);
} else {
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
}
}
}, 100000);
describe('check-latest flag', () => { describe('check-latest flag', () => {
it('use local version and dont check manifest if check-latest is not specified', async () => { it('use local version and dont check manifest if check-latest is not specified', async () => {
os.platform = 'linux'; os.platform = 'linux';

35
package-lock.json generated
View File

@ -6577,6 +6577,35 @@
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
}, },
"nock": {
"version": "13.0.4",
"resolved": "https://registry.npmjs.org/nock/-/nock-13.0.4.tgz",
"integrity": "sha512-alqTV8Qt7TUbc74x1pKRLSENzfjp4nywovcJgi/1aXDiUxXdt7TkruSTF5MDWPP7UoPVgea4F9ghVdmX0xxnSA==",
"dev": true,
"requires": {
"debug": "^4.1.0",
"json-stringify-safe": "^5.0.1",
"lodash.set": "^4.3.2",
"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": { "node-fetch": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
@ -6945,6 +6974,12 @@
"sisteransi": "^1.0.4" "sisteransi": "^1.0.4"
} }
}, },
"propagate": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz",
"integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==",
"dev": true
},
"psl": { "psl": {
"version": "1.8.0", "version": "1.8.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",

View File

@ -38,6 +38,7 @@
"@zeit/ncc": "^0.21.0", "@zeit/ncc": "^0.21.0",
"jest": "^24.9.0", "jest": "^24.9.0",
"jest-circus": "^24.7.1", "jest-circus": "^24.7.1",
"nock": "^13.0.4",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"ts-jest": "^24.3.0", "ts-jest": "^24.3.0",
"typescript": "^3.8.3" "typescript": "^3.8.3"