|
1 | | -import io = require('@actions/io'); |
2 | | -import fs = require('fs'); |
3 | | -import os = require('os'); |
4 | | -import path = require('path'); |
5 | | - |
6 | | -const toolDir = path.join( |
7 | | - __dirname, |
8 | | - 'runner', |
9 | | - path.join( |
10 | | - Math.random() |
11 | | - .toString(36) |
12 | | - .substring(7) |
13 | | - ), |
14 | | - 'tools' |
15 | | -); |
16 | | -const tempDir = path.join( |
17 | | - __dirname, |
18 | | - 'runner', |
19 | | - path.join( |
20 | | - Math.random() |
21 | | - .toString(36) |
22 | | - .substring(7) |
23 | | - ), |
24 | | - 'temp' |
25 | | -); |
26 | | - |
27 | | -process.env['RUNNER_TOOL_CACHE'] = toolDir; |
28 | | -process.env['RUNNER_TEMP'] = tempDir; |
| 1 | +import * as io from '@actions/io'; |
| 2 | +import * as tc from '@actions/tool-cache'; |
| 3 | +import * as fs from 'fs'; |
| 4 | +import * as os from 'os'; |
| 5 | +import * as path from 'path'; |
29 | 6 | import * as installer from '../src/installer'; |
30 | 7 |
|
31 | | -const IS_WINDOWS = process.platform === 'win32'; |
| 8 | +const isWindows = process.platform === 'win32'; |
| 9 | +let toolDir: string; |
32 | 10 |
|
33 | 11 | describe('installer tests', () => { |
34 | 12 | beforeAll(async () => { |
| 13 | + toolDir = path.join( |
| 14 | + __dirname, |
| 15 | + 'runner', |
| 16 | + path.join( |
| 17 | + Math.random() |
| 18 | + .toString(36) |
| 19 | + .substring(7) |
| 20 | + ), |
| 21 | + 'tools' |
| 22 | + ); |
| 23 | + const tempDir = path.join( |
| 24 | + __dirname, |
| 25 | + 'runner', |
| 26 | + path.join( |
| 27 | + Math.random() |
| 28 | + .toString(36) |
| 29 | + .substring(7) |
| 30 | + ), |
| 31 | + 'temp' |
| 32 | + ); |
35 | 33 | await io.rmRF(toolDir); |
36 | 34 | await io.rmRF(tempDir); |
| 35 | + process.env['RUNNER_TOOL_CACHE'] = toolDir; |
| 36 | + process.env['RUNNER_TEMP'] = tempDir; |
37 | 37 | }, 100000); |
38 | 38 |
|
39 | 39 | it('Acquires version of node if no matching version is installed', async () => { |
40 | 40 | await installer.getNode('10.16.0'); |
41 | 41 | const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch()); |
42 | 42 |
|
43 | 43 | expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); |
44 | | - if (IS_WINDOWS) { |
| 44 | + if (isWindows) { |
45 | 45 | expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); |
46 | 46 | } else { |
47 | 47 | expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); |
48 | 48 | } |
49 | 49 | }, 100000); |
50 | 50 |
|
51 | | - if (IS_WINDOWS) { |
| 51 | + if (isWindows) { |
52 | 52 | it('Falls back to backup location if first one doesnt contain correct version', async () => { |
53 | 53 | await installer.getNode('5.10.1'); |
54 | 54 | const nodeDir = path.join(toolDir, 'node', '5.10.1', os.arch()); |
@@ -81,7 +81,7 @@ describe('installer tests', () => { |
81 | 81 | const nodeDir = path.join(toolDir, 'node', '8.8.1', os.arch()); |
82 | 82 |
|
83 | 83 | expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); |
84 | | - if (IS_WINDOWS) { |
| 84 | + if (isWindows) { |
85 | 85 | expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); |
86 | 86 | } else { |
87 | 87 | expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); |
|
0 commit comments