switch from jest to vitest

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-02-28 15:48:21 +01:00
parent a60f0f62b5
commit d5be006250
14 changed files with 1450 additions and 3493 deletions

View File

@@ -1,4 +1,4 @@
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
import {beforeEach, describe, expect, test, vi} from 'vitest';
import * as fs from 'fs';
import * as path from 'path';
import * as dotenv from 'dotenv';
@@ -13,27 +13,33 @@ import {Meta, Version} from '../src/meta';
import repoFixture from './fixtures/repo.json';
jest.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
vi.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
return <Promise<GitHubRepo>>(repoFixture as unknown);
});
jest.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => {
vi.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => {
return '2020-01-10T00:30:00.000Z';
});
jest.mock('moment-timezone', () => {
return () => (jest.requireActual('moment-timezone') as typeof import('moment-timezone'))('2020-01-10T00:30:00.000Z');
vi.mock('moment-timezone', async () => {
const actual = await vi.importActual<unknown>('moment-timezone');
const actualModule = actual as {default?: (input?: string | Date) => unknown};
const momentTimezone = (typeof actual === 'function' ? actual : actualModule.default) as (input?: string | Date) => unknown;
return {
__esModule: true,
default: () => momentTimezone('2020-01-10T00:30:00.000Z')
};
});
beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
Object.keys(process.env).forEach(function (key) {
if (key !== 'GITHUB_TOKEN' && key.startsWith('GITHUB_')) {
delete process.env[key];
}
});
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
//@ts-expect-error partial info
return {
...new Context(),
@@ -53,7 +59,7 @@ describe('isRawStatement', () => {
['{{ raw }}', true],
['{{ raw}}', true],
['{{raw}}', true],
])('given %p pattern', async (pattern: string, expected: boolean) => {
])('given %o pattern', async (pattern: string, expected: boolean) => {
expect(Meta.isRawStatement(pattern)).toEqual(expected);
});
});
@@ -79,7 +85,7 @@ const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exV
describe('null', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'null01',
@@ -133,12 +139,12 @@ describe('null', () => {
],
undefined
],
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('push', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'push01',
@@ -856,12 +862,12 @@ describe('push', () => {
],
undefined
]
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('tag', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'tag01',
@@ -2035,12 +2041,12 @@ describe('tag', () => {
],
undefined
]
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('latest', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'latest01',
@@ -2377,12 +2383,12 @@ describe('latest', () => {
],
undefined
]
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('pr', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'pr01',
@@ -2765,7 +2771,7 @@ describe('pr', () => {
],
undefined
],
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('pr-head-sha', () => {
@@ -3140,7 +3146,7 @@ describe('pr-head-sha', () => {
"org.opencontainers.image.version=src-2020-01-10T00-30-00Z",
]
],
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabelsAnnotations: Array<string>) => {
])('given %o with %o event', async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabelsAnnotations: Array<string>) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
process.env.DOCKER_METADATA_PR_HEAD_SHA = 'true';
@@ -3164,7 +3170,7 @@ describe('pr-head-sha', () => {
describe('schedule', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'schedule01',
@@ -3423,12 +3429,12 @@ describe('schedule', () => {
],
undefined
],
])('given %p with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('release', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'release01',
@@ -3525,12 +3531,12 @@ describe('release', () => {
],
undefined
]
])('given %s with %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('raw', () => {
// prettier-ignore
// eslint-disable-next-line jest/expect-expect
// eslint-disable-next-line @vitest/expect-expect
test.each([
[
'raw01',
@@ -3905,7 +3911,7 @@ describe('raw', () => {
],
undefined
],
])('given %p wth %p event', tagsLabelsTest);
])('given %o with %o event', tagsLabelsTest);
});
describe('json', () => {
@@ -4259,7 +4265,7 @@ describe('json', () => {
]
}
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: unknown) => {
])('given %o with %o event', async (name: string, envFile: string, inputs: Inputs, exJSON: unknown) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const toolkit = new Toolkit();
@@ -4774,7 +4780,7 @@ describe('bakeFile', () => {
}
}
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeTags: unknown, exBakeLabels: unknown, exBakeAnnotations: unknown) => {
])('given %o with %o event', async (name: string, envFile: string, inputs: Inputs, exBakeTags: unknown, exBakeLabels: unknown, exBakeAnnotations: unknown) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const toolkit = new Toolkit();
@@ -4837,7 +4843,7 @@ describe('bakeFileTagsLabels', () => {
}
}
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: unknown) => {
])('given %o with %o event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: unknown) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const toolkit = new Toolkit();
@@ -4882,7 +4888,7 @@ describe('sepTags', () => {
} as Inputs,
"user/app:dev,user/app:my,user/app:custom,user/app:tags"
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, expTags: string) => {
])('given %o with %o event', async (name: string, envFile: string, inputs: Inputs, expTags: string) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const toolkit = new Toolkit();