mirror of
https://github.com/docker/metadata-action.git
synced 2026-03-04 15:58:19 +00:00
switch from jest to vitest
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -1,223 +0,0 @@
|
|||||||
import {jest} from '@jest/globals';
|
|
||||||
|
|
||||||
export const context = {
|
|
||||||
repo: {
|
|
||||||
owner: 'docker',
|
|
||||||
repo: 'actions-toolkit'
|
|
||||||
},
|
|
||||||
ref: 'refs/heads/master',
|
|
||||||
runId: 123,
|
|
||||||
payload: {
|
|
||||||
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
base_ref: null,
|
|
||||||
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
|
||||||
commits: [
|
|
||||||
{
|
|
||||||
author: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
committer: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
distinct: true,
|
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
message: 'hello dev',
|
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
|
||||||
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
|
|
||||||
created: false,
|
|
||||||
deleted: false,
|
|
||||||
forced: false,
|
|
||||||
head_commit: {
|
|
||||||
author: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
committer: {
|
|
||||||
email: 'crazy-max@users.noreply.github.com',
|
|
||||||
name: 'CrazyMax',
|
|
||||||
username: 'crazy-max'
|
|
||||||
},
|
|
||||||
distinct: true,
|
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
|
||||||
message: 'hello dev',
|
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
|
||||||
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
|
||||||
},
|
|
||||||
organization: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
|
||||||
description: 'Docker helps developers bring their ideas to life by conquering the complexity of app development.',
|
|
||||||
events_url: 'https://api.github.com/orgs/docker/events',
|
|
||||||
hooks_url: 'https://api.github.com/orgs/docker/hooks',
|
|
||||||
id: 5429470,
|
|
||||||
issues_url: 'https://api.github.com/orgs/docker/issues',
|
|
||||||
login: 'docker',
|
|
||||||
members_url: 'https://api.github.com/orgs/docker/members{/member}',
|
|
||||||
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
|
||||||
public_members_url: 'https://api.github.com/orgs/docker/public_members{/member}',
|
|
||||||
repos_url: 'https://api.github.com/orgs/docker/repos',
|
|
||||||
url: 'https://api.github.com/orgs/docker'
|
|
||||||
},
|
|
||||||
pusher: {
|
|
||||||
email: 'github@crazymax.dev',
|
|
||||||
name: 'crazy-max'
|
|
||||||
},
|
|
||||||
ref: 'refs/heads/dev',
|
|
||||||
repository: {
|
|
||||||
allow_forking: true,
|
|
||||||
archive_url: 'https://api.github.com/repos/docker/test-docker-action/{archive_format}{/ref}',
|
|
||||||
archived: false,
|
|
||||||
assignees_url: 'https://api.github.com/repos/docker/test-docker-action/assignees{/user}',
|
|
||||||
blobs_url: 'https://api.github.com/repos/docker/test-docker-action/git/blobs{/sha}',
|
|
||||||
branches_url: 'https://api.github.com/repos/docker/test-docker-action/branches{/branch}',
|
|
||||||
clone_url: 'https://github.com/docker/test-docker-action.git',
|
|
||||||
collaborators_url: 'https://api.github.com/repos/docker/test-docker-action/collaborators{/collaborator}',
|
|
||||||
comments_url: 'https://api.github.com/repos/docker/test-docker-action/comments{/number}',
|
|
||||||
commits_url: 'https://api.github.com/repos/docker/test-docker-action/commits{/sha}',
|
|
||||||
compare_url: 'https://api.github.com/repos/docker/test-docker-action/compare/{base}...{head}',
|
|
||||||
contents_url: 'https://api.github.com/repos/docker/test-docker-action/contents/{+path}',
|
|
||||||
contributors_url: 'https://api.github.com/repos/docker/test-docker-action/contributors',
|
|
||||||
created_at: 1596792180,
|
|
||||||
default_branch: 'master',
|
|
||||||
deployments_url: 'https://api.github.com/repos/docker/test-docker-action/deployments',
|
|
||||||
description: 'Test "Docker" Actions',
|
|
||||||
disabled: false,
|
|
||||||
downloads_url: 'https://api.github.com/repos/docker/test-docker-action/downloads',
|
|
||||||
events_url: 'https://api.github.com/repos/docker/test-docker-action/events',
|
|
||||||
fork: false,
|
|
||||||
forks: 1,
|
|
||||||
forks_count: 1,
|
|
||||||
forks_url: 'https://api.github.com/repos/docker/test-docker-action/forks',
|
|
||||||
full_name: 'docker/test-docker-action',
|
|
||||||
git_commits_url: 'https://api.github.com/repos/docker/test-docker-action/git/commits{/sha}',
|
|
||||||
git_refs_url: 'https://api.github.com/repos/docker/test-docker-action/git/refs{/sha}',
|
|
||||||
git_tags_url: 'https://api.github.com/repos/docker/test-docker-action/git/tags{/sha}',
|
|
||||||
git_url: 'git://github.com/docker/test-docker-action.git',
|
|
||||||
has_downloads: true,
|
|
||||||
has_issues: true,
|
|
||||||
has_pages: false,
|
|
||||||
has_projects: true,
|
|
||||||
has_wiki: true,
|
|
||||||
homepage: '',
|
|
||||||
hooks_url: 'https://api.github.com/repos/docker/test-docker-action/hooks',
|
|
||||||
html_url: 'https://github.com/docker/test-docker-action',
|
|
||||||
id: 285789493,
|
|
||||||
is_template: false,
|
|
||||||
issue_comment_url: 'https://api.github.com/repos/docker/test-docker-action/issues/comments{/number}',
|
|
||||||
issue_events_url: 'https://api.github.com/repos/docker/test-docker-action/issues/events{/number}',
|
|
||||||
issues_url: 'https://api.github.com/repos/docker/test-docker-action/issues{/number}',
|
|
||||||
keys_url: 'https://api.github.com/repos/docker/test-docker-action/keys{/key_id}',
|
|
||||||
labels_url: 'https://api.github.com/repos/docker/test-docker-action/labels{/name}',
|
|
||||||
language: 'JavaScript',
|
|
||||||
languages_url: 'https://api.github.com/repos/docker/test-docker-action/languages',
|
|
||||||
license: {
|
|
||||||
key: 'mit',
|
|
||||||
name: 'MIT License',
|
|
||||||
node_id: 'MDc6TGljZW5zZTEz',
|
|
||||||
spdx_id: 'MIT',
|
|
||||||
url: 'https://api.github.com/licenses/mit'
|
|
||||||
},
|
|
||||||
master_branch: 'master',
|
|
||||||
merges_url: 'https://api.github.com/repos/docker/test-docker-action/merges',
|
|
||||||
milestones_url: 'https://api.github.com/repos/docker/test-docker-action/milestones{/number}',
|
|
||||||
mirror_url: null,
|
|
||||||
name: 'test-docker-action',
|
|
||||||
node_id: 'MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=',
|
|
||||||
notifications_url: 'https://api.github.com/repos/docker/test-docker-action/notifications{?since,all,participating}',
|
|
||||||
open_issues: 6,
|
|
||||||
open_issues_count: 6,
|
|
||||||
organization: 'docker',
|
|
||||||
owner: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
|
||||||
email: 'info@docker.com',
|
|
||||||
events_url: 'https://api.github.com/users/docker/events{/privacy}',
|
|
||||||
followers_url: 'https://api.github.com/users/docker/followers',
|
|
||||||
following_url: 'https://api.github.com/users/docker/following{/other_user}',
|
|
||||||
gists_url: 'https://api.github.com/users/docker/gists{/gist_id}',
|
|
||||||
gravatar_id: '',
|
|
||||||
html_url: 'https://github.com/docker',
|
|
||||||
id: 5429470,
|
|
||||||
login: 'docker',
|
|
||||||
name: 'docker',
|
|
||||||
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
|
||||||
organizations_url: 'https://api.github.com/users/docker/orgs',
|
|
||||||
received_events_url: 'https://api.github.com/users/docker/received_events',
|
|
||||||
repos_url: 'https://api.github.com/users/docker/repos',
|
|
||||||
site_admin: false,
|
|
||||||
starred_url: 'https://api.github.com/users/docker/starred{/owner}{/repo}',
|
|
||||||
subscriptions_url: 'https://api.github.com/users/docker/subscriptions',
|
|
||||||
type: 'Organization',
|
|
||||||
url: 'https://api.github.com/users/docker'
|
|
||||||
},
|
|
||||||
private: true,
|
|
||||||
pulls_url: 'https://api.github.com/repos/docker/test-docker-action/pulls{/number}',
|
|
||||||
pushed_at: 1650360446,
|
|
||||||
releases_url: 'https://api.github.com/repos/docker/test-docker-action/releases{/id}',
|
|
||||||
size: 796,
|
|
||||||
ssh_url: 'git@github.com:docker/test-docker-action.git',
|
|
||||||
stargazers: 0,
|
|
||||||
stargazers_count: 0,
|
|
||||||
stargazers_url: 'https://api.github.com/repos/docker/test-docker-action/stargazers',
|
|
||||||
statuses_url: 'https://api.github.com/repos/docker/test-docker-action/statuses/{sha}',
|
|
||||||
subscribers_url: 'https://api.github.com/repos/docker/test-docker-action/subscribers',
|
|
||||||
subscription_url: 'https://api.github.com/repos/docker/test-docker-action/subscription',
|
|
||||||
svn_url: 'https://github.com/docker/test-docker-action',
|
|
||||||
tags_url: 'https://api.github.com/repos/docker/test-docker-action/tags',
|
|
||||||
teams_url: 'https://api.github.com/repos/docker/test-docker-action/teams',
|
|
||||||
topics: [],
|
|
||||||
trees_url: 'https://api.github.com/repos/docker/test-docker-action/git/trees{/sha}',
|
|
||||||
updated_at: '2022-04-19T09:05:09Z',
|
|
||||||
url: 'https://github.com/docker/test-docker-action',
|
|
||||||
visibility: 'private',
|
|
||||||
watchers: 0,
|
|
||||||
watchers_count: 0
|
|
||||||
},
|
|
||||||
sender: {
|
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/1951866?v=4',
|
|
||||||
events_url: 'https://api.github.com/users/crazy-max/events{/privacy}',
|
|
||||||
followers_url: 'https://api.github.com/users/crazy-max/followers',
|
|
||||||
following_url: 'https://api.github.com/users/crazy-max/following{/other_user}',
|
|
||||||
gists_url: 'https://api.github.com/users/crazy-max/gists{/gist_id}',
|
|
||||||
gravatar_id: '',
|
|
||||||
html_url: 'https://github.com/crazy-max',
|
|
||||||
id: 1951866,
|
|
||||||
login: 'crazy-max',
|
|
||||||
node_id: 'MDQ6VXNlcjE5NTE4NjY=',
|
|
||||||
organizations_url: 'https://api.github.com/users/crazy-max/orgs',
|
|
||||||
received_events_url: 'https://api.github.com/users/crazy-max/received_events',
|
|
||||||
repos_url: 'https://api.github.com/users/crazy-max/repos',
|
|
||||||
site_admin: false,
|
|
||||||
starred_url: 'https://api.github.com/users/crazy-max/starred{/owner}{/repo}',
|
|
||||||
subscriptions_url: 'https://api.github.com/users/crazy-max/subscriptions',
|
|
||||||
type: 'User',
|
|
||||||
url: 'https://api.github.com/users/crazy-max'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getOctokit = jest.fn(() => ({
|
|
||||||
rest: {
|
|
||||||
repos: {
|
|
||||||
getCommit: jest.fn(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
data: {
|
|
||||||
commit: {
|
|
||||||
committer: {
|
|
||||||
date: '2024-11-13T13:42:28Z'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {afterEach, beforeEach, describe, expect, test, it, jest} from '@jest/globals';
|
import {afterEach, beforeEach, describe, expect, test, it, vi} from 'vitest';
|
||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from 'dotenv';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
@@ -7,14 +7,25 @@ import {Git} from '@docker/actions-toolkit/lib/git';
|
|||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
|
|
||||||
import {ContextSource, getContext, getInputs, Inputs} from '../src/context';
|
import * as context from '../src/context';
|
||||||
|
|
||||||
const toolkit = new Toolkit({githubToken: 'fake-github-token'});
|
const toolkit = new Toolkit({githubToken: 'fake-github-token'});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
||||||
return new Context();
|
const ctx = new Context();
|
||||||
|
const payload = ctx.payload as {
|
||||||
|
commits?: Array<{id: string; timestamp: string}>;
|
||||||
|
head_commit?: {id: string; timestamp: string};
|
||||||
|
};
|
||||||
|
if (ctx.sha && !payload.commits?.length && !payload.head_commit) {
|
||||||
|
payload.head_commit = {
|
||||||
|
id: ctx.sha,
|
||||||
|
timestamp: '2024-11-13T13:42:28.000Z'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return ctx;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -29,14 +40,14 @@ describe('getInputs', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each([
|
const cases: [number, Map<string, string>, context.Inputs][] = [
|
||||||
[
|
[
|
||||||
0,
|
0,
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'],
|
['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'],
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
context: ContextSource.workflow,
|
context: context.ContextSource.workflow,
|
||||||
bakeTarget: 'docker-metadata-action',
|
bakeTarget: 'docker-metadata-action',
|
||||||
flavor: [],
|
flavor: [],
|
||||||
githubToken: '',
|
githubToken: '',
|
||||||
@@ -47,7 +58,7 @@ describe('getInputs', () => {
|
|||||||
sepTags: '\n',
|
sepTags: '\n',
|
||||||
sepAnnotations: '\n',
|
sepAnnotations: '\n',
|
||||||
tags: [],
|
tags: [],
|
||||||
} as Inputs
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
@@ -59,7 +70,7 @@ describe('getInputs', () => {
|
|||||||
['sep-annotations', ',']
|
['sep-annotations', ',']
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
context: ContextSource.workflow,
|
context: context.ContextSource.workflow,
|
||||||
bakeTarget: 'metadata',
|
bakeTarget: 'metadata',
|
||||||
flavor: [],
|
flavor: [],
|
||||||
githubToken: '',
|
githubToken: '',
|
||||||
@@ -70,7 +81,7 @@ describe('getInputs', () => {
|
|||||||
sepTags: ',',
|
sepTags: ',',
|
||||||
sepAnnotations: ',',
|
sepAnnotations: ',',
|
||||||
tags: [],
|
tags: [],
|
||||||
} as Inputs
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
2,
|
2,
|
||||||
@@ -78,7 +89,7 @@ describe('getInputs', () => {
|
|||||||
['images', 'moby/buildkit\n#comment\nghcr.io/moby/mbuildkit'],
|
['images', 'moby/buildkit\n#comment\nghcr.io/moby/mbuildkit'],
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
context: ContextSource.workflow,
|
context: context.ContextSource.workflow,
|
||||||
bakeTarget: 'docker-metadata-action',
|
bakeTarget: 'docker-metadata-action',
|
||||||
flavor: [],
|
flavor: [],
|
||||||
githubToken: '',
|
githubToken: '',
|
||||||
@@ -89,23 +100,21 @@ describe('getInputs', () => {
|
|||||||
sepTags: '\n',
|
sepTags: '\n',
|
||||||
sepAnnotations: '\n',
|
sepAnnotations: '\n',
|
||||||
tags: [],
|
tags: [],
|
||||||
} as Inputs
|
}
|
||||||
],
|
],
|
||||||
])(
|
];
|
||||||
'[%d] given %p as inputs, returns %p',
|
test.each(cases)('[%d] given %o as inputs, returns %o', async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
||||||
async (num: number, inputs: Map<string, string>, expected: Inputs) => {
|
|
||||||
inputs.forEach((value: string, name: string) => {
|
inputs.forEach((value: string, name: string) => {
|
||||||
setInput(name, value);
|
setInput(name, value);
|
||||||
});
|
});
|
||||||
expect(await getInputs()).toEqual(expected);
|
const res = await context.getInputs();
|
||||||
}
|
expect(res).toEqual(expected);
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getContext', () => {
|
describe('getContext', () => {
|
||||||
const originalEnv = process.env;
|
const originalEnv = process.env;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
|
||||||
process.env = {
|
process.env = {
|
||||||
...originalEnv,
|
...originalEnv,
|
||||||
...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env')))
|
...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env')))
|
||||||
@@ -116,26 +125,26 @@ describe('getContext', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('workflow', async () => {
|
it('workflow', async () => {
|
||||||
const context = await getContext(ContextSource.workflow, toolkit);
|
const ctx = await context.getContext(context.ContextSource.workflow, toolkit);
|
||||||
expect(context.ref).toEqual('refs/heads/dev');
|
expect(ctx.ref).toEqual('refs/heads/dev');
|
||||||
expect(context.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a');
|
expect(ctx.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a');
|
||||||
expect(context.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
expect(ctx.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('git', async () => {
|
it('git', async () => {
|
||||||
jest.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
|
vi.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
ref: 'refs/heads/git-test',
|
ref: 'refs/heads/git-test',
|
||||||
sha: 'git-test-sha'
|
sha: 'git-test-sha'
|
||||||
} as Context);
|
} as Context);
|
||||||
});
|
});
|
||||||
jest.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
vi.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
||||||
return new Date('2023-01-01T13:42:28.000Z');
|
return new Date('2023-01-01T13:42:28.000Z');
|
||||||
});
|
});
|
||||||
const context = await getContext(ContextSource.git, toolkit);
|
const ctx = await context.getContext(context.ContextSource.git, toolkit);
|
||||||
expect(context.ref).toEqual('refs/heads/git-test');
|
expect(ctx.ref).toEqual('refs/heads/git-test');
|
||||||
expect(context.sha).toEqual('git-test-sha');
|
expect(ctx.sha).toEqual('git-test-sha');
|
||||||
expect(context.commitDate).toEqual(new Date('2023-01-01T13:42:28.000Z'));
|
expect(ctx.commitDate).toEqual(new Date('2023-01-01T13:42:28.000Z'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from 'vitest';
|
||||||
|
|
||||||
import {Flavor, Transform} from '../src/flavor';
|
import {Flavor, Transform} from '../src/flavor';
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ describe('transform', () => {
|
|||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line jest/no-conditional-expect
|
// eslint-disable-next-line @vitest/no-conditional-expect
|
||||||
expect(true).toBe(invalid);
|
expect(true).toBe(invalid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from 'vitest';
|
||||||
|
|
||||||
import {Transform, Image} from '../src/image';
|
import {Transform, Image} from '../src/image';
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ describe('transform', () => {
|
|||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line jest/no-conditional-expect
|
// eslint-disable-next-line @vitest/no-conditional-expect
|
||||||
expect(true).toBe(invalid);
|
expect(true).toBe(invalid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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 fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from 'dotenv';
|
||||||
@@ -13,27 +13,33 @@ import {Meta, Version} from '../src/meta';
|
|||||||
|
|
||||||
import repoFixture from './fixtures/repo.json';
|
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);
|
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';
|
return '2020-01-10T00:30:00.000Z';
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.mock('moment-timezone', () => {
|
vi.mock('moment-timezone', async () => {
|
||||||
return () => (jest.requireActual('moment-timezone') as typeof import('moment-timezone'))('2020-01-10T00:30:00.000Z');
|
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(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
Object.keys(process.env).forEach(function (key) {
|
Object.keys(process.env).forEach(function (key) {
|
||||||
if (key !== 'GITHUB_TOKEN' && key.startsWith('GITHUB_')) {
|
if (key !== 'GITHUB_TOKEN' && key.startsWith('GITHUB_')) {
|
||||||
delete process.env[key];
|
delete process.env[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
||||||
//@ts-expect-error partial info
|
//@ts-expect-error partial info
|
||||||
return {
|
return {
|
||||||
...new Context(),
|
...new Context(),
|
||||||
@@ -53,7 +59,7 @@ describe('isRawStatement', () => {
|
|||||||
['{{ raw }}', true],
|
['{{ raw }}', true],
|
||||||
['{{ raw}}', true],
|
['{{ 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);
|
expect(Meta.isRawStatement(pattern)).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -79,7 +85,7 @@ const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exV
|
|||||||
|
|
||||||
describe('null', () => {
|
describe('null', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'null01',
|
'null01',
|
||||||
@@ -133,12 +139,12 @@ describe('null', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('push', () => {
|
describe('push', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'push01',
|
'push01',
|
||||||
@@ -856,12 +862,12 @@ describe('push', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
]
|
]
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tag', () => {
|
describe('tag', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'tag01',
|
'tag01',
|
||||||
@@ -2035,12 +2041,12 @@ describe('tag', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
]
|
]
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('latest', () => {
|
describe('latest', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'latest01',
|
'latest01',
|
||||||
@@ -2377,12 +2383,12 @@ describe('latest', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
]
|
]
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('pr', () => {
|
describe('pr', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'pr01',
|
'pr01',
|
||||||
@@ -2765,7 +2771,7 @@ describe('pr', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('pr-head-sha', () => {
|
describe('pr-head-sha', () => {
|
||||||
@@ -3140,7 +3146,7 @@ describe('pr-head-sha', () => {
|
|||||||
"org.opencontainers.image.version=src-2020-01-10T00-30-00Z",
|
"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 = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
process.env.DOCKER_METADATA_PR_HEAD_SHA = 'true';
|
process.env.DOCKER_METADATA_PR_HEAD_SHA = 'true';
|
||||||
|
|
||||||
@@ -3164,7 +3170,7 @@ describe('pr-head-sha', () => {
|
|||||||
|
|
||||||
describe('schedule', () => {
|
describe('schedule', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'schedule01',
|
'schedule01',
|
||||||
@@ -3423,12 +3429,12 @@ describe('schedule', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
])('given %p with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('release', () => {
|
describe('release', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'release01',
|
'release01',
|
||||||
@@ -3525,12 +3531,12 @@ describe('release', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
]
|
]
|
||||||
])('given %s with %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('raw', () => {
|
describe('raw', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// eslint-disable-next-line @vitest/expect-expect
|
||||||
test.each([
|
test.each([
|
||||||
[
|
[
|
||||||
'raw01',
|
'raw01',
|
||||||
@@ -3905,7 +3911,7 @@ describe('raw', () => {
|
|||||||
],
|
],
|
||||||
undefined
|
undefined
|
||||||
],
|
],
|
||||||
])('given %p wth %p event', tagsLabelsTest);
|
])('given %o with %o event', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('json', () => {
|
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)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
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)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
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)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
const toolkit = new Toolkit();
|
||||||
@@ -4882,7 +4888,7 @@ describe('sepTags', () => {
|
|||||||
} as Inputs,
|
} as Inputs,
|
||||||
"user/app:dev,user/app:my,user/app:custom,user/app:tags"
|
"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)));
|
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
const toolkit = new Toolkit();
|
||||||
|
|||||||
235
__tests__/setup.unit.ts
Normal file
235
__tests__/setup.unit.ts
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import {vi} from 'vitest';
|
||||||
|
|
||||||
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
|
||||||
|
|
||||||
|
process.env = Object.assign({}, process.env, {
|
||||||
|
TEMP: tmpDir,
|
||||||
|
GITHUB_REPOSITORY: 'docker/metadata-action',
|
||||||
|
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
|
||||||
|
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock('@actions/github', () => ({
|
||||||
|
context: {
|
||||||
|
repo: {
|
||||||
|
owner: 'docker',
|
||||||
|
repo: 'actions-toolkit'
|
||||||
|
},
|
||||||
|
ref: 'refs/heads/master',
|
||||||
|
runId: 2188748038,
|
||||||
|
runNumber: 15,
|
||||||
|
payload: {
|
||||||
|
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
base_ref: null,
|
||||||
|
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
||||||
|
commits: [
|
||||||
|
{
|
||||||
|
author: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
committer: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
distinct: true,
|
||||||
|
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
message: 'hello dev',
|
||||||
|
timestamp: '2022-04-19T11:27:24+02:00',
|
||||||
|
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
||||||
|
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
|
||||||
|
created: false,
|
||||||
|
deleted: false,
|
||||||
|
forced: false,
|
||||||
|
head_commit: {
|
||||||
|
author: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
committer: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
distinct: true,
|
||||||
|
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
message: 'hello dev',
|
||||||
|
timestamp: '2022-04-19T11:27:24+02:00',
|
||||||
|
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
||||||
|
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
||||||
|
},
|
||||||
|
organization: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
||||||
|
description: 'Docker helps developers bring their ideas to life by conquering the complexity of app development.',
|
||||||
|
events_url: 'https://api.github.com/orgs/docker/events',
|
||||||
|
hooks_url: 'https://api.github.com/orgs/docker/hooks',
|
||||||
|
id: 5429470,
|
||||||
|
issues_url: 'https://api.github.com/orgs/docker/issues',
|
||||||
|
login: 'docker',
|
||||||
|
members_url: 'https://api.github.com/orgs/docker/members{/member}',
|
||||||
|
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
||||||
|
public_members_url: 'https://api.github.com/orgs/docker/public_members{/member}',
|
||||||
|
repos_url: 'https://api.github.com/orgs/docker/repos',
|
||||||
|
url: 'https://api.github.com/orgs/docker'
|
||||||
|
},
|
||||||
|
pusher: {
|
||||||
|
email: 'github@crazymax.dev',
|
||||||
|
name: 'crazy-max'
|
||||||
|
},
|
||||||
|
ref: 'refs/heads/dev',
|
||||||
|
repository: {
|
||||||
|
allow_forking: true,
|
||||||
|
archive_url: 'https://api.github.com/repos/docker/test-docker-action/{archive_format}{/ref}',
|
||||||
|
archived: false,
|
||||||
|
assignees_url: 'https://api.github.com/repos/docker/test-docker-action/assignees{/user}',
|
||||||
|
blobs_url: 'https://api.github.com/repos/docker/test-docker-action/git/blobs{/sha}',
|
||||||
|
branches_url: 'https://api.github.com/repos/docker/test-docker-action/branches{/branch}',
|
||||||
|
clone_url: 'https://github.com/docker/test-docker-action.git',
|
||||||
|
collaborators_url: 'https://api.github.com/repos/docker/test-docker-action/collaborators{/collaborator}',
|
||||||
|
comments_url: 'https://api.github.com/repos/docker/test-docker-action/comments{/number}',
|
||||||
|
commits_url: 'https://api.github.com/repos/docker/test-docker-action/commits{/sha}',
|
||||||
|
compare_url: 'https://api.github.com/repos/docker/test-docker-action/compare/{base}...{head}',
|
||||||
|
contents_url: 'https://api.github.com/repos/docker/test-docker-action/contents/{+path}',
|
||||||
|
contributors_url: 'https://api.github.com/repos/docker/test-docker-action/contributors',
|
||||||
|
created_at: 1596792180,
|
||||||
|
default_branch: 'master',
|
||||||
|
deployments_url: 'https://api.github.com/repos/docker/test-docker-action/deployments',
|
||||||
|
description: 'Test "Docker" Actions',
|
||||||
|
disabled: false,
|
||||||
|
downloads_url: 'https://api.github.com/repos/docker/test-docker-action/downloads',
|
||||||
|
events_url: 'https://api.github.com/repos/docker/test-docker-action/events',
|
||||||
|
fork: false,
|
||||||
|
forks: 1,
|
||||||
|
forks_count: 1,
|
||||||
|
forks_url: 'https://api.github.com/repos/docker/test-docker-action/forks',
|
||||||
|
full_name: 'docker/test-docker-action',
|
||||||
|
git_commits_url: 'https://api.github.com/repos/docker/test-docker-action/git/commits{/sha}',
|
||||||
|
git_refs_url: 'https://api.github.com/repos/docker/test-docker-action/git/refs{/sha}',
|
||||||
|
git_tags_url: 'https://api.github.com/repos/docker/test-docker-action/git/tags{/sha}',
|
||||||
|
git_url: 'git://github.com/docker/test-docker-action.git',
|
||||||
|
has_downloads: true,
|
||||||
|
has_issues: true,
|
||||||
|
has_pages: false,
|
||||||
|
has_projects: true,
|
||||||
|
has_wiki: true,
|
||||||
|
homepage: '',
|
||||||
|
hooks_url: 'https://api.github.com/repos/docker/test-docker-action/hooks',
|
||||||
|
html_url: 'https://github.com/docker/test-docker-action',
|
||||||
|
id: 285789493,
|
||||||
|
is_template: false,
|
||||||
|
issue_comment_url: 'https://api.github.com/repos/docker/test-docker-action/issues/comments{/number}',
|
||||||
|
issue_events_url: 'https://api.github.com/repos/docker/test-docker-action/issues/events{/number}',
|
||||||
|
issues_url: 'https://api.github.com/repos/docker/test-docker-action/issues{/number}',
|
||||||
|
keys_url: 'https://api.github.com/repos/docker/test-docker-action/keys{/key_id}',
|
||||||
|
labels_url: 'https://api.github.com/repos/docker/test-docker-action/labels{/name}',
|
||||||
|
language: 'JavaScript',
|
||||||
|
languages_url: 'https://api.github.com/repos/docker/test-docker-action/languages',
|
||||||
|
license: {
|
||||||
|
key: 'mit',
|
||||||
|
name: 'MIT License',
|
||||||
|
node_id: 'MDc6TGljZW5zZTEz',
|
||||||
|
spdx_id: 'MIT',
|
||||||
|
url: 'https://api.github.com/licenses/mit'
|
||||||
|
},
|
||||||
|
master_branch: 'master',
|
||||||
|
merges_url: 'https://api.github.com/repos/docker/test-docker-action/merges',
|
||||||
|
milestones_url: 'https://api.github.com/repos/docker/test-docker-action/milestones{/number}',
|
||||||
|
mirror_url: null,
|
||||||
|
name: 'test-docker-action',
|
||||||
|
node_id: 'MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=',
|
||||||
|
notifications_url: 'https://api.github.com/repos/docker/test-docker-action/notifications{?since,all,participating}',
|
||||||
|
open_issues: 6,
|
||||||
|
open_issues_count: 6,
|
||||||
|
organization: 'docker',
|
||||||
|
owner: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
||||||
|
email: 'info@docker.com',
|
||||||
|
events_url: 'https://api.github.com/users/docker/events{/privacy}',
|
||||||
|
followers_url: 'https://api.github.com/users/docker/followers',
|
||||||
|
following_url: 'https://api.github.com/users/docker/following{/other_user}',
|
||||||
|
gists_url: 'https://api.github.com/users/docker/gists{/gist_id}',
|
||||||
|
gravatar_id: '',
|
||||||
|
html_url: 'https://github.com/docker',
|
||||||
|
id: 5429470,
|
||||||
|
login: 'docker',
|
||||||
|
name: 'docker',
|
||||||
|
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
||||||
|
organizations_url: 'https://api.github.com/users/docker/orgs',
|
||||||
|
received_events_url: 'https://api.github.com/users/docker/received_events',
|
||||||
|
repos_url: 'https://api.github.com/users/docker/repos',
|
||||||
|
site_admin: false,
|
||||||
|
starred_url: 'https://api.github.com/users/docker/starred{/owner}{/repo}',
|
||||||
|
subscriptions_url: 'https://api.github.com/users/docker/subscriptions',
|
||||||
|
type: 'Organization',
|
||||||
|
url: 'https://api.github.com/users/docker'
|
||||||
|
},
|
||||||
|
private: true,
|
||||||
|
pulls_url: 'https://api.github.com/repos/docker/test-docker-action/pulls{/number}',
|
||||||
|
pushed_at: 1650360446,
|
||||||
|
releases_url: 'https://api.github.com/repos/docker/test-docker-action/releases{/id}',
|
||||||
|
size: 796,
|
||||||
|
ssh_url: 'git@github.com:docker/test-docker-action.git',
|
||||||
|
stargazers: 0,
|
||||||
|
stargazers_count: 0,
|
||||||
|
stargazers_url: 'https://api.github.com/repos/docker/test-docker-action/stargazers',
|
||||||
|
statuses_url: 'https://api.github.com/repos/docker/test-docker-action/statuses/{sha}',
|
||||||
|
subscribers_url: 'https://api.github.com/repos/docker/test-docker-action/subscribers',
|
||||||
|
subscription_url: 'https://api.github.com/repos/docker/test-docker-action/subscription',
|
||||||
|
svn_url: 'https://github.com/docker/test-docker-action',
|
||||||
|
tags_url: 'https://api.github.com/repos/docker/test-docker-action/tags',
|
||||||
|
teams_url: 'https://api.github.com/repos/docker/test-docker-action/teams',
|
||||||
|
topics: [],
|
||||||
|
trees_url: 'https://api.github.com/repos/docker/test-docker-action/git/trees{/sha}',
|
||||||
|
updated_at: '2022-04-19T09:05:09Z',
|
||||||
|
url: 'https://github.com/docker/test-docker-action',
|
||||||
|
visibility: 'private',
|
||||||
|
watchers: 0,
|
||||||
|
watchers_count: 0
|
||||||
|
},
|
||||||
|
sender: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/1951866?v=4',
|
||||||
|
events_url: 'https://api.github.com/users/crazy-max/events{/privacy}',
|
||||||
|
followers_url: 'https://api.github.com/users/crazy-max/followers',
|
||||||
|
following_url: 'https://api.github.com/users/crazy-max/following{/other_user}',
|
||||||
|
gists_url: 'https://api.github.com/users/crazy-max/gists{/gist_id}',
|
||||||
|
gravatar_id: '',
|
||||||
|
html_url: 'https://github.com/crazy-max',
|
||||||
|
id: 1951866,
|
||||||
|
login: 'crazy-max',
|
||||||
|
node_id: 'MDQ6VXNlcjE5NTE4NjY=',
|
||||||
|
organizations_url: 'https://api.github.com/users/crazy-max/orgs',
|
||||||
|
received_events_url: 'https://api.github.com/users/crazy-max/received_events',
|
||||||
|
repos_url: 'https://api.github.com/users/crazy-max/repos',
|
||||||
|
site_admin: false,
|
||||||
|
starred_url: 'https://api.github.com/users/crazy-max/starred{/owner}{/repo}',
|
||||||
|
subscriptions_url: 'https://api.github.com/users/crazy-max/subscriptions',
|
||||||
|
type: 'User',
|
||||||
|
url: 'https://api.github.com/users/crazy-max'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getOctokit: () => ({
|
||||||
|
rest: {
|
||||||
|
repos: {
|
||||||
|
getCommit: async () => ({
|
||||||
|
data: {
|
||||||
|
commit: {
|
||||||
|
committer: {
|
||||||
|
date: '2024-11-13T13:42:28Z'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}));
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from 'vitest';
|
||||||
|
|
||||||
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ describe('transform', () => {
|
|||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line jest/no-conditional-expect
|
// eslint-disable-next-line @vitest/no-conditional-expect
|
||||||
expect(true).toBe(invalid);
|
expect(true).toBe(invalid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -461,7 +461,7 @@ describe('parse', () => {
|
|||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line jest/no-conditional-expect
|
// eslint-disable-next-line @vitest/no-conditional-expect
|
||||||
expect(true).toBe(invalid);
|
expect(true).toBe(invalid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ FROM deps AS test
|
|||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/.yarn/cache \
|
--mount=type=cache,target=/src/.yarn/cache \
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run test --coverage --coverageDirectory=/tmp/coverage
|
yarn run test --coverage --coverage.reportsDirectory=/tmp/coverage
|
||||||
|
|
||||||
FROM scratch AS test-coverage
|
FROM scratch AS test-coverage
|
||||||
COPY --from=test /tmp/coverage /
|
COPY --from=test /tmp/coverage /
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
const {defineConfig, globalIgnores} = require('eslint/config');
|
const {defineConfig, globalIgnores} = require('eslint/config');
|
||||||
const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat');
|
const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat');
|
||||||
const typescriptEslint = require('@typescript-eslint/eslint-plugin');
|
const typescriptEslint = require('@typescript-eslint/eslint-plugin');
|
||||||
const jestPlugin = require('eslint-plugin-jest');
|
const vitestPlugin = require('@vitest/eslint-plugin');
|
||||||
const prettier = require('eslint-plugin-prettier');
|
const prettier = require('eslint-plugin-prettier');
|
||||||
const globals = require('globals');
|
const globals = require('globals');
|
||||||
const tsParser = require('@typescript-eslint/parser');
|
const tsParser = require('@typescript-eslint/parser');
|
||||||
@@ -25,21 +25,21 @@ module.exports = defineConfig([
|
|||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:@typescript-eslint/eslint-recommended',
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
'plugin:jest/recommended',
|
'plugin:@vitest/legacy-recommended',
|
||||||
'plugin:prettier/recommended'
|
'plugin:prettier/recommended'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
plugins: {
|
plugins: {
|
||||||
'@typescript-eslint': fixupPluginRules(typescriptEslint),
|
'@typescript-eslint': fixupPluginRules(typescriptEslint),
|
||||||
jest: fixupPluginRules(jestPlugin),
|
'@vitest': fixupPluginRules(vitestPlugin),
|
||||||
prettier: fixupPluginRules(prettier)
|
prettier: fixupPluginRules(prettier)
|
||||||
},
|
},
|
||||||
|
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
globals: {
|
||||||
...globals.node,
|
...globals.node,
|
||||||
...globals.jest
|
...vitestPlugin.environments.env.globals
|
||||||
},
|
},
|
||||||
parser: tsParser,
|
parser: tsParser,
|
||||||
ecmaVersion: 'latest',
|
ecmaVersion: 'latest',
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
||||||
const fs = require('fs');
|
|
||||||
const os = require('os');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
|
|
||||||
|
|
||||||
process.env = Object.assign({}, process.env, {
|
|
||||||
TEMP: tmpDir,
|
|
||||||
GITHUB_REPOSITORY: 'docker/metadata-action',
|
|
||||||
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
|
|
||||||
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
clearMocks: true,
|
|
||||||
testEnvironment: 'node',
|
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
|
||||||
setupFiles: ['dotenv/config'],
|
|
||||||
testMatch: ['**/*.test.ts'],
|
|
||||||
transform: {
|
|
||||||
'^.+\\.ts$': 'ts-jest'
|
|
||||||
},
|
|
||||||
moduleNameMapper: {
|
|
||||||
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
|
||||||
},
|
|
||||||
collectCoverageFrom: ['src/**/{!(main.ts),}.ts'],
|
|
||||||
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
10
package.json
10
package.json
@@ -10,7 +10,7 @@
|
|||||||
"eslint:fix": "eslint --fix .",
|
"eslint:fix": "eslint --fix .",
|
||||||
"prettier": "prettier --check \"./**/*.ts\"",
|
"prettier": "prettier --check \"./**/*.ts\"",
|
||||||
"prettier:fix": "prettier --write \"./**/*.ts\"",
|
"prettier:fix": "prettier --write \"./**/*.ts\"",
|
||||||
"test": "jest"
|
"test": "vitest run"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -45,15 +45,15 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
||||||
"@typescript-eslint/parser": "^8.50.0",
|
"@typescript-eslint/parser": "^8.50.0",
|
||||||
"@vercel/ncc": "^0.38.4",
|
"@vercel/ncc": "^0.38.4",
|
||||||
|
"@vitest/coverage-v8": "^4.0.18",
|
||||||
|
"@vitest/eslint-plugin": "^1.6.9",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"eslint": "^9.39.2",
|
"eslint": "^9.39.2",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-jest": "^29.5.0",
|
|
||||||
"eslint-plugin-prettier": "^5.5.4",
|
"eslint-plugin-prettier": "^5.5.4",
|
||||||
"jest": "^30.2.0",
|
|
||||||
"prettier": "^3.7.4",
|
"prettier": "^3.7.4",
|
||||||
"ts-jest": "^29.4.6",
|
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3",
|
||||||
|
"vitest": "^4.0.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@
|
|||||||
"./__tests__/**/*",
|
"./__tests__/**/*",
|
||||||
"./lib/**/*",
|
"./lib/**/*",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"jest.config.ts"
|
"vitest.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
16
vitest.config.ts
Normal file
16
vitest.config.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import {defineConfig} from 'vitest/config';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
clearMocks: true,
|
||||||
|
environment: 'node',
|
||||||
|
setupFiles: ['./__tests__/setup.unit.ts'],
|
||||||
|
include: ['**/*.test.ts'],
|
||||||
|
coverage: {
|
||||||
|
provider: 'v8',
|
||||||
|
reporter: ['clover'],
|
||||||
|
include: ['src/**/*.ts'],
|
||||||
|
exclude: ['src/**/main.ts']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user