Skip to content

Commit

Permalink
Clean up from review and add nock for test validation
Browse files Browse the repository at this point in the history
  • Loading branch information
implausible committed Sep 27, 2019
1 parent 3d0361d commit c08e62d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 10 deletions.
Binary file not shown.
Binary file added __tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z
Binary file not shown.
Binary file not shown.
Binary file added __tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z
Binary file not shown.
49 changes: 43 additions & 6 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/setup-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
90 changes: 90 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/setup-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c08e62d

Please sign in to comment.