Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ permissions:
contents: read

jobs:
jest:
name: jest
vitest:
name: vitest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Expand Down
9 changes: 3 additions & 6 deletions __tests__/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { getTestStdout, mockActionsCoreLogging } from './helpers'
import { parseTestEvents } from '../src/events'
import { describe, expect, it } from 'vitest'
import { getTestStdout } from './helpers.js'
import { parseTestEvents } from '../src/events.js'

describe('events', () => {
beforeEach(() => {
mockActionsCoreLogging()
})

it('correctly parses test2json output', async () => {
const stdout = await getTestStdout()

Expand Down
25 changes: 6 additions & 19 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as fs from 'fs/promises'
import * as core from '@actions/core'
import path from 'path'
import { fileURLToPath } from 'url'
import { vi, type MockInstance } from 'vitest'

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

export const testFixturesDirectory = path.join(__dirname, 'fixtures')
export const testOutputDirectory = path.join(__dirname, 'output')
Expand Down Expand Up @@ -49,9 +53,9 @@ export const createFakeGoModule = async () => {
)
}

export const mockProcessExit = (): jest.SpyInstance => {
export const mockProcessExit = (): MockInstance => {
// @ts-ignore:next-line
return jest.spyOn(process, 'exit').mockImplementationOnce(() => {})
return vi.spyOn(process, 'exit').mockImplementationOnce(() => {})
}

export const getTestStdout = async (): Promise<string> => {
Expand All @@ -61,20 +65,3 @@ export const getTestStdout = async (): Promise<string> => {
return buf.toString()
}

export const mockActionsCoreLogging = (silent = true) => {
type LogFuncs = 'debug' | 'error' | 'warning' | 'notice' | 'info'
const logMethods: LogFuncs[] = ['debug', 'error', 'warning', 'notice', 'info']
logMethods.forEach(method => {
jest
.spyOn(core, method)
.mockImplementation(
(msg: string | Error, props?: core.AnnotationProperties) => {
if (silent) return
console.log(
`[mock: core.${method}(${props ? JSON.stringify(props) : ''})]:`,
msg
)
}
)
})
}
11 changes: 6 additions & 5 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { beforeEach, describe, expect, it, vi, type MockedFunction } from 'vitest'
import * as core from '@actions/core'
import { OmitOption, getInputs } from '../src/inputs'
import { OmitOption, getInputs } from '../src/inputs.js'

jest.mock('@actions/core')
vi.mock('@actions/core')

const mockGetInput = core.getInput as jest.MockedFunction<typeof core.getInput>
const mockGetBooleanInput = core.getBooleanInput as jest.MockedFunction<
const mockGetInput = core.getInput as MockedFunction<typeof core.getInput>
const mockGetBooleanInput = core.getBooleanInput as MockedFunction<
typeof core.getBooleanInput
>

Expand All @@ -18,7 +19,7 @@ const mockInputs = (inputs: Record<string, string>) => {

describe('renderer', () => {
beforeEach(() => {
jest.resetAllMocks()
vi.resetAllMocks()
})

it('uses default values', () => {
Expand Down
19 changes: 12 additions & 7 deletions __tests__/renderer.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from 'vitest'
import * as fs from 'fs/promises'
import * as cheerio from 'cheerio'

import {
getTestStdout,
mockActionsCoreLogging,
createFakeGoModule,
createSummaryFile,
removeSummaryFile,
testSummaryFilePath,
} from './helpers'
import { parseTestEvents } from '../src/events'
import Renderer from '../src/renderer'
import { SummaryTableCell } from '@actions/core/lib/summary'
import { OmitOption } from '../src/inputs'
} from './helpers.js'
import { parseTestEvents } from '../src/events.js'
import Renderer, { type SummaryTableCell } from '../src/renderer.js'
import { OmitOption } from '../src/inputs.js'

const loadSummaryHTML = async (): Promise<cheerio.CheerioAPI> => {
const file = await fs.readFile(testSummaryFilePath, { encoding: 'utf8' })
Expand All @@ -37,7 +43,6 @@ describe('renderer', () => {
})

beforeEach(async () => {
mockActionsCoreLogging()
await createSummaryFile()
})

Expand Down
11 changes: 4 additions & 7 deletions __tests__/results.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getTestStdout, mockActionsCoreLogging } from './helpers'
import { TestEvent, parseTestEvents } from '../src/events'
import PackageResult from '../src/results'
import { describe, expect, it } from 'vitest'
import { getTestStdout } from './helpers.js'
import { TestEvent, parseTestEvents } from '../src/events.js'
import PackageResult from '../src/results.js'

const getPackageLevelEvent = (testEvents: TestEvent[]): TestEvent => {
return testEvents.filter(
Expand All @@ -12,10 +13,6 @@ const getPackageLevelEvent = (testEvents: TestEvent[]): TestEvent => {
}

describe('results', () => {
beforeEach(() => {
mockActionsCoreLogging()
})

it('converts events to results', async () => {
const stdout = await getTestStdout()
const testEvents = parseTestEvents(stdout)
Expand Down
31 changes: 14 additions & 17 deletions __tests__/runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import * as fs from 'fs/promises'
import path from 'path'
import * as actionsExec from '@actions/exec'
Expand All @@ -9,18 +10,16 @@ import {
testFixturesDirectory,
mockProcessExit,
createFakeGoModule,
mockActionsCoreLogging,
} from './helpers'
import Runner from '../src/runner'
import Renderer from '../src/renderer'
} from './helpers.js'
import Runner from '../src/runner.js'
import Renderer from '../src/renderer.js'

describe('runner', () => {
beforeAll(async () => {
await createFakeGoModule()
})

beforeEach(() => {
mockActionsCoreLogging()
setupActionsInputs()
delete process.env['INPUT_FROMJSONFILE']
delete process.env['INPUT_FROMJSONFILES']
Expand Down Expand Up @@ -48,13 +47,11 @@ describe('runner', () => {
it('invokes exec with correct arguments', async () => {
const spyExit = mockProcessExit()

jest
.spyOn(Renderer.prototype, 'writeSummary')
.mockImplementationOnce(async () => {})
vi.spyOn(Renderer.prototype, 'writeSummary').mockImplementationOnce(
async () => {}
)

const spy = jest
.spyOn(actionsExec, 'exec')
.mockImplementationOnce(async () => 0)
const spy = vi.mocked(actionsExec.exec).mockImplementationOnce(async () => 0)

const runner = new Runner()
await runner.run()
Expand All @@ -74,11 +71,11 @@ describe('runner', () => {
it('exits the process with non-zero exit code on failure', async () => {
const spyExit = mockProcessExit()

jest
.spyOn(Renderer.prototype, 'writeSummary')
.mockImplementationOnce(async () => {})
vi.spyOn(Renderer.prototype, 'writeSummary').mockImplementationOnce(
async () => {}
)

jest.spyOn(actionsExec, 'exec').mockImplementationOnce(async () => 2)
vi.mocked(actionsExec.exec).mockImplementationOnce(async () => 2)

const runner = new Runner()
await runner.run()
Expand All @@ -88,7 +85,7 @@ describe('runner', () => {

it('reads from a single JSON file via fromJSONFile', async () => {
const spyExit = mockProcessExit()
const spyWrite = jest
const spyWrite = vi
.spyOn(Renderer.prototype, 'writeSummary')
.mockImplementationOnce(async () => {})

Expand All @@ -106,7 +103,7 @@ describe('runner', () => {

it('reads and combines multiple JSON files via fromJSONFiles', async () => {
const spyExit = mockProcessExit()
const spyWrite = jest
const spyWrite = vi
.spyOn(Renderer.prototype, 'writeSummary')
.mockImplementationOnce(async () => {})

Expand Down
21 changes: 21 additions & 0 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { vi } from 'vitest'

vi.mock('@actions/core', async importOriginal => {
const actual = await importOriginal<typeof import('@actions/core')>()
return {
...actual,
debug: vi.fn(),
error: vi.fn(),
warning: vi.fn(),
notice: vi.fn(),
info: vi.fn(),
}
})

vi.mock('@actions/exec', async importOriginal => {
const actual = await importOriginal<typeof import('@actions/exec')>()
return {
...actual,
exec: vi.fn(actual.exec),
}
})
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
11 changes: 0 additions & 11 deletions jest.config.ts

This file was deleted.

Loading