1+ import core = require( "@actions/core" ) ;
12import io = require( "@actions/io" ) ;
23import path = require( "path" ) ;
34import os = require( "os" ) ;
@@ -13,8 +14,18 @@ process.env["RUNNER_TEMP"] = tempDir;
1314process . env [ "RUNNER_TOOL_CACHE" ] = toolDir ;
1415import * as installer from "../src/installer" ;
1516
17+ // Inputs for mock @actions /core
18+ let inputs = {
19+ token : process . env . GITHUB_TOKEN || ""
20+ } as any ;
21+
1622describe ( "installer tests" , ( ) => {
1723 beforeEach ( async function ( ) {
24+ // Mock getInput
25+ jest . spyOn ( core , "getInput" ) . mockImplementation ( ( name : string ) => {
26+ return inputs [ name ] ;
27+ } ) ;
28+
1829 await io . rmRF ( toolDir ) ;
1930 await io . rmRF ( tempDir ) ;
2031 await io . mkdirP ( toolDir ) ;
@@ -28,6 +39,7 @@ describe("installer tests", () => {
2839 } catch {
2940 console . log ( "Failed to remove test directories" ) ;
3041 }
42+ jest . restoreAllMocks ( ) ;
3143 } ) ;
3244
3345 it ( "Downloads version of Arduino CLI if no matching version is installed" , async ( ) => {
@@ -41,10 +53,14 @@ describe("installer tests", () => {
4153 } else {
4254 expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
4355 }
44- } , 10000 ) ;
56+ } , 20000 ) ;
4557
4658 describe ( "Gets the latest release of Arduino CLI" , ( ) => {
4759 beforeEach ( ( ) => {
60+ jest . spyOn ( core , "getInput" ) . mockImplementation ( ( name : string ) => {
61+ return inputs [ name ] ;
62+ } ) ;
63+
4864 nock ( "https://api.github.com" )
4965 . get ( "/repos/Arduino/arduino-cli/git/refs/tags" )
5066 . replyWithFile ( 200 , path . join ( dataDir , "tags.json" ) ) ;
@@ -53,6 +69,7 @@ describe("installer tests", () => {
5369 afterEach ( ( ) => {
5470 nock . cleanAll ( ) ;
5571 nock . enableNetConnect ( ) ;
72+ jest . clearAllMocks ( ) ;
5673 } ) ;
5774
5875 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", () => {
6582 } else {
6683 expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
6784 }
68- } , 10000 ) ;
85+ } , 20000 ) ;
6986
7087 it ( "Gets latest version of Task using 0.x and no matching version is installed" , async ( ) => {
7188 await installer . getArduinoCli ( "0.x" ) ;
@@ -77,6 +94,6 @@ describe("installer tests", () => {
7794 } else {
7895 expect ( fs . existsSync ( path . join ( bindir , "arduino-cli" ) ) ) . toBe ( true ) ;
7996 }
80- } , 10000 ) ;
97+ } , 20000 ) ;
8198 } ) ;
8299} ) ;
0 commit comments