@@ -18,6 +18,15 @@ if (IS_WINDOWS) {
18
18
toolDir = path . join ( process . env [ 'HOME' ] + '' , '.dotnet' ) ;
19
19
}
20
20
21
+ function createGlobalJsonPath ( dotnetVersion : string ) {
22
+ const globalJsonPath = path . join ( process . cwd ( ) , 'global.json' ) ;
23
+ const jsonContents = `{${ os . EOL } "sdk": {${ os . EOL } "version": "${ dotnetVersion } "${ os . EOL } }${ os . EOL } }` ;
24
+ if ( ! fs . existsSync ( globalJsonPath ) ) {
25
+ fs . writeFileSync ( globalJsonPath , jsonContents ) ;
26
+ }
27
+ return globalJsonPath ;
28
+ }
29
+
21
30
const tempDir = path . join ( __dirname , 'runner' , 'temp2' ) ;
22
31
23
32
describe ( 'setup-dotnet tests' , ( ) => {
@@ -52,11 +61,7 @@ describe('setup-dotnet tests', () => {
52
61
} , 30000 ) ;
53
62
54
63
it ( 'Acquires version of dotnet from global.json if no matching version is installed' , async ( ) => {
55
- const globalJsonPath = path . join ( process . cwd ( ) , 'global.json' ) ;
56
- const jsonContents = `{${ os . EOL } "sdk": {${ os . EOL } "version": "3.1.201"${ os . EOL } }${ os . EOL } }` ;
57
- if ( ! fs . existsSync ( globalJsonPath ) ) {
58
- fs . writeFileSync ( globalJsonPath , jsonContents ) ;
59
- }
64
+ createGlobalJsonPath ( '3.1.201' ) ;
60
65
await setup . run ( ) ;
61
66
62
67
expect ( fs . existsSync ( path . join ( toolDir , 'sdk' , '3.1.201' ) ) ) . toBe ( true ) ;
@@ -78,11 +83,7 @@ describe('setup-dotnet tests', () => {
78
83
} , 400000 ) ;
79
84
80
85
it ( "Sets output with the version specified in global.json, if it's present" , async ( ) => {
81
- const globalJsonPath = path . join ( process . cwd ( ) , 'global.json' ) ;
82
- const jsonContents = `{${ os . EOL } "sdk": {${ os . EOL } "version": "3.0.103"${ os . EOL } }${ os . EOL } }` ;
83
- if ( ! fs . existsSync ( globalJsonPath ) ) {
84
- fs . writeFileSync ( globalJsonPath , jsonContents ) ;
85
- }
86
+ createGlobalJsonPath ( '3.0.103' ) ;
86
87
87
88
inputs [ 'dotnet-version' ] = [ '3.1.201' , '6.0.401' ] ;
88
89
inputs [ 'global-json-file' ] = './global.json' ;
@@ -95,4 +96,19 @@ describe('setup-dotnet tests', () => {
95
96
96
97
expect ( setOutputSpy ) . toHaveBeenCalledWith ( 'dotnet-version' , '3.0.103' ) ;
97
98
} , 400000 ) ;
99
+
100
+ it ( 'Sets output with the version specified in global.json with absolute path' , async ( ) => {
101
+ const globalJsonPath = createGlobalJsonPath ( '3.0.103' ) ;
102
+
103
+ inputs [ 'dotnet-version' ] = [ '3.1.201' , '6.0.401' ] ;
104
+ inputs [ 'global-json-file' ] = globalJsonPath ;
105
+
106
+ getMultilineInputSpy . mockImplementation ( input => inputs [ input ] ) ;
107
+
108
+ getInputSpy . mockImplementation ( input => inputs [ input ] ) ;
109
+
110
+ await setup . run ( ) ;
111
+
112
+ expect ( setOutputSpy ) . toHaveBeenCalledWith ( 'dotnet-version' , '3.0.103' ) ;
113
+ } , 400000 ) ;
98
114
} ) ;
0 commit comments