@@ -95,7 +95,12 @@ describe('Finder tests', () => {
95
95
fs . writeFileSync ( `${ pythonDir } .complete` , 'hello' ) ;
96
96
} ) ;
97
97
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
98
- await finder . useCpythonVersion ( '1.2.3' , 'x64' , true , false ) ;
98
+ await expect (
99
+ finder . useCpythonVersion ( '1.2.3' , 'x64' , true , false )
100
+ ) . resolves . toEqual ( {
101
+ impl : 'CPython' ,
102
+ version : '1.2.3'
103
+ } ) ;
99
104
expect ( spyCoreAddPath ) . toHaveBeenCalled ( ) ;
100
105
expect ( spyCoreExportVariable ) . toHaveBeenCalledWith (
101
106
'pythonLocation' ,
@@ -122,14 +127,19 @@ describe('Finder tests', () => {
122
127
const pythonDir : string = path . join (
123
128
toolDir ,
124
129
'Python' ,
125
- '1.2.3 -beta.2' ,
130
+ '1.2.4 -beta.2' ,
126
131
'x64'
127
132
) ;
128
133
await io . mkdirP ( pythonDir ) ;
129
134
fs . writeFileSync ( `${ pythonDir } .complete` , 'hello' ) ;
130
135
} ) ;
131
136
// This will throw if it doesn't find it in the manifest (because no such version exists)
132
- await finder . useCpythonVersion ( '1.2.3-beta.2' , 'x64' , false , false ) ;
137
+ await expect (
138
+ finder . useCpythonVersion ( '1.2.4-beta.2' , 'x64' , false , false )
139
+ ) . resolves . toEqual ( {
140
+ impl : 'CPython' ,
141
+ version : '1.2.4-beta.2'
142
+ } ) ;
133
143
} ) ;
134
144
135
145
it ( 'Check-latest true, finds the latest version in the manifest' , async ( ) => {
@@ -187,7 +197,7 @@ describe('Finder tests', () => {
187
197
) ;
188
198
expect ( installSpy ) . toHaveBeenCalled ( ) ;
189
199
expect ( addPathSpy ) . toHaveBeenCalledWith ( expPath ) ;
190
- await finder . useCpythonVersion ( '1.2.3 -beta.2' , 'x64' , false , true ) ;
200
+ await finder . useCpythonVersion ( '1.2.4 -beta.2' , 'x64' , false , true ) ;
191
201
expect ( spyCoreAddPath ) . toHaveBeenCalled ( ) ;
192
202
expect ( spyCoreExportVariable ) . toHaveBeenCalledWith (
193
203
'pythonLocation' ,
@@ -199,6 +209,55 @@ describe('Finder tests', () => {
199
209
) ;
200
210
} ) ;
201
211
212
+ it ( 'Finds stable Python version if it is not installed, but exists in the manifest, skipping newer pre-release' , async ( ) => {
213
+ const findSpy : jest . SpyInstance = jest . spyOn ( tc , 'getManifestFromRepo' ) ;
214
+ findSpy . mockImplementation ( ( ) => < tc . IToolRelease [ ] > manifestData ) ;
215
+
216
+ const installSpy : jest . SpyInstance = jest . spyOn (
217
+ installer ,
218
+ 'installCpythonFromRelease'
219
+ ) ;
220
+ installSpy . mockImplementation ( async ( ) => {
221
+ const pythonDir : string = path . join ( toolDir , 'Python' , '1.2.3' , 'x64' ) ;
222
+ await io . mkdirP ( pythonDir ) ;
223
+ fs . writeFileSync ( `${ pythonDir } .complete` , 'hello' ) ;
224
+ } ) ;
225
+ // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
226
+ await expect (
227
+ finder . useCpythonVersion ( '1.2' , 'x64' , false , false )
228
+ ) . resolves . toEqual ( {
229
+ impl : 'CPython' ,
230
+ version : '1.2.3'
231
+ } ) ;
232
+ } ) ;
233
+
234
+ it ( 'Finds Python version if it is not installed, but exists in the manifest, pre-release fallback' , async ( ) => {
235
+ const findSpy : jest . SpyInstance = jest . spyOn ( tc , 'getManifestFromRepo' ) ;
236
+ findSpy . mockImplementation ( ( ) => < tc . IToolRelease [ ] > manifestData ) ;
237
+
238
+ const installSpy : jest . SpyInstance = jest . spyOn (
239
+ installer ,
240
+ 'installCpythonFromRelease'
241
+ ) ;
242
+ installSpy . mockImplementation ( async ( ) => {
243
+ const pythonDir : string = path . join (
244
+ toolDir ,
245
+ 'Python' ,
246
+ '1.1.0-beta.2' ,
247
+ 'x64'
248
+ ) ;
249
+ await io . mkdirP ( pythonDir ) ;
250
+ fs . writeFileSync ( `${ pythonDir } .complete` , 'hello' ) ;
251
+ } ) ;
252
+ // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
253
+ await expect (
254
+ finder . useCpythonVersion ( '1.1' , 'x64' , false , false )
255
+ ) . resolves . toEqual ( {
256
+ impl : 'CPython' ,
257
+ version : '1.1.0-beta.2'
258
+ } ) ;
259
+ } ) ;
260
+
202
261
it ( 'Errors if Python is not installed' , async ( ) => {
203
262
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
204
263
let thrown = false ;
0 commit comments