1- import { getToolsMock } from '../utils' ;
2-
3- const core = {
4- addPath : jest . fn ( ) ,
5- getInput : jest . fn ( ) ,
6- group : < T > ( message : string , action : ( ) => Promise < T > ) : Promise < T > => action ( ) ,
7- info : jest . fn ( ) ,
8- } ;
9- const exec = { exec : jest . fn ( ) } ;
10- const install = { install : jest . fn ( ) } ;
11- const tools = getToolsMock ( ) ;
12-
13- jest . mock ( '@actions/core' , ( ) => core ) ;
14- jest . mock ( '@actions/exec' , ( ) => exec ) ;
15- jest . mock ( '../../src/tools' , ( ) => tools ) ;
16- jest . mock ( '../../src/install' , ( ) => install ) ;
1+ import { getToolsMock , mockInput } from '../utils' ;
172
3+ jest . mock ( '../../src/tools' , ( ) => getToolsMock ( ) ) ;
4+
5+ import * as core from '@actions/core' ;
6+
7+ import * as install from '../../src/install' ;
8+ import * as tools from '../../src/tools' ;
189import { setupAction } from '../../src/actions/setup' ;
1910
20- describe ( 'run' , ( ) => {
21- it ( 'patches the system when set to true' , async ( ) => {
22- mockInput ( { patchWatchers : 'true' } ) ;
23- await setupAction ( ) ;
24- expect ( tools . maybePatchWatchers ) . toHaveBeenCalled ( ) ;
25- } ) ;
11+ describe ( setupAction , ( ) => {
12+ describe ( 'patch watchers' , ( ) => {
13+ it ( 'patches the system when set to true' , async ( ) => {
14+ mockInput ( { 'patch-watchers' : 'true' } ) ;
15+ await setupAction ( ) ;
16+ expect ( tools . maybePatchWatchers ) . toHaveBeenCalled ( ) ;
17+ } ) ;
2618
27- it ( 'patches the system when not set' , async ( ) => {
28- mockInput ( { patchWatchers : '' } ) ;
29- await setupAction ( ) ;
30- expect ( tools . maybePatchWatchers ) . toHaveBeenCalled ( ) ;
31- } ) ;
19+ it ( 'patches the system when not set' , async ( ) => {
20+ mockInput ( { 'patch-watchers' : '' } ) ;
21+ await setupAction ( ) ;
22+ expect ( tools . maybePatchWatchers ) . toHaveBeenCalled ( ) ;
23+ } ) ;
3224
33- it ( 'skips the system patch when set to false' , async ( ) => {
34- mockInput ( { patchWatchers : 'false' } ) ;
35- await setupAction ( ) ;
36- expect ( tools . maybePatchWatchers ) . not . toHaveBeenCalled ( ) ;
25+ it ( 'skips the system patch when set to false' , async ( ) => {
26+ mockInput ( { 'patch-watchers' : 'false' } ) ;
27+ await setupAction ( ) ;
28+ expect ( tools . maybePatchWatchers ) . not . toHaveBeenCalled ( ) ;
29+ } ) ;
3730 } ) ;
3831
39- it ( 'authenticates with provided credentials' , async ( ) => {
40- mockInput ( { username : 'bycedric' , password : 'mypassword' , patchWatchers : 'false' } ) ;
41- await setupAction ( ) ;
42- expect ( tools . maybeAuthenticate ) . toBeCalledWith ( { username : 'bycedric' , password : 'mypassword' } ) ;
43- } ) ;
32+ describe ( 'authentication' , ( ) => {
33+ it ( 'authenticates with provided credentials' , async ( ) => {
34+ mockInput ( { username : 'bycedric' , password : 'mypassword' } ) ;
35+ await setupAction ( ) ;
36+ expect ( tools . maybeAuthenticate ) . toBeCalledWith ( { username : 'bycedric' , password : 'mypassword' } ) ;
37+ } ) ;
4438
45- it ( 'authenticates with provided token' , async ( ) => {
46- mockInput ( { token : 'ABC123' , patchWatchers : 'false' } ) ;
47- await setupAction ( ) ;
48- expect ( tools . maybeAuthenticate ) . toBeCalledWith ( { token : 'ABC123' } ) ;
39+ it ( 'authenticates with provided token' , async ( ) => {
40+ mockInput ( { token : 'ABC123' } ) ;
41+ await setupAction ( ) ;
42+ expect ( tools . maybeAuthenticate ) . toBeCalledWith ( { token : 'ABC123' } ) ;
43+ } ) ;
4944 } ) ;
5045
5146 [ 'expo' , 'eas' ] . forEach ( cliName => {
5247 const packageName = `${ cliName } -cli` ;
48+ let installMock : jest . SpyInstance ;
49+
50+ beforeEach ( ( ) => {
51+ installMock = jest . spyOn ( install , 'install' ) . mockImplementation ( ) ;
52+ } ) ;
53+
54+ afterEach ( ( ) => {
55+ installMock . mockRestore ( ) ;
56+ } ) ;
5357
5458 describe ( packageName , ( ) => {
5559 it ( `skips installation without \`${ cliName } -version\`` , async ( ) => {
5660 mockInput ( ) ;
5761 await setupAction ( ) ;
58- expect ( install . install ) . not . toBeCalledWith ( { package : packageName } ) ;
62+ expect ( installMock ) . not . toBeCalledWith ( { package : packageName } ) ;
5963 } ) ;
6064
6165 it ( 'installs with yarn by default' , async ( ) => {
62- mockInput ( { [ `${ cliName } Version ` ] : 'latest' } ) ;
66+ mockInput ( { [ `${ cliName } -version ` ] : 'latest' } ) ;
6367 await setupAction ( ) ;
64- expect ( install . install ) . toBeCalledWith ( {
68+ expect ( installMock ) . toBeCalledWith ( {
6569 package : packageName ,
6670 version : 'latest' ,
6771 packager : 'yarn' ,
@@ -70,9 +74,9 @@ describe('run', () => {
7074 } ) ;
7175
7276 it ( 'installs provided version with npm' , async ( ) => {
73- mockInput ( { [ `${ cliName } Version ` ] : '3.0.10' , packager : 'npm' } ) ;
77+ mockInput ( { [ `${ cliName } -version ` ] : '3.0.10' , packager : 'npm' } ) ;
7478 await setupAction ( ) ;
75- expect ( install . install ) . toBeCalledWith ( {
79+ expect ( installMock ) . toBeCalledWith ( {
7680 package : packageName ,
7781 version : '3.0.10' ,
7882 packager : 'npm' ,
@@ -83,11 +87,11 @@ describe('run', () => {
8387 it ( 'installs with yarn and cache enabled' , async ( ) => {
8488 mockInput ( {
8589 packager : 'yarn' ,
86- [ `${ cliName } Version ` ] : '4.2.0' ,
87- [ `${ cliName } Cache ` ] : 'true' ,
90+ [ `${ cliName } -version ` ] : '4.2.0' ,
91+ [ `${ cliName } -cache ` ] : 'true' ,
8892 } ) ;
8993 await setupAction ( ) ;
90- expect ( install . install ) . toBeCalledWith ( {
94+ expect ( installMock ) . toBeCalledWith ( {
9195 package : packageName ,
9296 version : '4.2.0' ,
9397 packager : 'yarn' ,
@@ -98,12 +102,12 @@ describe('run', () => {
98102 it ( 'installs with yarn and custom cache key' , async ( ) => {
99103 mockInput ( {
100104 packager : 'yarn' ,
101- [ `${ cliName } Version ` ] : '4.2.0' ,
102- [ `${ cliName } Cache ` ] : 'true' ,
103- [ `${ cliName } CacheKey ` ] : 'custom-key' ,
105+ [ `${ cliName } -version ` ] : '4.2.0' ,
106+ [ `${ cliName } -cache ` ] : 'true' ,
107+ [ `${ cliName } -cache-key ` ] : 'custom-key' ,
104108 } ) ;
105109 await setupAction ( ) ;
106- expect ( install . install ) . toBeCalledWith ( {
110+ expect ( installMock ) . toBeCalledWith ( {
107111 package : packageName ,
108112 version : '4.2.0' ,
109113 packager : 'yarn' ,
@@ -113,59 +117,11 @@ describe('run', () => {
113117 } ) ;
114118
115119 it ( 'installs path to global path' , async ( ) => {
116- install . install . mockResolvedValue ( `/${ cliName } /install/path` ) ;
120+ installMock . mockResolvedValue ( `/${ cliName } /install/path` ) ;
121+ const addPathSpy = jest . spyOn ( core , 'addPath' ) . mockImplementation ( ) ;
117122 await setupAction ( ) ;
118- expect ( core . addPath ) . toBeCalledWith ( `/${ cliName } /install/path` ) ;
123+ expect ( addPathSpy ) . toBeCalledWith ( `/${ cliName } /install/path` ) ;
119124 } ) ;
120125 } ) ;
121126 } ) ;
122127} ) ;
123-
124- interface MockInputProps {
125- expoVersion ?: string ;
126- expoCache ?: string ;
127- expoCacheKey ?: string ;
128- easVersion ?: string ;
129- easCache ?: string ;
130- easCacheKey ?: string ;
131- packager ?: string ;
132- token ?: string ;
133- username ?: string ;
134- password ?: string ;
135- patchWatchers ?: string ;
136- }
137-
138- function mockInput ( props : MockInputProps = { } ) {
139- // fix: kind of dirty workaround for missing "mock 'value' based on arguments"
140- const input = ( name : string ) => {
141- switch ( name ) {
142- case 'expo-version' :
143- return props . expoVersion || '' ;
144- case 'expo-cache' :
145- return props . expoCache || '' ;
146- case 'expo-cache-key' :
147- return props . expoCacheKey || '' ;
148- case 'eas-version' :
149- return props . easVersion || '' ;
150- case 'eas-cache' :
151- return props . easCache || '' ;
152- case 'eas-cache-key' :
153- return props . easCacheKey || '' ;
154- case 'packager' :
155- return props . packager || '' ;
156- case 'token' :
157- return props . token || '' ;
158- case 'username' :
159- return props . username || '' ;
160- case 'password' :
161- return props . password || '' ;
162- case 'patch-watchers' :
163- return props . patchWatchers || '' ;
164- default :
165- return '' ;
166- }
167- } ;
168-
169- // eslint-disable-next-line @typescript-eslint/no-explicit-any
170- core . getInput = input as any ;
171- }
0 commit comments