Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Clean up changes
  • Loading branch information
Danny McCormick committed Jun 4, 2019
commit d0b97fb9974d174922a2e52284a1627f9f9016ba
41 changes: 10 additions & 31 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import installer = require('../src/installer');
import io = require('@actions/io');
import fs = require('fs')
import os = require('os')
import fs = require('fs');
import os = require('os');
import path = require('path');

const toolDir = path.join(
__dirname,
'runner',
'tools'
);
const toolDir = path.join(__dirname, 'runner', 'tools');

const tempDir = path.join(
__dirname,
'runner',
'temp'
);
const tempDir = path.join(__dirname, 'runner', 'temp');

describe('installer tests', () => {
beforeAll(() => {});
beforeAll(async () => {
// TODO - these should eventually be changed to match new method of loading dir
process.env['Runner.ToolsDirectory'] = toolDir
process.env['Runner.ToolsDirectory'] = toolDir;
process.env['Runner.TempDirectory'] = tempDir;
await io.rmRF(toolDir);
await io.rmRF(tempDir);
Expand All @@ -38,15 +30,15 @@ describe('installer tests', () => {
it('Falls back to backup location if first one doesnt contain correct version', async () => {
await installer.getNode('5.10.1');
const nodeDir = path.join(toolDir, 'node', '5.10.1', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);

it('Falls back to third location if second one doesnt contain correct version', async () => {
await installer.getNode('0.12.18');
const nodeDir = path.join(toolDir, 'node', '0.12.18', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);
Expand All @@ -71,11 +63,7 @@ describe('installer tests', () => {
}, 100000);

it('Uses version of node installed in cache', async () => {
const nodeDir: string = path.join(
toolDir,
'250.0.0',
os.arch()
);
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
Expand All @@ -84,15 +72,10 @@ describe('installer tests', () => {
});

it('Doesnt use version of node that was only partially installed in cache', async () => {
const nodeDir: string = path.join(
toolDir,
'250.0.0',
os.arch()
);
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
await io.mkdirP(nodeDir);
let thrown = false;
try {

// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getNode('251.0.0');
} catch {
Expand All @@ -103,11 +86,7 @@ describe('installer tests', () => {
});

it('Resolves semantic versions of node installed in cache', async () => {
const nodeDir: string = path.join(
toolDir,
'250.0.0',
os.arch()
);
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// These will throw if it doesn't find it in the cache (because no such version exists)
Expand Down
4 changes: 1 addition & 3 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,14 @@ function acquireNode(version) {
if (err['httpStatusCode'] && err['httpStatusCode'] === '404') {
return yield acquireNodeFromFallbackLocation(version);
}
else {
console.log('Message', err.message.statusCode);
}
throw err;
}
//
// Extract
//
let extPath;
if (osPlat == 'win32') {
let _7zPath = path.join(__dirname, '7zr.exe');
extPath = yield tc.extract7z(downloadPath);
}
else {
Expand Down
3 changes: 1 addition & 2 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ async function acquireNode(version: string): Promise<string> {
} catch (err) {
if (err['httpStatusCode'] && err['httpStatusCode'] === '404') {
return await acquireNodeFromFallbackLocation(version);
} else {
console.log('Message', err.message.statusCode);
}

throw err;
Expand All @@ -159,6 +157,7 @@ async function acquireNode(version: string): Promise<string> {
//
let extPath: string;
if (osPlat == 'win32') {
let _7zPath = path.join(__dirname, '7zr.exe');
extPath = await tc.extract7z(downloadPath);
} else {
extPath = await tc.extractTar(downloadPath);
Expand Down