mirror of
https://github.com/docker/login-action.git
synced 2026-03-04 14:58:17 +00:00
switch from jest to vitest
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
||||
import {beforeEach, describe, expect, test, vi} from 'vitest';
|
||||
import {AuthorizationData} from '@aws-sdk/client-ecr';
|
||||
|
||||
import * as aws from '../src/aws';
|
||||
@@ -65,26 +65,28 @@ describe('getAccountIDs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const mockEcrGetAuthToken = jest.fn();
|
||||
const mockEcrPublicGetAuthToken = jest.fn();
|
||||
jest.mock('@aws-sdk/client-ecr', () => {
|
||||
const mockEcrGetAuthToken = vi.fn();
|
||||
const mockEcrPublicGetAuthToken = vi.fn();
|
||||
vi.mock('@aws-sdk/client-ecr', () => {
|
||||
class ECR {
|
||||
getAuthorizationToken = mockEcrGetAuthToken;
|
||||
}
|
||||
return {
|
||||
ECR: jest.fn(() => ({
|
||||
getAuthorizationToken: mockEcrGetAuthToken
|
||||
}))
|
||||
ECR
|
||||
};
|
||||
});
|
||||
jest.mock('@aws-sdk/client-ecr-public', () => {
|
||||
vi.mock('@aws-sdk/client-ecr-public', () => {
|
||||
class ECRPUBLIC {
|
||||
getAuthorizationToken = mockEcrPublicGetAuthToken;
|
||||
}
|
||||
return {
|
||||
ECRPUBLIC: jest.fn(() => ({
|
||||
getAuthorizationToken: mockEcrPublicGetAuthToken
|
||||
}))
|
||||
ECRPUBLIC
|
||||
};
|
||||
});
|
||||
|
||||
describe('getRegistriesData', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
delete process.env.AWS_ACCOUNT_IDS;
|
||||
});
|
||||
// prettier-ignore
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {expect, test} from '@jest/globals';
|
||||
import {expect, test} from 'vitest';
|
||||
|
||||
import {getInputs} from '../src/context';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {expect, jest, test} from '@jest/globals';
|
||||
import {expect, test, vi} from 'vitest';
|
||||
import * as path from 'path';
|
||||
|
||||
import {loginStandard, logout} from '../src/docker';
|
||||
@@ -10,7 +10,7 @@ process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
|
||||
test('loginStandard calls exec', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const execSpy = jest.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||
return {
|
||||
exitCode: expect.any(Number),
|
||||
stdout: expect.any(Function),
|
||||
@@ -40,7 +40,7 @@ test('loginStandard calls exec', async () => {
|
||||
test('logout calls exec', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const execSpy = jest.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||
return {
|
||||
exitCode: expect.any(Number),
|
||||
stdout: expect.any(Function),
|
||||
|
||||
12
__tests__/setup.unit.ts
Normal file
12
__tests__/setup.unit.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-login-action-'));
|
||||
|
||||
process.env = Object.assign({}, process.env, {
|
||||
TEMP: tmpDir,
|
||||
GITHUB_REPOSITORY: 'docker/login-action',
|
||||
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
|
||||
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
|
||||
});
|
||||
Reference in New Issue
Block a user