Skip to content

Commit 7a3669a

Browse files
aminyaimplausible
andcommitted
test: add arch tests
Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com> feat: add nock Co-Authored-By: Tyler Ang-Wanek <tylerw@axosoft.com>
1 parent 66f3e9f commit 7a3669a

7 files changed

+83
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

__tests__/installer.test.ts

Lines changed: 47 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');
@@ -337,6 +338,52 @@ describe('setup-node', () => {
337338
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
338339
});
339340

341+
it('Acquires specified x64 or x86 version of node if no matching version is installed', async () => {
342+
const toolDir = path.join(
343+
__dirname,
344+
'runner',
345+
path.join(
346+
Math.random()
347+
.toString(36)
348+
.substring(7)
349+
),
350+
'tools'
351+
);
352+
353+
os.platform = process.platform;
354+
const IS_WINDOWS = os.platform === 'win32';
355+
for (const {arch, version} of [
356+
{arch: 'x64', version: '12.18.3'},
357+
{arch: 'x86', version: '12.18.3'}
358+
]) {
359+
nock.cleanAll();
360+
const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz';
361+
const platform = {
362+
linux: 'linux',
363+
darwin: 'darwin',
364+
win32: 'win'
365+
}[process.platform];
366+
const fileName = `node-v${version}-${platform}-${arch}.${fileExtension}`;
367+
const pathOnNodeJs = `/dist/v${version}/${fileName}`;
368+
const scope = nock('nodejs.org')
369+
.get(pathOnNodeJs)
370+
.replyWithFile(
371+
200,
372+
path.join(__dirname, '__fixtures__', `mock-${fileName}`)
373+
);
374+
await im.getNode(version, true, true, undefined, arch);
375+
const nodeDir = path.join(toolDir, 'node', version, arch);
376+
377+
expect(scope.isDone()).toBe(true);
378+
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
379+
if (IS_WINDOWS) {
380+
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
381+
} else {
382+
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
383+
}
384+
}
385+
}, 100000);
386+
340387
describe('check-latest flag', () => {
341388
it('use local version and dont check manifest if check-latest is not specified', async () => {
342389
os.platform = 'linux';

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@zeit/ncc": "^0.21.0",
3939
"jest": "^24.9.0",
4040
"jest-circus": "^24.7.1",
41+
"nock": "^13.0.4",
4142
"prettier": "^1.19.1",
4243
"ts-jest": "^24.3.0",
4344
"typescript": "^3.8.3"

0 commit comments

Comments
 (0)