|
1 | | -import {afterEach, beforeEach, describe, expect, test, it, vi} from 'vitest'; |
2 | | -import * as dotenv from 'dotenv'; |
3 | | -import * as fs from 'fs'; |
4 | | -import * as path from 'path'; |
| 1 | +import {beforeEach, describe, expect, test, it, vi} from 'vitest'; |
5 | 2 | import {Context} from '@actions/github/lib/context.js'; |
6 | 3 | import {Git} from '@docker/actions-toolkit/lib/git.js'; |
7 | | -import {GitHub} from '@docker/actions-toolkit/lib/github.js'; |
8 | 4 | import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js'; |
9 | 5 |
|
10 | 6 | import * as context from '../src/context.js'; |
11 | 7 |
|
12 | 8 | const toolkit = new Toolkit({githubToken: 'fake-github-token'}); |
13 | 9 |
|
14 | | -beforeEach(() => { |
15 | | - vi.clearAllMocks(); |
16 | | - vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => { |
17 | | - const ctx = new Context(); |
18 | | - const payload = ctx.payload as { |
19 | | - commits?: Array<{id: string; timestamp: string}>; |
20 | | - head_commit?: {id: string; timestamp: string}; |
21 | | - }; |
22 | | - if (ctx.sha && !payload.commits?.length && !payload.head_commit) { |
23 | | - payload.head_commit = { |
24 | | - id: ctx.sha, |
25 | | - timestamp: '2024-11-13T13:42:28.000Z' |
26 | | - }; |
27 | | - } |
28 | | - return ctx; |
29 | | - }); |
30 | | -}); |
31 | | - |
32 | 10 | describe('getInputs', () => { |
33 | 11 | beforeEach(() => { |
34 | 12 | process.env = Object.keys(process.env).reduce((object, key) => { |
@@ -113,24 +91,12 @@ describe('getInputs', () => { |
113 | 91 | }); |
114 | 92 |
|
115 | 93 | describe('getContext', () => { |
116 | | - const originalEnv = process.env; |
117 | | - beforeEach(() => { |
118 | | - process.env = { |
119 | | - ...originalEnv, |
120 | | - ...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env'))) |
121 | | - }; |
122 | | - }); |
123 | | - afterEach(() => { |
124 | | - process.env = originalEnv; |
125 | | - }); |
126 | | - |
127 | 94 | it('workflow', async () => { |
128 | 95 | const ctx = await context.getContext(context.ContextSource.workflow, toolkit); |
129 | 96 | expect(ctx.ref).toEqual('refs/heads/dev'); |
130 | 97 | expect(ctx.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a'); |
131 | 98 | expect(ctx.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z')); |
132 | 99 | }); |
133 | | - |
134 | 100 | it('git', async () => { |
135 | 101 | vi.spyOn(Git, 'context').mockImplementation((): Promise<Context> => { |
136 | 102 | return Promise.resolve({ |
|
0 commit comments