@@ -280,6 +280,59 @@ describe('Tool Tests', function () {
280
280
} ) ;
281
281
} ) ;
282
282
283
+ it ( 'installs a zip and extracts it to specified directory' , function ( ) {
284
+ this . timeout ( 2000 ) ;
285
+
286
+ return new Promise < void > ( async ( resolve , reject ) => {
287
+ try {
288
+ let tempDir = path . join ( __dirname , 'test-install-zip' ) ;
289
+ tl . mkdirP ( tempDir ) ;
290
+
291
+ // stage the layout for a zip file:
292
+ // file.txt
293
+ // folder/nested-file.txt
294
+ let stagingDir = path . join ( tempDir , 'zip-staging' ) ;
295
+ tl . mkdirP ( path . join ( stagingDir , 'folder' ) ) ;
296
+ fs . writeFileSync ( path . join ( stagingDir , 'file.txt' ) , '' ) ;
297
+ fs . writeFileSync ( path . join ( stagingDir , 'folder' , 'nested-file.txt' ) , '' ) ;
298
+
299
+ // create the zip
300
+ let zipFile = path . join ( tempDir , 'test.zip' ) ;
301
+ if ( process . platform == 'win32' ) {
302
+ let escapedStagingPath = stagingDir . replace ( / ' / g, "''" ) // double-up single quotes
303
+ let escapedZipFile = zipFile . replace ( / ' / g, "''" ) ;
304
+ let powershell = tl . tool ( tl . which ( 'powershell' , true ) )
305
+ . line ( '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command' )
306
+ . arg ( `$ErrorActionPreference = 'Stop' ; Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::CreateFromDirectory('${ escapedStagingPath } ', '${ escapedZipFile } ')` ) ;
307
+ powershell . execSync ( ) ;
308
+ }
309
+ else {
310
+ let zip = tl . tool ( 'zip' )
311
+ . arg ( zipFile )
312
+ . arg ( '-r' )
313
+ . arg ( '.' ) ;
314
+ zip . execSync ( < trm . IExecOptions > { cwd : stagingDir } ) ;
315
+ }
316
+
317
+ let destDir = path . join ( __dirname , 'unzip-dest' ) ;
318
+ tl . mkdirP ( destDir ) ;
319
+
320
+ let extPath : string = await toolLib . extractZip ( zipFile , destDir ) ;
321
+ toolLib . cacheDir ( extPath , 'foo' , '1.1.0' ) ;
322
+ let toolPath : string = toolLib . findLocalTool ( 'foo' , '1.1.0' ) ;
323
+ assert ( tl . exist ( toolPath ) , 'found tool exists' ) ;
324
+ assert ( tl . exist ( `${ toolPath } .complete` ) , 'tool.complete exists' ) ;
325
+ assert ( tl . exist ( path . join ( toolPath , 'file.txt' ) ) , 'file.txt exists' ) ;
326
+ assert ( tl . exist ( path . join ( toolPath , 'folder' , 'nested-file.txt' ) ) , 'nested-file.txt exists' ) ;
327
+
328
+ resolve ( ) ;
329
+ }
330
+ catch ( err ) {
331
+ reject ( err ) ;
332
+ }
333
+ } ) ;
334
+ } ) ;
335
+
283
336
it ( 'finds and evaluates local tool version' , function ( ) {
284
337
this . timeout ( 2000 ) ;
285
338
0 commit comments