forked from mathieudutour/github-tag-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.test.ts
More file actions
59 lines (52 loc) · 1.66 KB
/
Copy pathgithub.test.ts
File metadata and controls
59 lines (52 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { describe, expect, it, vi } from 'vitest';
import { listTags } from '../src/github.js';
// Vitest statically hoists `vi.mock(...)` calls above every static
// `import` in the file, so the factory below is registered before
// `../src/github.js` is evaluated even though it appears afterwards
// textually.
vi.mock('@actions/github', () => ({
context: { repo: { owner: 'mock-owner', repo: 'mock-repo' } },
getOctokit: vi.fn().mockReturnValue({
rest: {
repos: {
listTags: vi.fn().mockImplementation(({ page }: { page: number }) => {
if (page === 6) {
return { data: [] };
}
const res = [...new Array(100).keys()].map((_) => ({
name: `v0.0.${_ + (page - 1) * 100}`,
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
}));
return { data: res };
}),
},
},
}),
}));
describe('github', () => {
it('returns all tags', async () => {
const tags = await listTags(true);
expect(tags.length).toEqual(500);
expect(tags[499]).toEqual({
name: 'v0.0.499',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
});
});
it('returns only the first page when shouldFetchAllTags is false', async () => {
const tags = await listTags(false);
expect(tags.length).toEqual(100);
expect(tags[99]).toEqual({
name: 'v0.0.99',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
});
});
});