@@ -4,7 +4,7 @@ import semver from 'semver';
44import * as auth from '../src/authutil' ;
55
66import * as setup from '../src/setup-dotnet' ;
7- import { DotnetCoreInstaller } from '../src/installer' ;
7+ import { DotnetCoreInstaller , DotnetInstallDir } from '../src/installer' ;
88import * as cacheUtils from '../src/cache-utils' ;
99import * as cacheRestore from '../src/cache-restore' ;
1010
@@ -28,22 +28,25 @@ describe('setup-dotnet tests', () => {
2828 DotnetCoreInstaller . prototype ,
2929 'installDotnet'
3030 ) ;
31- const addToPathSpy = jest . spyOn ( DotnetCoreInstaller , 'addToPath' ) ;
31+
3232 const isCacheFeatureAvailableSpy = jest . spyOn (
3333 cacheUtils ,
3434 'isCacheFeatureAvailable'
3535 ) ;
3636 const restoreCacheSpy = jest . spyOn ( cacheRestore , 'restoreCache' ) ;
3737 const configAuthenticationSpy = jest . spyOn ( auth , 'configAuthentication' ) ;
38+ const addToPathOriginal = DotnetInstallDir . addToPath ;
3839
3940 describe ( 'run() tests' , ( ) => {
4041 beforeEach ( ( ) => {
42+ DotnetInstallDir . addToPath = jest . fn ( ) ;
4143 getMultilineInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
4244 getInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
4345 getBooleanInputSpy . mockImplementation ( input => inputs [ input as string ] ) ;
4446 } ) ;
4547
4648 afterEach ( ( ) => {
49+ DotnetInstallDir . addToPath = addToPathOriginal ;
4750 jest . clearAllMocks ( ) ;
4851 jest . resetAllMocks ( ) ;
4952 } ) ;
@@ -104,10 +107,9 @@ describe('setup-dotnet tests', () => {
104107 inputs [ 'dotnet-quality' ] = '' ;
105108
106109 installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
107- addToPathSpy . mockImplementation ( ( ) => { } ) ;
108110
109111 await setup . run ( ) ;
110- expect ( addToPathSpy ) . toHaveBeenCalledTimes ( 1 ) ;
112+ expect ( DotnetInstallDir . addToPath ) . toHaveBeenCalledTimes ( 1 ) ;
111113 } ) ;
112114
113115 it ( 'should call auth.configAuthentication() if source-url input is provided' , async ( ) => {
@@ -148,18 +150,16 @@ describe('setup-dotnet tests', () => {
148150 installDotnetSpy . mockImplementation ( ( ) =>
149151 Promise . resolve ( `${ inputs [ 'dotnet-version' ] } ` )
150152 ) ;
151- addToPathSpy . mockImplementation ( ( ) => { } ) ;
152153
153154 await setup . run ( ) ;
154- expect ( setOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
155+ expect ( DotnetInstallDir . addToPath ) . toHaveBeenCalledTimes ( 1 ) ;
155156 } ) ;
156157
157158 it ( `shouldn't call setOutput() if parsing dotnet-installer logs failed` , async ( ) => {
158159 inputs [ 'dotnet-version' ] = [ '6.0.300' ] ;
159160 const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.` ;
160161
161162 installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( null ) ) ;
162- addToPathSpy . mockImplementation ( ( ) => { } ) ;
163163
164164 await setup . run ( ) ;
165165 expect ( warningSpy ) . toHaveBeenCalledWith ( warningMessage ) ;
@@ -170,8 +170,6 @@ describe('setup-dotnet tests', () => {
170170 inputs [ 'dotnet-version' ] = [ ] ;
171171 const warningMessage = `The 'dotnet-version' output will not be set.` ;
172172
173- addToPathSpy . mockImplementation ( ( ) => { } ) ;
174-
175173 await setup . run ( ) ;
176174
177175 expect ( infoSpy ) . toHaveBeenCalledWith ( warningMessage ) ;
@@ -185,7 +183,6 @@ describe('setup-dotnet tests', () => {
185183 inputs [ 'cache-dependency-path' ] = 'fictitious.package.lock.json' ;
186184
187185 installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
188- addToPathSpy . mockImplementation ( ( ) => { } ) ;
189186
190187 isCacheFeatureAvailableSpy . mockImplementation ( ( ) => true ) ;
191188 restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
@@ -203,7 +200,6 @@ describe('setup-dotnet tests', () => {
203200 inputs [ 'cache' ] = false ;
204201
205202 installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
206- addToPathSpy . mockImplementation ( ( ) => { } ) ;
207203
208204 isCacheFeatureAvailableSpy . mockImplementation ( ( ) => true ) ;
209205 restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
@@ -218,7 +214,6 @@ describe('setup-dotnet tests', () => {
218214 inputs [ 'cache' ] = true ;
219215
220216 installDotnetSpy . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
221- addToPathSpy . mockImplementation ( ( ) => { } ) ;
222217
223218 isCacheFeatureAvailableSpy . mockImplementation ( ( ) => false ) ;
224219 restoreCacheSpy . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
0 commit comments