2020-01-20 05:16:28 +08:00
|
|
|
// Initial env variable setup for tests.
|
2020-03-05 21:19:45 +08:00
|
|
|
process.env['INPUT_FOLDER'] = 'build'
|
|
|
|
process.env['GITHUB_SHA'] = '123'
|
|
|
|
process.env['INPUT_DEBUG'] = 'debug'
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
import '../src/main'
|
|
|
|
import {action} from '../src/constants'
|
|
|
|
import run from '../src/lib'
|
|
|
|
import {execute} from '../src/execute'
|
2020-04-12 01:57:56 +08:00
|
|
|
import {rmRF} from '@actions/io'
|
2020-05-15 05:24:32 +08:00
|
|
|
import {setFailed, exportVariable} from '@actions/core'
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
const originalAction = JSON.stringify(action)
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
jest.mock('../src/execute', () => ({
|
2020-01-20 05:16:28 +08:00
|
|
|
execute: jest.fn()
|
2020-03-05 21:19:45 +08:00
|
|
|
}))
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-04-12 01:57:56 +08:00
|
|
|
jest.mock('@actions/io', () => ({
|
|
|
|
rmRF: jest.fn()
|
|
|
|
}))
|
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
jest.mock('@actions/core', () => ({
|
2020-01-20 05:16:28 +08:00
|
|
|
setFailed: jest.fn(),
|
2020-03-02 20:52:38 +08:00
|
|
|
getInput: jest.fn(),
|
2020-03-28 22:35:26 +08:00
|
|
|
exportVariable: jest.fn(),
|
|
|
|
isDebug: jest.fn(),
|
|
|
|
info: jest.fn()
|
2020-03-05 21:19:45 +08:00
|
|
|
}))
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
describe('main', () => {
|
2020-01-20 05:16:28 +08:00
|
|
|
afterEach(() => {
|
2020-03-05 21:19:45 +08:00
|
|
|
Object.assign(action, JSON.parse(originalAction))
|
|
|
|
})
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
it('should run through the commands', async () => {
|
2020-01-20 05:16:28 +08:00
|
|
|
Object.assign(action, {
|
2020-03-05 21:19:45 +08:00
|
|
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
|
|
|
folder: 'build',
|
|
|
|
branch: 'branch',
|
|
|
|
gitHubToken: '123',
|
2020-01-20 05:16:28 +08:00
|
|
|
pusher: {
|
2020-03-05 21:19:45 +08:00
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
2020-01-20 05:16:28 +08:00
|
|
|
},
|
2020-03-02 20:52:38 +08:00
|
|
|
isTest: false,
|
|
|
|
debug: true
|
2020-03-05 21:19:45 +08:00
|
|
|
})
|
|
|
|
await run(action)
|
2020-04-12 01:57:56 +08:00
|
|
|
expect(execute).toBeCalledTimes(18)
|
|
|
|
expect(rmRF).toBeCalledTimes(1)
|
2020-05-15 05:24:32 +08:00
|
|
|
expect(exportVariable).toBeCalledTimes(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should run through the commands and succeed', async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
|
|
|
folder: 'build',
|
|
|
|
branch: 'branch',
|
|
|
|
gitHubToken: '123',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await run(action)
|
|
|
|
expect(execute).toBeCalledTimes(17)
|
|
|
|
expect(rmRF).toBeCalledTimes(1)
|
|
|
|
expect(exportVariable).toBeCalledTimes(1)
|
2020-03-05 21:19:45 +08:00
|
|
|
})
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
it('should throw if an error is encountered', async () => {
|
2020-01-20 05:16:28 +08:00
|
|
|
Object.assign(action, {
|
2020-03-05 21:19:45 +08:00
|
|
|
folder: 'build',
|
|
|
|
branch: 'branch',
|
|
|
|
baseBranch: 'master',
|
2020-01-20 05:16:28 +08:00
|
|
|
gitHubToken: null,
|
2020-03-29 01:24:51 +08:00
|
|
|
ssh: null,
|
2020-01-20 05:16:28 +08:00
|
|
|
accessToken: null,
|
|
|
|
pusher: {
|
2020-03-05 21:19:45 +08:00
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
2020-01-20 05:16:28 +08:00
|
|
|
},
|
|
|
|
isTest: true
|
2020-03-05 21:19:45 +08:00
|
|
|
})
|
|
|
|
await run(action)
|
|
|
|
expect(execute).toBeCalledTimes(0)
|
|
|
|
expect(setFailed).toBeCalledTimes(1)
|
2020-05-15 05:24:32 +08:00
|
|
|
expect(exportVariable).toBeCalledTimes(1)
|
2020-03-05 21:19:45 +08:00
|
|
|
})
|
|
|
|
})
|