Skip to content

Commit

Permalink
add vitest and remove jest
Browse files Browse the repository at this point in the history
  • Loading branch information
scandar committed Nov 11, 2024
1 parent 5fa5d49 commit d8c5978
Show file tree
Hide file tree
Showing 5 changed files with 2,400 additions and 4,462 deletions.
8 changes: 4 additions & 4 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Unit tests for the action's entrypoint, src/index.ts
*/

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

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

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()
})
Expand Down
25 changes: 13 additions & 12 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@

import * as core from '@actions/core'
import * as main from '../src/main'
import { vi, MockInstance, describe, beforeEach, it, expect } 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: MockInstance<typeof core.debug>
let errorMock: MockInstance<typeof core.error>
let getInputMock: MockInstance<typeof core.getInput>
let setFailedMock: MockInstance<typeof core.setFailed>
let setOutputMock: MockInstance<typeof core.setOutput>

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 () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Unit tests for src/wait.ts
*/

import { describe, expect, it } from 'vitest'
import { wait } from '../src/wait'
import { expect } from '@jest/globals'

describe('wait.ts', () => {
it('throws an invalid number', async () => {
Expand Down
Loading

0 comments on commit d8c5978

Please sign in to comment.