Commit f119f587 authored by Daniel Kennedy's avatar Daniel Kennedy
Browse files

Upgrade the module to ESM and bump dependencies

parent 47309c99
Loading
Loading
Loading
Loading
−16

File deleted.

+1
Changes for .gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
node_modules/
lib/
__tests__/_temp/
.DS_Store
 No newline at end of file
+96 −51
Changes for __tests__/merge.test.ts: 96 added lines, 51 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import artifact from '@actions/artifact'
import {run} from '../src/merge/merge-artifacts'
import {Inputs} from '../src/merge/constants'
import * as search from '../src/shared/search'
import {jest, describe, test, expect, beforeEach} from '@jest/globals'

// Mock @actions/github before importing modules that use it
jest.unstable_mockModule('@actions/github', () => ({
  context: {
    repo: {
      owner: 'actions',
      repo: 'toolkit'
    },
    runId: 123,
    serverUrl: 'https://github.com'
  },
  getOctokit: jest.fn()
}))

// Mock @actions/core
jest.unstable_mockModule('@actions/core', () => ({
  getInput: jest.fn(),
  getBooleanInput: jest.fn(),
  setOutput: jest.fn(),
  setFailed: jest.fn(),
  setSecret: jest.fn(),
  info: jest.fn(),
  warning: jest.fn(),
  debug: jest.fn(),
  error: jest.fn(),
  notice: jest.fn(),
  startGroup: jest.fn(),
  endGroup: jest.fn(),
  isDebug: jest.fn(() => false),
  getState: jest.fn(),
  saveState: jest.fn(),
  exportVariable: jest.fn(),
  addPath: jest.fn(),
  group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
  toPlatformPath: jest.fn((p: string) => p),
  toWin32Path: jest.fn((p: string) => p),
  toPosixPath: jest.fn((p: string) => p)
}))

// Mock fs/promises
const actualFsPromises = await import('fs/promises')
jest.unstable_mockModule('fs/promises', () => ({
  ...actualFsPromises,
  mkdtemp:
    jest.fn<() => Promise<string>>().mockResolvedValue('/tmp/merge-artifact'),
  rm: jest.fn<() => Promise<void>>().mockResolvedValue(undefined)
}))

// Mock shared search module
const mockFindFilesToUpload = jest.fn<
  () => Promise<{filesToUpload: string[]; rootDirectory: string}>
>()
jest.unstable_mockModule('../src/shared/search.js', () => ({
  findFilesToUpload: mockFindFilesToUpload
}))

// Dynamic imports after mocking
const core = await import('@actions/core')
const artifact = await import('@actions/artifact')
const {run} = await import('../src/merge/merge-artifacts.js')
const {Inputs} = await import('../src/merge/constants.js')

const fixtures = {
  artifactName: 'my-merged-artifact',
@@ -34,27 +91,10 @@ const fixtures = {
  ]
}

jest.mock('@actions/github', () => ({
  context: {
    repo: {
      owner: 'actions',
      repo: 'toolkit'
    },
    runId: 123,
    serverUrl: 'https://github.com'
  }
}))

jest.mock('@actions/core')

jest.mock('fs/promises', () => ({
  mkdtemp: jest.fn().mockResolvedValue('/tmp/merge-artifact'),
  rm: jest.fn().mockResolvedValue(undefined)
}))

/* eslint-disable no-unused-vars */
const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
  const inputs = {
const mockInputs = (
  overrides?: Partial<{[K in (typeof Inputs)[keyof typeof Inputs]]?: any}>
) => {
  const inputs: Record<string, any> = {
    [Inputs.Name]: 'my-merged-artifact',
    [Inputs.Pattern]: '*',
    [Inputs.SeparateDirectories]: false,
@@ -64,10 +104,14 @@ const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
    ...overrides
  }

  ;(core.getInput as jest.Mock).mockImplementation((name: string) => {
  ;(core.getInput as jest.Mock<typeof core.getInput>).mockImplementation(
    (name: string) => {
      return inputs[name]
  })
  ;(core.getBooleanInput as jest.Mock).mockImplementation((name: string) => {
    }
  )
  ;(
    core.getBooleanInput as jest.Mock<typeof core.getBooleanInput>
  ).mockImplementation((name: string) => {
    return inputs[name]
  })

@@ -77,44 +121,45 @@ const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
describe('merge', () => {
  beforeEach(async () => {
    mockInputs()
    jest.clearAllMocks()

    jest
      .spyOn(artifact, 'listArtifacts')
      .spyOn(artifact.default, 'listArtifacts')
      .mockResolvedValue({artifacts: fixtures.artifacts})

    jest.spyOn(artifact, 'downloadArtifact').mockResolvedValue({
    jest.spyOn(artifact.default, 'downloadArtifact').mockResolvedValue({
      downloadPath: fixtures.tmpDirectory
    })

    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: fixtures.filesToUpload,
      rootDirectory: fixtures.tmpDirectory
    })

    jest.spyOn(artifact, 'uploadArtifact').mockResolvedValue({
    jest.spyOn(artifact.default, 'uploadArtifact').mockResolvedValue({
      size: 123,
      id: 1337
    })

    jest
      .spyOn(artifact, 'deleteArtifact')
      .mockImplementation(async artifactName => {
        const artifact = fixtures.artifacts.find(a => a.name === artifactName)
        if (!artifact) throw new Error(`Artifact ${artifactName} not found`)
        return {id: artifact.id}
      .spyOn(artifact.default, 'deleteArtifact')
      .mockImplementation(async (artifactName: string) => {
        const found = fixtures.artifacts.find(a => a.name === artifactName)
        if (!found) throw new Error(`Artifact ${artifactName} not found`)
        return {id: found.id}
      })
  })

  it('merges artifacts', async () => {
  test('merges artifacts', async () => {
    await run()

    for (const a of fixtures.artifacts) {
      expect(artifact.downloadArtifact).toHaveBeenCalledWith(a.id, {
      expect(artifact.default.downloadArtifact).toHaveBeenCalledWith(a.id, {
        path: fixtures.tmpDirectory
      })
    }

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.tmpDirectory,
@@ -122,23 +167,23 @@ describe('merge', () => {
    )
  })

  it('fails if no artifacts found', async () => {
  test('fails if no artifacts found', async () => {
    mockInputs({[Inputs.Pattern]: 'this-does-not-match'})

    expect(run()).rejects.toThrow()
    await expect(run()).rejects.toThrow()

    expect(artifact.uploadArtifact).not.toBeCalled()
    expect(artifact.downloadArtifact).not.toBeCalled()
    expect(artifact.default.uploadArtifact).not.toHaveBeenCalled()
    expect(artifact.default.downloadArtifact).not.toHaveBeenCalled()
  })

  it('supports custom compression level', async () => {
  test('supports custom compression level', async () => {
    mockInputs({
      [Inputs.CompressionLevel]: 2
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.tmpDirectory,
@@ -146,14 +191,14 @@ describe('merge', () => {
    )
  })

  it('supports custom retention days', async () => {
  test('supports custom retention days', async () => {
    mockInputs({
      [Inputs.RetentionDays]: 7
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.tmpDirectory,
@@ -161,7 +206,7 @@ describe('merge', () => {
    )
  })

  it('supports deleting artifacts after merge', async () => {
  test('supports deleting artifacts after merge', async () => {
    mockInputs({
      [Inputs.DeleteMerged]: true
    })
@@ -169,7 +214,7 @@ describe('merge', () => {
    await run()

    for (const a of fixtures.artifacts) {
      expect(artifact.deleteArtifact).toHaveBeenCalledWith(a.name)
      expect(artifact.default.deleteArtifact).toHaveBeenCalledWith(a.name)
    }
  })
})
+45 −53
Changes for __tests__/search.test.ts: 45 added lines, 53 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import {jest, describe, test, expect, beforeAll} from '@jest/globals'
import * as path from 'path'
import * as io from '@actions/io'
import {promises as fs} from 'fs'
import {findFilesToUpload} from '../src/shared/search'
import {fileURLToPath} from 'url'

// Mock @actions/core to suppress output during tests
jest.unstable_mockModule('@actions/core', () => ({
  getInput: jest.fn(),
  getBooleanInput: jest.fn(),
  setOutput: jest.fn(),
  setFailed: jest.fn(),
  setSecret: jest.fn(),
  info: jest.fn(),
  warning: jest.fn(),
  debug: jest.fn(),
  error: jest.fn(),
  notice: jest.fn(),
  startGroup: jest.fn(),
  endGroup: jest.fn(),
  isDebug: jest.fn(() => false),
  getState: jest.fn(),
  saveState: jest.fn(),
  exportVariable: jest.fn(),
  addPath: jest.fn(),
  group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
  toPlatformPath: jest.fn((p: string) => p),
  toWin32Path: jest.fn((p: string) => p),
  toPosixPath: jest.fn((p: string) => p)
}))

const {findFilesToUpload} = await import('../src/shared/search.js')

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const root = path.join(__dirname, '_temp', 'search')
const searchItem1Path = path.join(
@@ -77,11 +106,8 @@ const fileInHiddenFolderInFolderA = path.join(

describe('Search', () => {
  beforeAll(async () => {
    // mock all output so that there is less noise when running tests
    // mock console.log to reduce noise
    jest.spyOn(console, 'log').mockImplementation(() => {})
    jest.spyOn(core, 'debug').mockImplementation(() => {})
    jest.spyOn(core, 'info').mockImplementation(() => {})
    jest.spyOn(core, 'warning').mockImplementation(() => {})

    // clear temp directory
    await io.rmRF(root)
@@ -136,43 +162,9 @@ describe('Search', () => {
    await fs.writeFile(hiddenFile, 'hidden file')
    await fs.writeFile(fileInHiddenFolderPath, 'file in hidden directory')
    await fs.writeFile(fileInHiddenFolderInFolderA, 'file in hidden directory')
    /*
      Directory structure of files that get created:
      root/
          .hidden-folder/
              folder-in-hidden-folder/
                  file.txt
          folder-a/
              .hidden-folder-in-folder-a/
                  file.txt
              folder-b/
                  folder-c/
                      search-item1.txt
                      extraSearch-item1.txt
                      extra-file-in-folder-c.txt
                  folder-e/
          folder-d/
              search-item2.txt
              search-item3.txt
              search-item4.txt
              extraSearch-item2.txt
          folder-f/
              extraSearch-item3.txt
          folder-g/
          folder-h/
              amazing-item.txt
              folder-i/
                  extraSearch-item4.txt
                  extraSearch-item5.txt
              folder-j/
                  folder-k/
                      lonely-file.txt
          .hidden-file.txt
          search-item5.txt
    */
  })

  it('Single file search - Absolute Path', async () => {
  test('Single file search - Absolute Path', async () => {
    const searchResult = await findFilesToUpload(extraFileInFolderCPath)
    expect(searchResult.filesToUpload.length).toEqual(1)
    expect(searchResult.filesToUpload[0]).toEqual(extraFileInFolderCPath)
@@ -181,7 +173,7 @@ describe('Search', () => {
    )
  })

  it('Single file search - Relative Path', async () => {
  test('Single file search - Relative Path', async () => {
    const relativePath = path.join(
      '__tests__',
      '_temp',
@@ -200,7 +192,7 @@ describe('Search', () => {
    )
  })

  it('Single file using wildcard', async () => {
  test('Single file using wildcard', async () => {
    const expectedRoot = path.join(root, 'folder-h')
    const searchPath = path.join(root, 'folder-h', '**/*lonely*')
    const searchResult = await findFilesToUpload(searchPath)
@@ -209,7 +201,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(expectedRoot)
  })

  it('Single file using directory', async () => {
  test('Single file using directory', async () => {
    const searchPath = path.join(root, 'folder-h', 'folder-j')
    const searchResult = await findFilesToUpload(searchPath)
    expect(searchResult.filesToUpload.length).toEqual(1)
@@ -217,7 +209,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(searchPath)
  })

  it('Directory search - Absolute Path', async () => {
  test('Directory search - Absolute Path', async () => {
    const searchPath = path.join(root, 'folder-h')
    const searchResult = await findFilesToUpload(searchPath)
    expect(searchResult.filesToUpload.length).toEqual(4)
@@ -236,7 +228,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(searchPath)
  })

  it('Directory search - Relative Path', async () => {
  test('Directory search - Relative Path', async () => {
    const searchPath = path.join('__tests__', '_temp', 'search', 'folder-h')
    const expectedRootDirectory = path.join(root, 'folder-h')
    const searchResult = await findFilesToUpload(searchPath)
@@ -256,7 +248,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(expectedRootDirectory)
  })

  it('Wildcard search - Absolute Path', async () => {
  test('Wildcard search - Absolute Path', async () => {
    const searchPath = path.join(root, '**/*[Ss]earch*')
    const searchResult = await findFilesToUpload(searchPath)
    expect(searchResult.filesToUpload.length).toEqual(10)
@@ -285,7 +277,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(root)
  })

  it('Wildcard search - Relative Path', async () => {
  test('Wildcard search - Relative Path', async () => {
    const searchPath = path.join(
      '__tests__',
      '_temp',
@@ -319,7 +311,7 @@ describe('Search', () => {
    expect(searchResult.rootDirectory).toEqual(root)
  })

  it('Multi path search - root directory', async () => {
  test('Multi path search - root directory', async () => {
    const searchPath1 = path.join(root, 'folder-a')
    const searchPath2 = path.join(root, 'folder-d')

@@ -343,7 +335,7 @@ describe('Search', () => {
    )
  })

  it('Multi path search - with exclude character', async () => {
  test('Multi path search - with exclude character', async () => {
    const searchPath1 = path.join(root, 'folder-a')
    const searchPath2 = path.join(root, 'folder-d')
    const searchPath3 = path.join(root, 'folder-a', 'folder-b', '**/extra*.txt')
@@ -363,7 +355,7 @@ describe('Search', () => {
    )
  })

  it('Multi path search - non root directory', async () => {
  test('Multi path search - non root directory', async () => {
    const searchPath1 = path.join(root, 'folder-h', 'folder-i')
    const searchPath2 = path.join(root, 'folder-h', 'folder-j', 'folder-k')
    const searchPath3 = amazingFileInFolderHPath
@@ -385,7 +377,7 @@ describe('Search', () => {
    expect(searchResult.filesToUpload.includes(lonelyFilePath)).toEqual(true)
  })

  it('Hidden files ignored by default', async () => {
  test('Hidden files ignored by default', async () => {
    const searchPath = path.join(root, '**/*')
    const searchResult = await findFilesToUpload(searchPath)

@@ -396,7 +388,7 @@ describe('Search', () => {
    )
  })

  it('Hidden files included', async () => {
  test('Hidden files included', async () => {
    const searchPath = path.join(root, '**/*')
    const searchResult = await findFilesToUpload(searchPath, true)

+97 −53
Changes for __tests__/upload.test.ts: 97 added lines, 53 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import * as github from '@actions/github'
import artifact, {ArtifactNotFoundError} from '@actions/artifact'
import {run} from '../src/upload/upload-artifact'
import {Inputs} from '../src/upload/constants'
import * as search from '../src/shared/search'
import {jest, describe, test, expect, beforeEach} from '@jest/globals'

const fixtures = {
  artifactName: 'artifact-name',
  rootDirectory: '/some/artifact/path',
  filesToUpload: [
    '/some/artifact/path/file1.txt',
    '/some/artifact/path/file2.txt'
  ]
}

jest.mock('@actions/github', () => ({
// Mock @actions/github before importing modules that use it
jest.unstable_mockModule('@actions/github', () => ({
  context: {
    repo: {
      owner: 'actions',
@@ -22,14 +9,64 @@ jest.mock('@actions/github', () => ({
    },
    runId: 123,
    serverUrl: 'https://github.com'
  }
  },
  getOctokit: jest.fn()
}))

// Mock @actions/core
jest.unstable_mockModule('@actions/core', () => ({
  getInput: jest.fn(),
  getBooleanInput: jest.fn(),
  setOutput: jest.fn(),
  setFailed: jest.fn(),
  setSecret: jest.fn(),
  info: jest.fn(),
  warning: jest.fn(),
  debug: jest.fn(),
  error: jest.fn(),
  notice: jest.fn(),
  startGroup: jest.fn(),
  endGroup: jest.fn(),
  isDebug: jest.fn(() => false),
  getState: jest.fn(),
  saveState: jest.fn(),
  exportVariable: jest.fn(),
  addPath: jest.fn(),
  group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
  toPlatformPath: jest.fn((p: string) => p),
  toWin32Path: jest.fn((p: string) => p),
  toPosixPath: jest.fn((p: string) => p)
}))

// Mock shared search module
const mockFindFilesToUpload = jest.fn<
  () => Promise<{filesToUpload: string[]; rootDirectory: string}>
>()
jest.unstable_mockModule('../src/shared/search.js', () => ({
  findFilesToUpload: mockFindFilesToUpload
}))

jest.mock('@actions/core')
// Dynamic imports after mocking
const core = await import('@actions/core')
const github = await import('@actions/github')
const artifact = await import('@actions/artifact')
const {run} = await import('../src/upload/upload-artifact.js')
const {Inputs} = await import('../src/upload/constants.js')
const {ArtifactNotFoundError} = artifact

/* eslint-disable no-unused-vars */
const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
  const inputs = {
const fixtures = {
  artifactName: 'artifact-name',
  rootDirectory: '/some/artifact/path',
  filesToUpload: [
    '/some/artifact/path/file1.txt',
    '/some/artifact/path/file2.txt'
  ]
}

const mockInputs = (
  overrides?: Partial<{[K in (typeof Inputs)[keyof typeof Inputs]]?: any}>
) => {
  const inputs: Record<string, any> = {
    [Inputs.Name]: 'artifact-name',
    [Inputs.Path]: '/some/artifact/path',
    [Inputs.IfNoFilesFound]: 'warn',
@@ -39,10 +76,14 @@ const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
    ...overrides
  }

  ;(core.getInput as jest.Mock).mockImplementation((name: string) => {
  ;(core.getInput as jest.Mock<typeof core.getInput>).mockImplementation(
    (name: string) => {
      return inputs[name]
  })
  ;(core.getBooleanInput as jest.Mock).mockImplementation((name: string) => {
    }
  )
  ;(
    core.getBooleanInput as jest.Mock<typeof core.getBooleanInput>
  ).mockImplementation((name: string) => {
    return inputs[name]
  })

@@ -52,28 +93,29 @@ const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
describe('upload', () => {
  beforeEach(async () => {
    mockInputs()
    jest.clearAllMocks()

    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: fixtures.filesToUpload,
      rootDirectory: fixtures.rootDirectory
    })

    jest.spyOn(artifact, 'uploadArtifact').mockResolvedValue({
    jest.spyOn(artifact.default, 'uploadArtifact').mockResolvedValue({
      size: 123,
      id: 1337,
      digest: 'facefeed'
    })
  })

  it('uploads a single file', async () => {
    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
  test('uploads a single file', async () => {
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: [fixtures.filesToUpload[0]],
      rootDirectory: fixtures.rootDirectory
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      [fixtures.filesToUpload[0]],
      fixtures.rootDirectory,
@@ -81,10 +123,10 @@ describe('upload', () => {
    )
  })

  it('uploads multiple files', async () => {
  test('uploads multiple files', async () => {
    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.rootDirectory,
@@ -92,27 +134,25 @@ describe('upload', () => {
    )
  })

  it('sets outputs', async () => {
  test('sets outputs', async () => {
    await run()

    expect(core.setOutput).toHaveBeenCalledWith('artifact-id', 1337)
    expect(core.setOutput).toHaveBeenCalledWith('artifact-digest', 'facefeed')
    expect(core.setOutput).toHaveBeenCalledWith(
      'artifact-url',
      `${github.context.serverUrl}/${github.context.repo.owner}/${
        github.context.repo.repo
      }/actions/runs/${github.context.runId}/artifacts/${1337}`
      `${github.context.serverUrl}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/artifacts/${1337}`
    )
  })

  it('supports custom compression level', async () => {
  test('supports custom compression level', async () => {
    mockInputs({
      [Inputs.CompressionLevel]: 2
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.rootDirectory,
@@ -120,14 +160,14 @@ describe('upload', () => {
    )
  })

  it('supports custom retention days', async () => {
  test('supports custom retention days', async () => {
    mockInputs({
      [Inputs.RetentionDays]: 7
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.rootDirectory,
@@ -135,12 +175,12 @@ describe('upload', () => {
    )
  })

  it('supports warn if-no-files-found', async () => {
  test('supports warn if-no-files-found', async () => {
    mockInputs({
      [Inputs.IfNoFilesFound]: 'warn'
    })

    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: [],
      rootDirectory: fixtures.rootDirectory
    })
@@ -152,12 +192,12 @@ describe('upload', () => {
    )
  })

  it('supports error if-no-files-found', async () => {
  test('supports error if-no-files-found', async () => {
    mockInputs({
      [Inputs.IfNoFilesFound]: 'error'
    })

    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: [],
      rootDirectory: fixtures.rootDirectory
    })
@@ -169,12 +209,12 @@ describe('upload', () => {
    )
  })

  it('supports ignore if-no-files-found', async () => {
  test('supports ignore if-no-files-found', async () => {
    mockInputs({
      [Inputs.IfNoFilesFound]: 'ignore'
    })

    jest.spyOn(search, 'findFilesToUpload').mockResolvedValue({
    mockFindFilesToUpload.mockResolvedValue({
      filesToUpload: [],
      rootDirectory: fixtures.rootDirectory
    })
@@ -186,46 +226,50 @@ describe('upload', () => {
    )
  })

  it('supports overwrite', async () => {
  test('supports overwrite', async () => {
    mockInputs({
      [Inputs.Overwrite]: true
    })

    jest.spyOn(artifact, 'deleteArtifact').mockResolvedValue({
    jest.spyOn(artifact.default, 'deleteArtifact').mockResolvedValue({
      id: 1337
    })

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.rootDirectory,
      {compressionLevel: 6}
    )

    expect(artifact.deleteArtifact).toHaveBeenCalledWith(fixtures.artifactName)
    expect(artifact.default.deleteArtifact).toHaveBeenCalledWith(
      fixtures.artifactName
    )
  })

  it('supports overwrite and continues if not found', async () => {
  test('supports overwrite and continues if not found', async () => {
    mockInputs({
      [Inputs.Overwrite]: true
    })

    jest
      .spyOn(artifact, 'deleteArtifact')
      .spyOn(artifact.default, 'deleteArtifact')
      .mockRejectedValue(new ArtifactNotFoundError('not found'))

    await run()

    expect(artifact.uploadArtifact).toHaveBeenCalledWith(
    expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
      fixtures.artifactName,
      fixtures.filesToUpload,
      fixtures.rootDirectory,
      {compressionLevel: 6}
    )

    expect(artifact.deleteArtifact).toHaveBeenCalledWith(fixtures.artifactName)
    expect(artifact.default.deleteArtifact).toHaveBeenCalledWith(
      fixtures.artifactName
    )
    expect(core.debug).toHaveBeenCalledWith(
      `Skipping deletion of '${fixtures.artifactName}', it does not exist`
    )
Loading