1+ import { describe , expect , it , jest , test } from '@jest/globals' ;
12import * as fs from 'fs' ;
23import * as path from 'path' ;
34import * as semver from 'semver' ;
45import * as exec from '@actions/exec' ;
5-
66import * as buildx from '../src/buildx' ;
77import * as context from '../src/context' ;
88
@@ -25,6 +25,19 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
2525 return tmpNameSync ;
2626} ) ;
2727
28+ export const skipItIf = ( conditional : boolean ) => ( conditional ? it . skip : it ) ;
29+
30+ async function isDaemonRunning ( ) {
31+ return await exec
32+ . getExecOutput ( `docker` , [ 'version' , '--format' , '{{.Server.Os}}' ] , {
33+ ignoreReturnCode : true ,
34+ silent : true
35+ } )
36+ . then ( res => {
37+ return ! res . stdout . includes ( ' ' ) && res . exitCode == 0 ;
38+ } ) ;
39+ }
40+
2841describe ( 'getImageID' , ( ) => {
2942 it ( 'matches' , async ( ) => {
3043 const imageIDFile = await buildx . getImageIDFile ( ) ;
@@ -104,7 +117,7 @@ describe('isLocalOrTarExporter', () => {
104117} ) ;
105118
106119describe ( 'isAvailable' , ( ) => {
107- const execSpy : jest . SpyInstance = jest . spyOn ( exec , 'getExecOutput' ) ;
120+ const execSpy = jest . spyOn ( exec , 'getExecOutput' ) ;
108121 buildx . isAvailable ( ) ;
109122
110123 expect ( execSpy ) . toHaveBeenCalledWith ( `docker` , [ 'buildx' ] , {
@@ -114,17 +127,7 @@ describe('isAvailable', () => {
114127} ) ;
115128
116129describe ( 'getVersion' , ( ) => {
117- async function isDaemonRunning ( ) {
118- return await exec
119- . getExecOutput ( `docker` , [ 'version' , '--format' , '{{.Server.Os}}' ] , {
120- ignoreReturnCode : true ,
121- silent : true
122- } )
123- . then ( res => {
124- return ! res . stdout . includes ( ' ' ) && res . exitCode == 0 ;
125- } ) ;
126- }
127- ( isDaemonRunning ( ) ? it : it . skip ) (
130+ skipItIf ( ! isDaemonRunning ( ) ) (
128131 'valid' ,
129132 async ( ) => {
130133 const version = await buildx . getVersion ( ) ;
0 commit comments