Convert to use src and dist paths

This commit is contained in:
Nick Alteen
2023-09-15 10:56:32 -04:00
parent 7c2c305cfe
commit a7e777abad
16 changed files with 27876 additions and 152 deletions

18
__tests__/index.test.js Normal file
View File

@ -0,0 +1,18 @@
/**
* Unit tests for the action's entrypoint, src/index.js
*/
const { run } = require('../src/main')
// Mock the action's entrypoint
jest.mock('../src/main', () => ({
run: jest.fn()
}))
describe('index', () => {
it('calls run when imported', async () => {
require('../src/index')
expect(run).toHaveBeenCalled()
})
})

90
__tests__/main.test.js Normal file
View File

@ -0,0 +1,90 @@
/**
* Unit tests for the action's main functionality, src/main.js
*/
const core = require('@actions/core')
const github = require('@actions/github')
const main = require('../src/main')
// Mock the GitHub Actions core library
const infoMock = jest.spyOn(core, 'info').mockImplementation()
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()
})
it('sets the time output', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
return 'World'
default:
return ''
}
})
// Mock the action's payload
github.context.payload = {}
await main.run()
expect(runMock).toHaveReturned()
expect(setOutputMock).toHaveBeenCalledWith('time', expect.any(String))
})
it('logs the event payload', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
return 'World'
default:
return ''
}
})
// Mock the action's payload
github.context.payload = {
actor: 'mona'
}
await main.run()
expect(runMock).toHaveReturned()
expect(infoMock).toHaveBeenCalledWith(
`The event payload: ${JSON.stringify(github.context.payload, null, 2)}`
)
})
it('sets a failed status', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
throw new Error('Something went wrong...')
default:
return ''
}
})
// Mock the action's payload
github.context.payload = {
actor: 'mona'
}
await main.run()
expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith('Something went wrong...')
})
})