@@ -4,7 +4,7 @@ import semver from 'semver';
4
4
import * as auth from '../src/authutil' ;
5
5
6
6
import * as setup from '../src/setup-dotnet' ;
7
- import { DotnetCoreInstaller } from '../src/installer' ;
7
+ import { DotnetCoreInstaller , DotnetInstallDir } from '../src/installer' ;
8
8
import * as cacheUtils from '../src/cache-utils' ;
9
9
import * as cacheRestore from '../src/cache-restore' ;
10
10
@@ -28,22 +28,25 @@ describe('setup-dotnet tests', () => {
28
28
DotnetCoreInstaller . prototype ,
29
29
'installDotnet'
30
30
) ;
31
- const addToPathSpy = jest . spyOn ( DotnetCoreInstaller , 'addToPath' ) ;
31
+
32
32
const isCacheFeatureAvailableSpy = jest . spyOn (
33
33
cacheUtils ,
34
34
'isCacheFeatureAvailable'
35
35
) ;
36
36
const restoreCacheSpy = jest . spyOn ( cacheRestore , 'restoreCache' ) ;
37
37
const configAuthenticationSpy = jest . spyOn ( auth , 'configAuthentication' ) ;
38
+ const addToPathOriginal = DotnetInstallDir . addToPath ;
38
39
39
40
describe ( 'run() tests' , ( ) => {
40
41
beforeEach ( ( ) => {
42
+ DotnetInstallDir . addToPath = jest . fn ( ) ;
41
43
getMultilineInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
42
44
getInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
43
45
getBooleanInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
44
46
} ) ;
45
47
46
48
afterEach ( ( ) => {
49
+ DotnetInstallDir . addToPath = addToPathOriginal ;
47
50
jest . clearAllMocks ( ) ;
48
51
jest . resetAllMocks ( ) ;
49
52
} ) ;
@@ -104,10 +107,9 @@ describe('setup-dotnet tests', () => {
104
107
inputs [ 'dotnet-quality' ] = '' ;
105
108
106
109
installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
107
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
108
110
109
111
await setup . run ( ) ;
110
- expect ( addToPathSpy ) . toHaveBeenCalledTimes ( 1 ) ;
112
+ expect ( DotnetInstallDir . addToPath ) . toHaveBeenCalledTimes ( 1 ) ;
111
113
} ) ;
112
114
113
115
it ( 'should call auth.configAuthentication() if source-url input is provided' , async ( ) => {
@@ -148,18 +150,16 @@ describe('setup-dotnet tests', () => {
148
150
installDotnetSpy . mockImplementation ( ( ) =>
149
151
Promise . resolve ( `${ inputs [ 'dotnet-version' ] } ` )
150
152
) ;
151
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
152
153
153
154
await setup . run ( ) ;
154
- expect ( setOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
155
+ expect ( DotnetInstallDir . addToPath ) . toHaveBeenCalledTimes ( 1 ) ;
155
156
} ) ;
156
157
157
158
it ( `shouldn't call setOutput() if parsing dotnet-installer logs failed` , async ( ) => {
158
159
inputs [ 'dotnet-version' ] = [ '6.0.300' ] ;
159
160
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.` ;
160
161
161
162
installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( null ) ) ;
162
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
163
163
164
164
await setup . run ( ) ;
165
165
expect ( warningSpy ) . toHaveBeenCalledWith ( warningMessage ) ;
@@ -170,8 +170,6 @@ describe('setup-dotnet tests', () => {
170
170
inputs [ 'dotnet-version' ] = [ ] ;
171
171
const warningMessage = `The 'dotnet-version' output will not be set.` ;
172
172
173
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
174
-
175
173
await setup . run ( ) ;
176
174
177
175
expect ( infoSpy ) . toHaveBeenCalledWith ( warningMessage ) ;
@@ -185,7 +183,6 @@ describe('setup-dotnet tests', () => {
185
183
inputs [ 'cache-dependency-path' ] = 'fictitious.package.lock.json' ;
186
184
187
185
installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
188
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
189
186
190
187
isCacheFeatureAvailableSpy . mockImplementation ( ( ) => true ) ;
191
188
restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
@@ -203,7 +200,6 @@ describe('setup-dotnet tests', () => {
203
200
inputs [ 'cache' ] = false ;
204
201
205
202
installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
206
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
207
203
208
204
isCacheFeatureAvailableSpy . mockImplementation ( ( ) => true ) ;
209
205
restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
@@ -218,7 +214,6 @@ describe('setup-dotnet tests', () => {
218
214
inputs [ 'cache' ] = true ;
219
215
220
216
installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
221
- addToPathSpy . mockImplementation ( ( ) => { } ) ;
222
217
223
218
isCacheFeatureAvailableSpy . mockImplementation ( ( ) => false ) ;
224
219
restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
0 commit comments