github-pages-deploy-action/__tests__/main.test.ts
Axel Hecht 291c5c792e
Hyphenate inputs and outputs, add step output, fix #558 (#559)
* Hyphenate inputs and outputs, add step output, fix #558

I've also tried to make the clean docs a bit clearer, and consistent
about clean being on my default. Still not totally happy with the intro
of the docs there, though.

* Add testing of step outputs to build integration tests
2021-01-05 10:39:10 -05:00

93 lines
2.2 KiB
TypeScript

/* eslint-disable import/first */
// Initial env variable setup for tests.
process.env['INPUT_FOLDER'] = 'build'
process.env['GITHUB_SHA'] = '123'
process.env['INPUT_DEBUG'] = 'debug'
import '../src/main'
import {action, TestFlag} from '../src/constants'
import run from '../src/lib'
import {execute} from '../src/execute'
import {rmRF} from '@actions/io'
import {setFailed, exportVariable} from '@actions/core'
const originalAction = JSON.stringify(action)
jest.mock('../src/execute', () => ({
execute: jest.fn()
}))
jest.mock('@actions/io', () => ({
rmRF: jest.fn()
}))
jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
setOutput: jest.fn(),
exportVariable: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
describe('main', () => {
afterEach(() => {
Object.assign(action, JSON.parse(originalAction))
})
it('should run through the commands', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.NONE,
debug: true
})
await run(action)
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should run through the commands and succeed', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should throw if an error is encountered', async () => {
Object.assign(action, {
folder: 'assets',
branch: 'branch',
token: null,
ssh: null,
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(0)
expect(setFailed).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
})