Skip to content

Commit

Permalink
feat: add arch tests
Browse files Browse the repository at this point in the history
Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com>
  • Loading branch information
aminya and implausible committed Sep 3, 2020
1 parent b717376 commit 5766020
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 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.
72 changes: 72 additions & 0 deletions __tests__/installer.test.ts
Expand Up @@ -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');
Expand Down Expand Up @@ -40,7 +41,20 @@ describe('setup-node', () => {
let execSpy: jest.SpyInstance;
let authSpy: jest.SpyInstance;

const IS_WINDOWS = process.platform === 'win32';
const toolDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'tools'
);

beforeEach(() => {
nock.cleanAll();
// @actions/core
inputs = {};
inSpy = jest.spyOn(core, 'getInput');
Expand Down Expand Up @@ -337,6 +351,64 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
});

it('Acquires specified x86 version of node if no matching version is installed', async () => {
const arch = 'x86';
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('nodejs.org')
.get(pathOnNodeJs)
.replyWithFile(
200,
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
);
await im.getNode(version, true, true, 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);

it('Acquires specified x64 version of node if no matching version is installed', async () => {
const arch = 'x64';
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('nodejs.org')
.get(pathOnNodeJs)
.replyWithFile(
200,
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
);
await im.getNode(version, true, true, 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';
Expand Down

0 comments on commit 5766020

Please sign in to comment.