mirror of
				https://gitea.com/actions/download-artifact.git
				synced 2025-10-31 00:58:16 +07:00 
			
		
		
		
	Lint
This commit is contained in:
		
							parent
							
								
									96a6f165f4
								
							
						
					
					
						commit
						9a869e9c49
					
				| @ -1,19 +1,8 @@ | |||||||
| import * as core from '@actions/core' | import * as core from '@actions/core' | ||||||
| import * as github from '@actions/github' |  | ||||||
| import * as os from 'os' |  | ||||||
| import artifact, {ArtifactNotFoundError} from '@actions/artifact' | import artifact, {ArtifactNotFoundError} from '@actions/artifact' | ||||||
| import {run} from '../src/download-artifact' | import {run} from '../src/download-artifact' | ||||||
| import {Inputs} from '../src/constants' | import {Inputs} from '../src/constants' | ||||||
| 
 | 
 | ||||||
| const fixtures = { |  | ||||||
|   artifactName: 'artifact-name', |  | ||||||
|   rootDirectory: '/some/artifact/path', |  | ||||||
|   filesToUpload: [ |  | ||||||
|     '/some/artifact/path/file1.txt', |  | ||||||
|     '/some/artifact/path/file2.txt' |  | ||||||
|   ] |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| jest.mock('@actions/github', () => ({ | jest.mock('@actions/github', () => ({ | ||||||
|   context: { |   context: { | ||||||
|     repo: { |     repo: { | ||||||
| @ -27,7 +16,7 @@ jest.mock('@actions/github', () => ({ | |||||||
| 
 | 
 | ||||||
| jest.mock('@actions/core') | jest.mock('@actions/core') | ||||||
| 
 | 
 | ||||||
| /* eslint-disable no-unused-vars */ | /* eslint-disable no-unused-vars */ /* eslint-disable  @typescript-eslint/no-explicit-any */ | ||||||
| const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => { | const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => { | ||||||
|   const inputs = { |   const inputs = { | ||||||
|     [Inputs.Name]: 'artifact-name', |     [Inputs.Name]: 'artifact-name', | ||||||
| @ -55,15 +44,15 @@ describe('download', () => { | |||||||
|     jest.clearAllMocks() |     jest.clearAllMocks() | ||||||
| 
 | 
 | ||||||
|     // Mock artifact client methods
 |     // Mock artifact client methods
 | ||||||
|       jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifacts: [] }) |       .spyOn(artifact, 'listArtifacts') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifacts: []})) | ||||||
|       jest.spyOn(artifact, 'getArtifact').mockImplementation((name) => { |     jest.spyOn(artifact, 'getArtifact').mockImplementation(name => { | ||||||
|       throw new ArtifactNotFoundError(`Artifact '${name}' not found`) |       throw new ArtifactNotFoundError(`Artifact '${name}' not found`) | ||||||
|     }) |     }) | ||||||
|       jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ digestMismatch: false }) |       .spyOn(artifact, 'downloadArtifact') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({digestMismatch: false})) | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|   test('downloads a single artifact by name', async () => { |   test('downloads a single artifact by name', async () => { | ||||||
| @ -74,9 +63,9 @@ describe('download', () => { | |||||||
|       digest: 'abc123' |       digest: 'abc123' | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|       jest.spyOn(artifact, 'getArtifact').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifact: mockArtifact }) |       .spyOn(artifact, 'getArtifact') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifact: mockArtifact})) | ||||||
| 
 | 
 | ||||||
|     await run() |     await run() | ||||||
| 
 | 
 | ||||||
| @ -102,18 +91,20 @@ describe('download', () => { | |||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|     // Set up artifact mock after clearing mocks
 |     // Set up artifact mock after clearing mocks
 | ||||||
|       jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifacts: mockArtifacts }) |       .spyOn(artifact, 'listArtifacts') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifacts: mockArtifacts})) | ||||||
| 
 | 
 | ||||||
|     // Reset downloadArtifact mock as well
 |     // Reset downloadArtifact mock as well
 | ||||||
|       jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ digestMismatch: false }) |       .spyOn(artifact, 'downloadArtifact') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({digestMismatch: false})) | ||||||
| 
 | 
 | ||||||
|     await run() |     await run() | ||||||
| 
 | 
 | ||||||
|       expect(core.info).toHaveBeenCalledWith('No input name or pattern filtered specified, downloading all artifacts') |     expect(core.info).toHaveBeenCalledWith( | ||||||
|  |       'No input name or pattern filtered specified, downloading all artifacts' | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     expect(core.info).toHaveBeenCalledWith('Total of 2 artifact(s) downloaded') |     expect(core.info).toHaveBeenCalledWith('Total of 2 artifact(s) downloaded') | ||||||
|     expect(artifact.downloadArtifact).toHaveBeenCalledTimes(2) |     expect(artifact.downloadArtifact).toHaveBeenCalledTimes(2) | ||||||
| @ -133,9 +124,7 @@ describe('download', () => { | |||||||
|       'Download artifact has finished successfully' |       'Download artifact has finished successfully' | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|       expect(core.info).toHaveBeenCalledWith( |     expect(core.info).toHaveBeenCalledWith('Total of 0 artifact(s) downloaded') | ||||||
|         'Total of 0 artifact(s) downloaded' |  | ||||||
|       ) |  | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|   test('filters artifacts by pattern', async () => { |   test('filters artifacts by pattern', async () => { | ||||||
| @ -144,9 +133,9 @@ describe('download', () => { | |||||||
|       {id: 456, name: 'prod-artifact', size: 2048, digest: 'def456'} |       {id: 456, name: 'prod-artifact', size: 2048, digest: 'def456'} | ||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|       jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifacts: mockArtifacts }) |       .spyOn(artifact, 'listArtifacts') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifacts: mockArtifacts})) | ||||||
| 
 | 
 | ||||||
|     mockInputs({ |     mockInputs({ | ||||||
|       [Inputs.Name]: '', |       [Inputs.Name]: '', | ||||||
| @ -172,9 +161,9 @@ describe('download', () => { | |||||||
|       [Inputs.RunID]: '789' |       [Inputs.RunID]: '789' | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|       jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifacts: [] }) |       .spyOn(artifact, 'listArtifacts') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifacts: []})) | ||||||
| 
 | 
 | ||||||
|     await run() |     await run() | ||||||
| 
 | 
 | ||||||
| @ -209,13 +198,13 @@ describe('download', () => { | |||||||
|       digest: 'abc123' |       digest: 'abc123' | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|       jest.spyOn(artifact, 'getArtifact').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ artifact: mockArtifact }) |       .spyOn(artifact, 'getArtifact') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({artifact: mockArtifact})) | ||||||
| 
 | 
 | ||||||
|       jest.spyOn(artifact, 'downloadArtifact').mockImplementation(() =>  |     jest | ||||||
|         Promise.resolve({ digestMismatch: true }) |       .spyOn(artifact, 'downloadArtifact') | ||||||
|       ) |       .mockImplementation(() => Promise.resolve({digestMismatch: true})) | ||||||
| 
 | 
 | ||||||
|     await run() |     await run() | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user