Skip to content

Commit dc22dc7

Browse files
authored
Merge pull request #1975 from actions/ghadimir/update_call_to_list_artifacts
Compare Artifact Digests
2 parents d70fb49 + 8c05dc8 commit dc22dc7

File tree

8 files changed

+432
-49
lines changed

8 files changed

+432
-49
lines changed

packages/artifact/CONTRIBUTIONS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ Any easy way to test changes for the official upload/download actions is to fork
4141
1. In the locally cloned fork, link to your local toolkit changes: `npm link @actions/artifact`
4242
2. Then, compile your changes with: `npm run release`. The local `dist/index.js` should be updated with your changes.
4343
3. Commit and push to your fork, you can then test with a `uses:` in your workflow pointed at your fork.
44+
4. The format for the above is `<username>/<repository-name>/@<ref>`, i.e. `me/myrepo/@HEAD`

packages/artifact/__tests__/download-artifact.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,6 @@ describe('download-artifact', () => {
319319

320320
const mockGet = jest.fn(async () => {
321321
return new Promise((resolve, reject) => {
322-
// Resolve with a 200 status code immediately
323-
resolve({
324-
message: msg,
325-
readBody: async () => {
326-
return Promise.resolve(`{"ok": true}`)
327-
}
328-
})
329-
330322
// Reject with an error after 31 seconds
331323
setTimeout(() => {
332324
reject(new Error('Request timeout'))

packages/artifact/__tests__/list-artifacts.test.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as github from '@actions/github'
2-
import type {RestEndpointMethods} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types'
32
import type {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types'
43
import {
54
listArtifactsInternal,
@@ -10,13 +9,13 @@ import {ArtifactServiceClientJSON, Timestamp} from '../src/generated'
109
import * as util from '../src/internal/shared/util'
1110
import {noopLogs} from './common'
1211
import {Artifact} from '../src/internal/shared/interfaces'
12+
import {RequestInterface} from '@octokit/types'
1313

14-
type MockedListWorkflowRunArtifacts = jest.MockedFunction<
15-
RestEndpointMethods['actions']['listWorkflowRunArtifacts']
16-
>
14+
type MockedRequest = jest.MockedFunction<RequestInterface<object>>
1715

1816
jest.mock('@actions/github', () => ({
1917
getOctokit: jest.fn().mockReturnValue({
18+
request: jest.fn(),
2019
rest: {
2120
actions: {
2221
listWorkflowRunArtifacts: jest.fn()
@@ -81,10 +80,10 @@ describe('list-artifact', () => {
8180

8281
describe('public', () => {
8382
it('should return a list of artifacts', async () => {
84-
const mockListArtifacts = github.getOctokit(fixtures.token).rest.actions
85-
.listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
83+
const mockRequest = github.getOctokit(fixtures.token)
84+
.request as MockedRequest
8685

87-
mockListArtifacts.mockResolvedValueOnce({
86+
mockRequest.mockResolvedValueOnce({
8887
status: 200,
8988
headers: {},
9089
url: '',
@@ -105,10 +104,10 @@ describe('list-artifact', () => {
105104
})
106105

107106
it('should return the latest artifact when latest is specified', async () => {
108-
const mockListArtifacts = github.getOctokit(fixtures.token).rest.actions
109-
.listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
107+
const mockRequest = github.getOctokit(fixtures.token)
108+
.request as MockedRequest
110109

111-
mockListArtifacts.mockResolvedValueOnce({
110+
mockRequest.mockResolvedValueOnce({
112111
status: 200,
113112
headers: {},
114113
url: '',
@@ -129,10 +128,10 @@ describe('list-artifact', () => {
129128
})
130129

131130
it('can return empty artifacts', async () => {
132-
const mockListArtifacts = github.getOctokit(fixtures.token).rest.actions
133-
.listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
131+
const mockRequest = github.getOctokit(fixtures.token)
132+
.request as MockedRequest
134133

135-
mockListArtifacts.mockResolvedValueOnce({
134+
mockRequest.mockResolvedValueOnce({
136135
status: 200,
137136
headers: {},
138137
url: '',
@@ -156,10 +155,10 @@ describe('list-artifact', () => {
156155
})
157156

158157
it('should fail if non-200 response', async () => {
159-
const mockListArtifacts = github.getOctokit(fixtures.token).rest.actions
160-
.listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
158+
const mockRequest = github.getOctokit(fixtures.token)
159+
.request as MockedRequest
161160

162-
mockListArtifacts.mockRejectedValue(new Error('boom'))
161+
mockRequest.mockRejectedValueOnce(new Error('boom'))
163162

164163
await expect(
165164
listArtifactsPublic(

0 commit comments

Comments
 (0)