mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
560e416032
* Stop checking out base branch before deployment, drop option. * Don't check out default branch, as we don't check out base branch, drop option. * Don't stash/unstash as we don't update the workdir, drop preserve option. * Don't init the workspace * Only fetch the remote branch if it exists, only with depth 1. * Rely on previous checkouts to have handled lfs files correctly, drop option. * Update README, action.yml, integration tests
91 lines
2.1 KiB
TypeScript
91 lines
2.1 KiB
TypeScript
// 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} 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(),
|
|
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',
|
|
gitHubToken: '123',
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
},
|
|
isTest: false,
|
|
debug: true
|
|
})
|
|
await run(action)
|
|
expect(execute).toBeCalledTimes(12)
|
|
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',
|
|
gitHubToken: '123',
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
}
|
|
})
|
|
await run(action)
|
|
expect(execute).toBeCalledTimes(12)
|
|
expect(rmRF).toBeCalledTimes(1)
|
|
expect(exportVariable).toBeCalledTimes(1)
|
|
})
|
|
|
|
it('should throw if an error is encountered', async () => {
|
|
Object.assign(action, {
|
|
folder: 'assets',
|
|
branch: 'branch',
|
|
gitHubToken: null,
|
|
ssh: null,
|
|
accessToken: null,
|
|
pusher: {
|
|
name: 'asd',
|
|
email: 'as@cat'
|
|
},
|
|
isTest: true
|
|
})
|
|
await run(action)
|
|
expect(execute).toBeCalledTimes(0)
|
|
expect(setFailed).toBeCalledTimes(1)
|
|
expect(exportVariable).toBeCalledTimes(1)
|
|
})
|
|
})
|