From 7a3669aa8ae68a57ad9dfab3ea5293570132ad5a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Sep 2020 08:47:25 -0500 Subject: [PATCH] test: add arch tests Co-Authored-By: Tyler Ang-Wanek feat: add nock Co-Authored-By: Tyler Ang-Wanek --- .../mock-node-v12.18.3-linux-x64.tar.gz | Bin 0 -> 205 bytes .../mock-node-v12.18.3-linux-x86.tar.gz | Bin 0 -> 205 bytes .../mock-node-v12.18.3-win-x64.7z | Bin 0 -> 210 bytes .../mock-node-v12.18.3-win-x86.7z | Bin 0 -> 209 bytes __tests__/installer.test.ts | 47 ++++++++++++++++++ package-lock.json | 35 +++++++++++++ package.json | 1 + 7 files changed, 83 insertions(+) create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-linux-x86.tar.gz create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z create mode 100644 __tests__/__fixtures__/mock-node-v12.18.3-win-x86.7z diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz b/__tests__/__fixtures__/mock-node-v12.18.3-linux-x64.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..50c8dd35e5e4461cd7af5255b6936650b2a27537 GIT binary patch literal 205 zcmV;;05bm{iwFpe{ZL;70B&z&Wi56wGA=PVE;B7`X>N6REqFFGE_7jX0PWJ<3c?^1 z!0~h4Q}_Z~o)2fQvz5?bIA|{R__-jWiw1#s(flDCK`(^Ae!RHqj#T5R=4$Buyi`jg zM@UF((bn2HpFZYmk8Fg+n1%>6q9FlgAcJ`d?G54!_UT*yuJ_6Qzz_Y!%G#gEHl=?K zTm9EFNI;|B?$7k@Z#dp(6b6;0$N6REqFLKE_7jX0PWI23d0}} zK+#$E6kZ_djH5BvNm`+SV4yL@7s#xxJY~mBj`f-y6I}G2g#b+nyYbeOQ=HI zoFO4Zg~pgTU%uvhPplOyts5x;i8Lb!4H+!6@9q#^a7@4Y_k&CJ2ma` H01N;CUO`&6 literal 0 HcmV?d00001 diff --git a/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z b/__tests__/__fixtures__/mock-node-v12.18.3-win-x64.7z new file mode 100644 index 0000000000000000000000000000000000000000..f5ecfd4d27762e53124841feb8573bf3c5e414e6 GIT binary patch literal 210 zcmXr7+Ou9=hJodcb&|+L1_)4u(sM7dc{4IdmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewy_`Ue9Z~!_!3W3okpj)SkTZ)c%_5_Kz(Q z&77z2I@n**sJVQu-HYuh+h=h$IY!Q626k>n21aFOMn=|H1_1^Jo`!u~jFuVYbu+1_)4u(%y?dX)`iNmSkiWD*#bmeu+Y2o59? zaH-Z2-nqJO?rt|d^Tz76?uny4NAef{ewz0v=Iz_ZY0_TP%UnZ)O17`P`|-q0zG8O! zvJ8X8bG$fZ){5x+FY-5hC(b6v$XUd|&dtccsLagB$QsKaz`(%Mu#byT?%u^|3=9DO C literal 0 HcmV?d00001 diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index b1e3cb0c..8007952a 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -9,6 +9,7 @@ import * as main from '../src/main'; import * as im from '../src/installer'; import * as auth from '../src/authutil'; import {context} from '@actions/github'; +import nock = require('nock'); let nodeTestManifest = require('./data/versions-manifest.json'); let nodeTestDist = require('./data/node-dist-index.json'); @@ -337,6 +338,52 @@ describe('setup-node', () => { 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', () => { it('use local version and dont check manifest if check-latest is not specified', async () => { os.platform = 'linux'; diff --git a/package-lock.json b/package-lock.json index be7fec2d..4f5279b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6577,6 +6577,35 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "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": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -6945,6 +6974,12 @@ "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": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", diff --git a/package.json b/package.json index 9a3f1c57..c80fa0c7 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^24.9.0", "jest-circus": "^24.7.1", + "nock": "^13.0.4", "prettier": "^1.19.1", "ts-jest": "^24.3.0", "typescript": "^3.8.3"