1
+ import core = require( "@actions/core" ) ;
1
2
import io = require( "@actions/io" ) ;
2
3
import path = require( "path" ) ;
3
4
import os = require( "os" ) ;
@@ -13,8 +14,18 @@ process.env["RUNNER_TEMP"] = tempDir;
13
14
process . env [ "RUNNER_TOOL_CACHE" ] = toolDir ;
14
15
import * as installer from "../src/installer" ;
15
16
17
+ // Inputs for mock @actions /core
18
+ let inputs = {
19
+ token : process . env . GITHUB_TOKEN || ""
20
+ } as any ;
21
+
16
22
describe ( "installer tests" , ( ) => {
17
23
beforeEach ( async function ( ) {
24
+ // Mock getInput
25
+ jest . spyOn ( core , "getInput" ) . mockImplementation ( ( name : string ) => {
26
+ return inputs [ name ] ;
27
+ } ) ;
28
+
18
29
await io . rmRF ( toolDir ) ;
19
30
await io . rmRF ( tempDir ) ;
20
31
await io . mkdirP ( toolDir ) ;
@@ -28,6 +39,7 @@ describe("installer tests", () => {
28
39
} catch {
29
40
console . log ( "Failed to remove test directories" ) ;
30
41
}
42
+ jest . restoreAllMocks ( ) ;
31
43
} ) ;
32
44
33
45
it ( "Downloads version of Arduino CLI if no matching version is installed" , async ( ) => {
@@ -41,10 +53,14 @@ describe("installer tests", () => {
41
53
} else {
42
54
expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
43
55
}
44
- } , 10000 ) ;
56
+ } , 20000 ) ;
45
57
46
58
describe ( "Gets the latest release of Arduino CLI" , ( ) => {
47
59
beforeEach ( ( ) => {
60
+ jest . spyOn ( core , "getInput" ) . mockImplementation ( ( name : string ) => {
61
+ return inputs [ name ] ;
62
+ } ) ;
63
+
48
64
nock ( "https://api.github.com" )
49
65
. get ( "/repos/Arduino/arduino-cli/git/refs/tags" )
50
66
. replyWithFile ( 200 , path . join ( dataDir , "tags.json" ) ) ;
@@ -53,6 +69,7 @@ describe("installer tests", () => {
53
69
afterEach ( ( ) => {
54
70
nock . cleanAll ( ) ;
55
71
nock . enableNetConnect ( ) ;
72
+ jest . clearAllMocks ( ) ;
56
73
} ) ;
57
74
58
75
it ( "Gets the latest version of Arduino CLI 0.4.0 using 0.4 and no matching version is installed" , async ( ) => {
@@ -65,7 +82,7 @@ describe("installer tests", () => {
65
82
} else {
66
83
expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
67
84
}
68
- } , 10000 ) ;
85
+ } , 20000 ) ;
69
86
70
87
it ( "Gets latest version of Task using 0.x and no matching version is installed" , async ( ) => {
71
88
await installer . getArduinoCli ( "0.x" ) ;
@@ -77,6 +94,6 @@ describe("installer tests", () => {
77
94
} else {
78
95
expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
79
96
}
80
- } , 10000 ) ;
97
+ } , 20000 ) ;
81
98
} ) ;
82
99
} ) ;
0 commit comments