1- import { afterEach , beforeEach , describe , expect , jest , test } from '@jest/globals ' ;
1+ import { afterEach , beforeEach , describe , expect , test , vi } from 'vitest ' ;
22import * as fs from 'fs' ;
3+ import * as os from 'os' ;
34import * as path from 'path' ;
5+ import { fileURLToPath } from 'node:url' ;
46
5- import { Builder } from '@docker/actions-toolkit/lib/buildx/builder' ;
6- import { Buildx } from '@docker/actions-toolkit/lib/buildx/buildx' ;
7- import { Build } from '@docker/actions-toolkit/lib/buildx/build' ;
8- import { Context } from '@docker/actions-toolkit/lib/context' ;
9- import { Docker } from '@docker/actions-toolkit/lib/docker/docker' ;
10- import { GitHub } from '@docker/actions-toolkit/lib/github' ;
11- import { Toolkit } from '@docker/actions-toolkit/lib/toolkit' ;
7+ import { Builder } from '@docker/actions-toolkit/lib/buildx/builder.js' ;
8+ import { Buildx } from '@docker/actions-toolkit/lib/buildx/buildx.js' ;
9+ import { Build } from '@docker/actions-toolkit/lib/buildx/build.js' ;
10+ import { Context } from '@docker/actions-toolkit/lib/context.js' ;
11+ import { Docker } from '@docker/actions-toolkit/lib/docker/docker.js' ;
12+ import { Toolkit } from '@docker/actions-toolkit/lib/toolkit.js' ;
1213
13- import { BuilderInfo } from '@docker/actions-toolkit/lib/types/buildx/builder' ;
14- import { GitHubRepo } from '@docker/actions-toolkit/lib/types/github' ;
14+ import { BuilderInfo } from '@docker/actions-toolkit/lib/types/buildx/builder.js' ;
1515
16- import * as context from '../src/context' ;
16+ import * as context from '../src/context.js ' ;
1717
18- const tmpDir = path . join ( '/tmp' , '.docker-build-push-jest' ) ;
19- const tmpName = path . join ( tmpDir , '.tmpname-jest' ) ;
18+ const tmpDir = fs . mkdtempSync ( path . join ( process . env . TEMP || os . tmpdir ( ) , 'context-' ) ) ;
19+ const tmpName = path . join ( tmpDir , '.tmpname-vi' ) ;
20+ const testDir = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
2021
21- import repoFixture from './fixtures/github-repo.json' ;
22- jest . spyOn ( GitHub . prototype , 'repoData' ) . mockImplementation ( ( ) : Promise < GitHubRepo > => {
23- return < Promise < GitHubRepo > > ( repoFixture as unknown ) ;
24- } ) ;
25-
26- jest . spyOn ( Context , 'tmpDir' ) . mockImplementation ( ( ) : string => {
22+ vi . spyOn ( Context , 'tmpDir' ) . mockImplementation ( ( ) : string => {
2723 if ( ! fs . existsSync ( tmpDir ) ) {
2824 fs . mkdirSync ( tmpDir , { recursive : true } ) ;
2925 }
3026 return tmpDir ;
3127} ) ;
3228
33- jest . spyOn ( Context , 'tmpName' ) . mockImplementation ( ( ) : string => {
29+ vi . spyOn ( Context , 'tmpName' ) . mockImplementation ( ( ) : string => {
3430 return tmpName ;
3531} ) ;
3632
37- jest . spyOn ( Docker , 'isAvailable' ) . mockImplementation ( async ( ) : Promise < boolean > => {
33+ vi . spyOn ( Docker , 'isAvailable' ) . mockImplementation ( async ( ) : Promise < boolean > => {
3834 return true ;
3935} ) ;
4036
4137const metadataJson = path . join ( tmpDir , 'metadata.json' ) ;
42- jest . spyOn ( Build . prototype , 'getMetadataFilePath' ) . mockImplementation ( ( ) : string => {
38+ vi . spyOn ( Build . prototype , 'getMetadataFilePath' ) . mockImplementation ( ( ) : string => {
4339 return metadataJson ;
4440} ) ;
4541
4642const imageIDFilePath = path . join ( tmpDir , 'iidfile.txt' ) ;
47- jest . spyOn ( Build . prototype , 'getImageIDFilePath' ) . mockImplementation ( ( ) : string => {
43+ vi . spyOn ( Build . prototype , 'getImageIDFilePath' ) . mockImplementation ( ( ) : string => {
4844 return imageIDFilePath ;
4945} ) ;
5046
51- jest . spyOn ( Builder . prototype , 'inspect' ) . mockImplementation ( async ( ) : Promise < BuilderInfo > => {
47+ vi . spyOn ( Builder . prototype , 'inspect' ) . mockImplementation ( async ( ) : Promise < BuilderInfo > => {
5248 return {
5349 name : 'builder2' ,
5450 driver : 'docker-container' ,
@@ -346,7 +342,7 @@ ccc`],
346342 new Map < string , string > ( [
347343 [ 'context' , 'https://github.com/docker/build-push-action.git#refs/heads/master' ] ,
348344 [ 'tag' , 'localhost:5000/name/app:latest' ] ,
349- [ 'secret-files' , `MY_SECRET=${ path . join ( __dirname , 'fixtures' , 'secret.txt' ) } ` ] ,
345+ [ 'secret-files' , `MY_SECRET=${ path . join ( testDir , 'fixtures' , 'secret.txt' ) } ` ] ,
350346 [ 'file' , './test/Dockerfile' ] ,
351347 [ 'builder' , 'builder-git-context-2' ] ,
352348 [ 'network' , 'host' ] ,
@@ -904,7 +900,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
904900 ] )
905901 ] ,
906902 ] ) (
907- '[%d] given %p with %p as inputs, returns %p ' ,
903+ '[%d] given %o with %o as inputs, returns %o ' ,
908904 async ( num : number , buildxVersion : string , inputs : Map < string , string > , expected : Array < string > , envs : Map < string , string > | undefined ) => {
909905 if ( envs ) {
910906 envs . forEach ( ( value : string , name : string ) => {
@@ -915,7 +911,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
915911 setInput ( name , value ) ;
916912 } ) ;
917913 const toolkit = new Toolkit ( ) ;
918- jest . spyOn ( Buildx . prototype , 'version' ) . mockImplementation ( async ( ) : Promise < string > => {
914+ vi . spyOn ( Buildx . prototype , 'version' ) . mockImplementation ( async ( ) : Promise < string > => {
919915 return buildxVersion ;
920916 } ) ;
921917 const inp = await context . getInputs ( ) ;
0 commit comments