github-pages-deploy-action/__tests__/git.test.ts
James Ives d418023e70
4.1.2 (#707)
* Release 4.1.1 📣

* Version README -> 4.1.1

* Bump eslint-plugin-jest from 24.3.2 to 24.3.4 (#658)

Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.3.2 to 24.3.4.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.2...v24.3.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @actions/io from 1.0.2 to 1.1.0 (#659)

Bumps [@actions/io](https://github.com/actions/toolkit/tree/HEAD/packages/io) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/io/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/@actions/core@1.1.0/packages/io)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint-plugin-prettier from 3.1.2 to 3.3.1 (#660)

Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 3.1.2 to 3.3.1.
- [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-plugin-prettier/compare/v3.1.2...v3.3.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint-plugin-github from 4.1.2 to 4.1.3 (#662)

Bumps [eslint-plugin-github](https://github.com/github/eslint-plugin-github) from 4.1.2 to 4.1.3.
- [Release notes](https://github.com/github/eslint-plugin-github/releases)
- [Commits](https://github.com/github/eslint-plugin-github/compare/v4.1.2...v4.1.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump typescript from 4.2.3 to 4.2.4 (#663)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.2.3 to 4.2.4.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint-plugin-jest from 24.3.4 to 24.3.5 (#666)

Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.3.4 to 24.3.5.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.4...v24.3.5)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint from 7.23.0 to 7.24.0 (#667)

Bumps [eslint](https://github.com/eslint/eslint) from 7.23.0 to 7.24.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.23.0...v7.24.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @actions/core from 1.2.6 to 1.2.7 (#669)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.2.7.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @types/node from 14.14.37 to 14.14.39 (#670)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.37 to 14.14.39.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* changed branch master to main (#676)

* Bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#671)

Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 3.3.1 to 3.4.0.
- [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-plugin-prettier/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @types/node from 14.14.39 to 14.14.41 (#673)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.39 to 14.14.41.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ts-jest from 26.5.4 to 26.5.5 (#674)

Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 26.5.4 to 26.5.5.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v26.5.4...v26.5.5)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Check buffer length (#668)

* Check buffer len

* Update execute.ts

* Format

* Bump eslint from 7.24.0 to 7.25.0 (#684)

Bumps [eslint](https://github.com/eslint/eslint) from 7.24.0 to 7.25.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.24.0...v7.25.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint-plugin-jest from 24.3.5 to 24.3.6 (#683)

Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.3.5 to 24.3.6.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.5...v24.3.6)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Eslint improvements (#686)

* Initial Pass at new configs

* Improved Linting/Formatting

* Update execute.ts

* Update main.test.ts

* Change typing

* Update git.ts

* Update worktree.ts

* Update worktree.ts

* Update worktree.ts

* Maybe

* Update execute.ts

* Bump @types/jest from 26.0.22 to 26.0.23 (#688)

Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.22 to 26.0.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @types/node from 14.14.41 to 15.0.0 (#689)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.41 to 15.0.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @types/node from 15.0.0 to 15.0.1 (#691)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.0.0 to 15.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update README.md

* Bump @types/node from 15.0.1 to 15.0.2 (#692)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.0.1 to 15.0.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @typescript-eslint/eslint-plugin from 4.22.0 to 4.22.1 (#693)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.22.0 to 4.22.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.22.1/packages/eslint-plugin)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @typescript-eslint/parser from 4.22.0 to 4.22.1 (#694)

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 4.22.0 to 4.22.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.22.1/packages/parser)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Adds Sponsors

* Update README.md

* Deploying to dev from @ JamesIves/github-pages-deploy-action@ac8210fb5f 🚀

* Update README.md

* Update sponsors.yml

* Update README.md

* Update main.test.ts

* Deploying to dev from @ JamesIves/github-pages-deploy-action@184d104236 🚀

* Bump ts-jest from 26.5.5 to 26.5.6 (#695)

Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 26.5.5 to 26.5.6.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v26.5.5...v26.5.6)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update sponsors.yml

* Update BUG_REPORT.md

* Updated documentation for `clean` (#698)

Tried to be more clear about what it does. Said that it does not touch `.git`, `.github`, `.ssh`.

* Bump eslint from 7.25.0 to 7.26.0 (#704)

Bumps [eslint](https://github.com/eslint/eslint) from 7.25.0 to 7.26.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.25.0...v7.26.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump hosted-git-info from 2.8.8 to 2.8.9 (#706)

Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Allow Subsequent Deployments (#690)

* Removing artifacts

* Update git.ts

* Update git.ts

* Fixng up unit tests

* Update main.test.ts

* Update integration.yml

* Update integration.yml

* Changes to ref search (#705)

* Exact match on branchExists

* Linting

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lambert Schulze <schulze.lambert@googlemail.com>
Co-authored-by: JamesIves <JamesIves@users.noreply.github.com>
Co-authored-by: Sancho McCann <sanchom@gmail.com>
2021-05-10 10:07:20 -04:00

429 lines
11 KiB
TypeScript

// Initial env variable setup for tests.
process.env['INPUT_FOLDER'] = 'build'
process.env['GITHUB_SHA'] = '123'
import {mkdirP, rmRF} from '@actions/io'
import {action, Status, TestFlag} from '../src/constants'
import {execute} from '../src/execute'
import {deploy, init} from '../src/git'
import fs from 'fs'
const originalAction = JSON.stringify(action)
jest.mock('fs', () => ({
existsSync: jest.fn()
}))
jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
setOutput: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
jest.mock('@actions/io', () => ({
rmRF: jest.fn(),
mkdirP: jest.fn()
}))
jest.mock('../src/execute', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
execute: jest.fn()
}))
describe('git', () => {
afterEach(() => {
Object.assign(action, JSON.parse(originalAction))
})
describe('init', () => {
it('should execute commands', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action',
token: '123',
branch: 'branch',
folder: '.',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
await init(action)
expect(execute).toBeCalledTimes(5)
})
it('should catch when a function throws an error', async () => {
;(execute as jest.Mock).mockImplementationOnce(() => {
throw new Error('Mocked throw')
})
Object.assign(action, {
hostname: 'github.com',
silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action',
token: '123',
branch: 'branch',
folder: '.',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
try {
await init(action)
} catch (error) {
expect(error.message).toBe(
'There was an error initializing the repository: Mocked throw ❌'
)
}
})
it('should correctly continue when it cannot unset a git config value', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action',
token: '123',
branch: 'branch',
folder: '.',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.UNABLE_TO_UNSET_GIT_CONFIG
})
await init(action)
expect(execute).toBeCalledTimes(5)
})
it('should not unset git config if a user is using ssh', async () => {
// Sets and unsets the CI condition.
process.env.CI = 'true'
Object.assign(action, {
hostname: 'github.com',
silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action',
sshKey: true,
branch: 'branch',
folder: '.',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: false
})
await init(action)
expect(execute).toBeCalledTimes(4)
process.env.CI = undefined
})
it('should correctly continue when it cannot remove origin', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action',
token: '123',
branch: 'branch',
folder: '.',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.UNABLE_TO_REMOVE_ORIGIN
})
await init(action)
expect(execute).toBeCalledTimes(5)
})
})
describe('deploy', () => {
it('should execute commands', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
branch: 'branch',
token: '123',
repositoryName: 'JamesIves/montezuma',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
const response = await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})
it('should not push when asked to dryRun', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
dryRun: true,
folder: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
const response = await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(12)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})
it('should execute commands with single commit toggled', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'other',
folderPath: 'other',
branch: 'branch',
token: '123',
singleCommit: true,
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
isTest: TestFlag.HAS_CHANGED_FILES
})
await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
})
it('should execute commands with single commit toggled and existing branch', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'other',
folderPath: 'other',
branch: 'branch',
token: '123',
singleCommit: true,
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
isTest: TestFlag.HAS_CHANGED_FILES | TestFlag.HAS_REMOTE_BRANCH
})
await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(9)
expect(rmRF).toBeCalledTimes(1)
})
it('should execute commands with single commit and dryRun toggled', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'other',
folderPath: 'other',
branch: 'branch',
gitHubToken: '123',
singleCommit: true,
dryRun: true,
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
isTest: TestFlag.HAS_CHANGED_FILES
})
await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(9)
expect(rmRF).toBeCalledTimes(1)
})
it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => {
;(fs.existsSync as jest.Mock)
.mockImplementationOnce(() => {
return true
})
.mockImplementationOnce(() => {
return true
})
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
folderPath: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
isTest: TestFlag.HAS_CHANGED_FILES
})
const response = await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(fs.existsSync).toBeCalledTimes(2)
expect(response).toBe(Status.SUCCESS)
})
describe('with empty GITHUB_SHA', () => {
const oldSha = process.env.GITHUB_SHA
afterAll(() => {
process.env.GITHUB_SHA = oldSha
})
it('should execute commands with clean options', async () => {
process.env.GITHUB_SHA = ''
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'other',
folderPath: 'other',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
workspace: 'other',
isTest: TestFlag.NONE
})
await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
})
})
it('should execute commands with clean options stored as an array', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
folderPath: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
clean: true,
cleanExclude: ['cat', 'montezuma'],
isTest: TestFlag.NONE
})
await deploy(action)
// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
})
it('should gracefully handle target folder', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: '.',
branch: 'branch',
token: '123',
pusher: {},
clean: true,
targetFolder: 'new_folder',
commitMessage: 'Hello!',
isTest: TestFlag.NONE
})
await deploy(action)
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
expect(mkdirP).toBeCalledTimes(1)
})
it('should stop early if there is nothing to commit', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.NONE // Setting this flag to None means there will never be anything to commit and the action will exit early.
})
const response = await deploy(action)
expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SKIPPED)
})
it('should catch when a function throws an error', async () => {
;(execute as jest.Mock).mockImplementationOnce(() => {
throw new Error('Mocked throw')
})
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
branch: 'branch',
token: '123',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
try {
await deploy(action)
} catch (error) {
expect(error.message).toBe(
'The deploy step encountered an error: Mocked throw ❌'
)
}
})
})
})