Skip to content

Commit db4ff6c

Browse files
committed
switch from jest to vitest
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 10e90e3 commit db4ff6c

9 files changed

Lines changed: 1596 additions & 3638 deletions

File tree

__mocks__/@actions/github.ts

Lines changed: 0 additions & 207 deletions
This file was deleted.

__tests__/context.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import {afterEach, beforeEach, describe, expect, jest, test} from '@jest/globals';
1+
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest';
22
import * as fs from 'fs';
3+
import * as os from 'os';
34
import * as path from 'path';
45

56
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
@@ -13,42 +14,41 @@ import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
1314
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder';
1415
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
1516

17+
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
18+
const tmpName = path.join(tmpDir, '.tmpname-vi');
1619
import * as context from '../src/context';
1720

18-
const tmpDir = path.join('/tmp', '.docker-build-push-jest');
19-
const tmpName = path.join(tmpDir, '.tmpname-jest');
20-
2121
import repoFixture from './fixtures/github-repo.json';
22-
jest.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
22+
vi.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
2323
return <Promise<GitHubRepo>>(repoFixture as unknown);
2424
});
2525

26-
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
26+
vi.spyOn(Context, 'tmpDir').mockImplementation((): string => {
2727
if (!fs.existsSync(tmpDir)) {
2828
fs.mkdirSync(tmpDir, {recursive: true});
2929
}
3030
return tmpDir;
3131
});
3232

33-
jest.spyOn(Context, 'tmpName').mockImplementation((): string => {
33+
vi.spyOn(Context, 'tmpName').mockImplementation((): string => {
3434
return tmpName;
3535
});
3636

37-
jest.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise<boolean> => {
37+
vi.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise<boolean> => {
3838
return true;
3939
});
4040

4141
const metadataJson = path.join(tmpDir, 'metadata.json');
42-
jest.spyOn(Build.prototype, 'getMetadataFilePath').mockImplementation((): string => {
42+
vi.spyOn(Build.prototype, 'getMetadataFilePath').mockImplementation((): string => {
4343
return metadataJson;
4444
});
4545

4646
const imageIDFilePath = path.join(tmpDir, 'iidfile.txt');
47-
jest.spyOn(Build.prototype, 'getImageIDFilePath').mockImplementation((): string => {
47+
vi.spyOn(Build.prototype, 'getImageIDFilePath').mockImplementation((): string => {
4848
return imageIDFilePath;
4949
});
5050

51-
jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
51+
vi.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
5252
return {
5353
name: 'builder2',
5454
driver: 'docker-container',
@@ -904,7 +904,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
904904
])
905905
],
906906
])(
907-
'[%d] given %p with %p as inputs, returns %p',
907+
'[%d] given %o with %o as inputs, returns %o',
908908
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>, envs: Map<string, string> | undefined) => {
909909
if (envs) {
910910
envs.forEach((value: string, name: string) => {
@@ -915,7 +915,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
915915
setInput(name, value);
916916
});
917917
const toolkit = new Toolkit();
918-
jest.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise<string> => {
918+
vi.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise<string> => {
919919
return buildxVersion;
920920
});
921921
const inp = await context.getInputs();

0 commit comments

Comments
 (0)