forked from JamesIves/github-pages-deploy-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.test.ts
95 lines (86 loc) · 2.34 KB
/
main.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// 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: '.github/assets',
branch: 'branch',
token: '123',
hostname: 'github.com',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.NONE,
debug: true
})
await run(action)
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should run through the commands and succeed', async () => {
Object.assign(action, {
hostname: 'github.com',
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: '.github/assets',
branch: 'branch',
token: '123',
sshKey: true,
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(17)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should throw if an error is encountered', async () => {
Object.assign(action, {
hostname: 'github.com',
folder: '.github/assets',
branch: 'branch',
token: null,
sshKey: 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)
})
})