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
5 changes: 3 additions & 2 deletions .github/linters/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export default [
'**/node_modules/',
'**/dist/',
'**/coverage/',
'**/__mocks__/',
'**/__fixtures__/',
'**/*.json',
'.github/linters/eslint.config.mjs'
'.github/linters/eslint.config.mjs',
'jest.config.js'
]
},
...compat.extends(
Expand Down
6 changes: 5 additions & 1 deletion .github/linters/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"compilerOptions": {
"noEmit": true
},
"include": ["../../__tests__/**/*", "../../src/**/*"],
"include": [
"../../__tests__/**/*",
"../../src/**/*",
"../../__fixtures__/**/*"
],
"exclude": ["../../dist", "../../node_modules", "../../coverage", "*.json"]
}
11 changes: 11 additions & 0 deletions __fixtures__/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type * as core from '@actions/core'
import { jest } from '@jest/globals'

export const debug = jest.fn<typeof core.debug>()
export const info = jest.fn<typeof core.info>()
export const error = jest.fn<typeof core.error>()
export const warning = jest.fn<typeof core.warning>()
export const getInput = jest.fn<typeof core.getInput>()
export const setOutput = jest.fn<typeof core.setOutput>()
export const setFailed = jest.fn<typeof core.setFailed>()
export const exportVariable = jest.fn<typeof core.exportVariable>()
10 changes: 0 additions & 10 deletions __mocks__/@actions/core.js

This file was deleted.

24 changes: 13 additions & 11 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import * as core from '@actions/core'
import type { jest } from '@jest/globals'
import type * as core from '@actions/core'
import * as coreMock from '../__fixtures__/core.js'

export interface MockSpies {
errorMock: jest.SpiedFunction<typeof core.error>
getInputMock: jest.SpiedFunction<typeof core.getInput>
setFailedMock: jest.SpiedFunction<typeof core.setFailed>
setOutputMock: jest.SpiedFunction<typeof core.setOutput>
exportVariableMock: jest.SpiedFunction<typeof core.exportVariable>
errorMock: jest.Mock<typeof core.error>
getInputMock: jest.Mock<typeof core.getInput>
setFailedMock: jest.Mock<typeof core.setFailed>
setOutputMock: jest.Mock<typeof core.setOutput>
exportVariableMock: jest.Mock<typeof core.exportVariable>
}

export function setupMocks(): MockSpies {
return {
errorMock: jest.spyOn(core, 'error').mockImplementation(),
getInputMock: jest.spyOn(core, 'getInput').mockImplementation(),
setFailedMock: jest.spyOn(core, 'setFailed').mockImplementation(),
setOutputMock: jest.spyOn(core, 'setOutput').mockImplementation(),
exportVariableMock: jest.spyOn(core, 'exportVariable').mockImplementation()
errorMock: coreMock.error,
getInputMock: coreMock.getInput,
setFailedMock: coreMock.setFailed,
setOutputMock: coreMock.setOutput,
exportVariableMock: coreMock.exportVariable
}
}
18 changes: 11 additions & 7 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
* Unit tests for the action's entrypoint, src/index.ts
*/

import * as main from '../src/main'
import { jest } from '@jest/globals'
import * as core from '../__fixtures__/core.js'

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()
jest.unstable_mockModule('@actions/core', () => core)

const mainMock = {
run: jest.fn()
}
jest.unstable_mockModule('../src/main.js', () => mainMock)

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.js')

expect(runMock).toHaveBeenCalled()
expect(mainMock.run).toHaveBeenCalled()
})
})
82 changes: 30 additions & 52 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

import * as main from '../src/main'
import { type MockSpies, setupMocks } from './helpers'
import { jest } from '@jest/globals'
import * as core from '../__fixtures__/core.js'
import { type MockSpies, setupMocks } from './helpers.js'

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
jest.unstable_mockModule('@actions/core', () => core)

const { run } = await import('../src/main.js')

let mocks: MockSpies

Expand All @@ -30,8 +32,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -51,8 +52,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -72,8 +72,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -93,8 +92,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -114,8 +112,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setOutputMock).not.toHaveBeenCalled()
Expand All @@ -138,8 +135,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -164,8 +160,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -191,8 +186,7 @@ describe('correct input values, successful cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.setFailedMock).not.toHaveBeenCalled()
Expand All @@ -218,8 +212,7 @@ describe('correct input values, edge cases', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand Down Expand Up @@ -248,8 +241,7 @@ describe('allowed empty map', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -269,8 +261,7 @@ describe('allowed empty map', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -294,8 +285,7 @@ describe('allowed empty map', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -316,8 +306,7 @@ describe('allowed empty map', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -343,8 +332,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -363,8 +351,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -384,8 +371,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -405,8 +391,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -429,8 +414,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -453,8 +437,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -478,8 +461,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -502,8 +484,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -526,8 +507,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -550,8 +530,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand All @@ -574,8 +553,7 @@ describe('input validation', () => {
}
mocks.getInputMock.mockImplementation(name => input[name])

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

expect(mocks.errorMock).not.toHaveBeenCalled()
expect(mocks.exportVariableMock).not.toHaveBeenCalled()
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ outputs:

runs:
using: node20
main: dist/index.js
main: dist/index.cjs
2 changes: 1 addition & 1 deletion dist/index.js → dist/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map → dist/index.cjs.map

Large diffs are not rendered by default.

Loading