diff --git a/__tests__/__fixtures__/mock-node-v8.8.0-linux-x86.tar.gz b/__tests__/__fixtures__/mock-node-v8.8.0-linux-x86.tar.gz new file mode 100644 index 000000000..fd88664a8 Binary files /dev/null and b/__tests__/__fixtures__/mock-node-v8.8.0-linux-x86.tar.gz differ diff --git a/__tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z b/__tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z new file mode 100644 index 000000000..9a16b0912 Binary files /dev/null and b/__tests__/__fixtures__/mock-node-v8.8.0-win-x86.7z differ diff --git a/__tests__/__fixtures__/mock-node-v8.9.1-linux-x64.tar.gz b/__tests__/__fixtures__/mock-node-v8.9.1-linux-x64.tar.gz new file mode 100644 index 000000000..3a4824456 Binary files /dev/null and b/__tests__/__fixtures__/mock-node-v8.9.1-linux-x64.tar.gz differ diff --git a/__tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z b/__tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z new file mode 100644 index 000000000..dda8188f3 Binary files /dev/null and b/__tests__/__fixtures__/mock-node-v8.9.1-win-x64.7z differ diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 6f3a411eb..71b7b8058 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'); @@ -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'); @@ -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';