Skip to content

Commit 5766020

Browse files
aminyaimplausible
andcommitted
feat: add arch tests
Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com>
1 parent b717376 commit 5766020

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed
Binary file not shown.
211 Bytes
Binary file not shown.
Binary file not shown.
213 Bytes
Binary file not shown.

__tests__/installer.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as main from '../src/main';
99
import * as im from '../src/installer';
1010
import * as auth from '../src/authutil';
1111
import {context} from '@actions/github';
12+
import nock = require('nock');
1213

1314
let nodeTestManifest = require('./data/versions-manifest.json');
1415
let nodeTestDist = require('./data/node-dist-index.json');
@@ -40,7 +41,20 @@ describe('setup-node', () => {
4041
let execSpy: jest.SpyInstance;
4142
let authSpy: jest.SpyInstance;
4243

44+
const IS_WINDOWS = process.platform === 'win32';
45+
const toolDir = path.join(
46+
__dirname,
47+
'runner',
48+
path.join(
49+
Math.random()
50+
.toString(36)
51+
.substring(7)
52+
),
53+
'tools'
54+
);
55+
4356
beforeEach(() => {
57+
nock.cleanAll();
4458
// @actions/core
4559
inputs = {};
4660
inSpy = jest.spyOn(core, 'getInput');
@@ -337,6 +351,64 @@ describe('setup-node', () => {
337351
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
338352
});
339353

354+
it('Acquires specified x86 version of node if no matching version is installed', async () => {
355+
const arch = 'x86';
356+
const version = '8.8.0';
357+
const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz';
358+
const platform = {
359+
linux: 'linux',
360+
darwin: 'darwin',
361+
win32: 'win'
362+
}[process.platform];
363+
const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`;
364+
const pathOnNodeJs = `/dist/v${version}/${fileName}`;
365+
const scope = nock('nodejs.org')
366+
.get(pathOnNodeJs)
367+
.replyWithFile(
368+
200,
369+
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
370+
);
371+
await im.getNode(version, true, true, arch);
372+
const nodeDir = path.join(toolDir, 'node', version, arch);
373+
374+
expect(scope.isDone()).toBe(true);
375+
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
376+
if (IS_WINDOWS) {
377+
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
378+
} else {
379+
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
380+
}
381+
}, 100000);
382+
383+
it('Acquires specified x64 version of node if no matching version is installed', async () => {
384+
const arch = 'x64';
385+
const version = '8.9.1';
386+
const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz';
387+
const platform = {
388+
linux: 'linux',
389+
darwin: 'darwin',
390+
win32: 'win'
391+
}[process.platform];
392+
const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`;
393+
const pathOnNodeJs = `/dist/v${version}/${fileName}`;
394+
const scope = nock('nodejs.org')
395+
.get(pathOnNodeJs)
396+
.replyWithFile(
397+
200,
398+
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
399+
);
400+
await im.getNode(version, true, true, arch);
401+
const nodeDir = path.join(toolDir, 'node', version, arch);
402+
403+
expect(scope.isDone()).toBe(true);
404+
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
405+
if (IS_WINDOWS) {
406+
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
407+
} else {
408+
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
409+
}
410+
}, 100000);
411+
340412
describe('check-latest flag', () => {
341413
it('use local version and dont check manifest if check-latest is not specified', async () => {
342414
os.platform = 'linux';

0 commit comments

Comments
 (0)