Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio authored Dec 23, 2024
1 parent f35baeb commit d549eb6
Show file tree
Hide file tree
Showing 14 changed files with 44,389 additions and 21,678 deletions.
9 changes: 4 additions & 5 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
*/

import * as main from '../src/main'
import { describe, it, expect, vi } from 'vitest'

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()
const runMock = vi.spyOn(main, 'run').mockImplementation()

describe('index', () => {
it('calls run when imported', () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')

it('calls run when imported', async () => {
await import('../src/index')
expect(runMock).toHaveBeenCalled()
})
})
73 changes: 22 additions & 51 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,43 @@

import * as core from '@actions/core'
import * as main from '../src/main'
import { describe, it, beforeEach, expect, vi } from 'vitest'

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
const runMock = vi.spyOn(main, 'run')

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/

// Mock the GitHub Actions core library
let debugMock: jest.SpiedFunction<typeof core.debug>
let errorMock: jest.SpiedFunction<typeof core.error>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>
let debugMock: ReturnType<typeof vi.spyOn>
let errorMock: ReturnType<typeof vi.spyOn>
let getInputMock: ReturnType<typeof vi.spyOn>
let setFailedMock: ReturnType<typeof vi.spyOn>
let setOutputMock: ReturnType<typeof vi.spyOn>

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()
vi.clearAllMocks()

debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
debugMock = vi.spyOn(core, 'debug').mockImplementation()
errorMock = vi.spyOn(core, 'error').mockImplementation()
getInputMock = vi.spyOn(core, 'getInput').mockImplementation()
setFailedMock = vi.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = vi.spyOn(core, 'setOutput').mockImplementation()
})

it('sets the time output', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return '500'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
expect(debugMock).toHaveBeenNthCalledWith(
2,
expect.stringMatching(timeRegex)
)
expect(debugMock).toHaveBeenNthCalledWith(
3,
expect.stringMatching(timeRegex)
)
expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'time',
expect.stringMatching(timeRegex)
)
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
it('sets a failed status for unsupported platform', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
case 'action':
return 'test-action'
case 'project':
return 'test-project'
case 'pipelab-version':
return '1.0.0'
default:
return ''
}
Expand All @@ -79,11 +53,8 @@ describe('action', () => {
await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'milliseconds not a number'
)
// Verify that the core.setFailed function was called correctly
expect(setFailedMock).toHaveBeenCalledWith('You are using an unsupported platform')
expect(errorMock).not.toHaveBeenCalled()
})
})
25 changes: 0 additions & 25 deletions __tests__/wait.test.ts

This file was deleted.

Loading

0 comments on commit d549eb6

Please sign in to comment.