Skip to content

Commit dc667b3

Browse files
authored
Feat: add support for checking if source folder exists (JamesIves#463)
* Refactor: check parameters in `init` * Test: add test for checking if folder exist - rm unnecessary tests * Test: fix wrong error message * Refactor: mv initialization functions to `run` Refactor: rm `action.root`, `action.rootPath` Refactor: `generateFolderPath`, `hasRequiredParameters` Test: rm some tests for `init`, add tests for `checkParameters`
1 parent dc96a8f commit dc667b3

File tree

6 files changed

+154
-304
lines changed

6 files changed

+154
-304
lines changed

__tests__/git.test.ts

Lines changed: 0 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -32,171 +32,6 @@ describe('git', () => {
3232
})
3333

3434
describe('init', () => {
35-
it('should execute commands if a GitHub token is provided', async () => {
36-
Object.assign(action, {
37-
silent: false,
38-
repositoryPath: 'JamesIves/github-pages-deploy-action',
39-
folder: 'assets',
40-
branch: 'branch',
41-
gitHubToken: '123',
42-
pusher: {
43-
name: 'asd',
44-
email: 'as@cat'
45-
}
46-
})
47-
48-
await init(action)
49-
expect(execute).toBeCalledTimes(6)
50-
})
51-
52-
it('should execute commands if an Access Token is provided', async () => {
53-
Object.assign(action, {
54-
silent: false,
55-
repositoryPath: 'JamesIves/github-pages-deploy-action',
56-
folder: 'assets',
57-
branch: 'branch',
58-
accessToken: '123',
59-
pusher: {
60-
name: 'asd',
61-
email: 'as@cat'
62-
}
63-
})
64-
65-
await init(action)
66-
expect(execute).toBeCalledTimes(6)
67-
})
68-
69-
it('should execute commands if SSH is true', async () => {
70-
Object.assign(action, {
71-
silent: false,
72-
repositoryPath: 'JamesIves/github-pages-deploy-action',
73-
folder: 'assets',
74-
branch: 'branch',
75-
ssh: true,
76-
pusher: {
77-
name: 'asd',
78-
email: 'as@cat'
79-
}
80-
})
81-
82-
await init(action)
83-
84-
expect(execute).toBeCalledTimes(6)
85-
})
86-
87-
it('should fail if there is no provided GitHub Token, Access Token or SSH bool', async () => {
88-
Object.assign(action, {
89-
silent: false,
90-
repositoryPath: null,
91-
folder: 'assets',
92-
branch: 'branch',
93-
pusher: {
94-
name: 'asd',
95-
email: 'as@cat'
96-
}
97-
})
98-
99-
try {
100-
await init(action)
101-
} catch (e) {
102-
expect(execute).toBeCalledTimes(0)
103-
expect(e.message).toMatch(
104-
'There was an error initializing the repository: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. ❌'
105-
)
106-
}
107-
})
108-
109-
it('should fail if access token is defined but it is an empty string', async () => {
110-
Object.assign(action, {
111-
silent: false,
112-
repositoryPath: null,
113-
folder: 'assets',
114-
branch: 'branch',
115-
pusher: {
116-
name: 'asd',
117-
email: 'as@cat'
118-
},
119-
accessToken: ''
120-
})
121-
122-
try {
123-
await init(action)
124-
} catch (e) {
125-
expect(execute).toBeCalledTimes(0)
126-
expect(e.message).toMatch(
127-
'There was an error initializing the repository: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. ❌'
128-
)
129-
}
130-
})
131-
132-
it('should fail if there is no folder', async () => {
133-
Object.assign(action, {
134-
silent: false,
135-
repositoryPath: 'JamesIves/github-pages-deploy-action',
136-
gitHubToken: '123',
137-
branch: 'branch',
138-
pusher: {
139-
name: 'asd',
140-
email: 'as@cat'
141-
},
142-
folder: null,
143-
ssh: true
144-
})
145-
146-
try {
147-
await init(action)
148-
} catch (e) {
149-
expect(execute).toBeCalledTimes(0)
150-
expect(e.message).toMatch(
151-
'There was an error initializing the repository: You must provide the action with a folder to deploy. ❌'
152-
)
153-
}
154-
})
155-
156-
it('should fail if there is no provided repository path', async () => {
157-
Object.assign(action, {
158-
silent: true,
159-
repositoryPath: null,
160-
folder: 'assets',
161-
branch: 'branch',
162-
pusher: {
163-
name: 'asd',
164-
email: 'as@cat'
165-
},
166-
gitHubToken: '123',
167-
accessToken: null,
168-
ssh: null
169-
})
170-
171-
try {
172-
await init(action)
173-
} catch (e) {
174-
expect(execute).toBeCalledTimes(0)
175-
expect(e.message).toMatch(
176-
'There was an error initializing the repository: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. '
177-
)
178-
}
179-
})
180-
181-
it('should not fail if root is used', async () => {
182-
Object.assign(action, {
183-
silent: false,
184-
repositoryPath: 'JamesIves/github-pages-deploy-action',
185-
accessToken: '123',
186-
branch: 'branch',
187-
folder: '.',
188-
root: '.',
189-
pusher: {
190-
name: 'asd',
191-
email: 'as@cat'
192-
}
193-
})
194-
195-
await init(action)
196-
197-
expect(execute).toBeCalledTimes(6)
198-
})
199-
20035
it('should stash changes if preserve is true', async () => {
20136
Object.assign(action, {
20237
silent: false,
@@ -213,7 +48,6 @@ describe('git', () => {
21348
})
21449

21550
await init(action)
216-
21751
expect(execute).toBeCalledTimes(7)
21852
})
21953
})
@@ -234,27 +68,6 @@ describe('git', () => {
23468
await generateBranch(action)
23569
expect(execute).toBeCalledTimes(6)
23670
})
237-
238-
it('should fail if there is no branch', async () => {
239-
Object.assign(action, {
240-
silent: false,
241-
accessToken: '123',
242-
branch: null,
243-
folder: '.',
244-
pusher: {
245-
name: 'asd',
246-
email: 'as@cat'
247-
}
248-
})
249-
250-
try {
251-
await generateBranch(action)
252-
} catch (e) {
253-
expect(e.message).toMatch(
254-
'There was an error creating the deployment branch: Branch is required. ❌'
255-
)
256-
}
257-
})
25871
})
25972

26073
describe('switchToBaseBranch', () => {
@@ -290,31 +103,6 @@ describe('git', () => {
290103
await switchToBaseBranch(action)
291104
expect(execute).toBeCalledTimes(1)
292105
})
293-
294-
it('should fail if one of the required parameters is not available', async () => {
295-
Object.assign(action, {
296-
silent: false,
297-
baseBranch: '123',
298-
accessToken: null,
299-
gitHubToken: null,
300-
ssh: null,
301-
branch: 'branch',
302-
folder: null,
303-
pusher: {
304-
name: 'asd',
305-
email: 'as@cat'
306-
}
307-
})
308-
309-
try {
310-
await switchToBaseBranch(action)
311-
} catch (e) {
312-
expect(execute).toBeCalledTimes(0)
313-
expect(e.message).toMatch(
314-
'There was an error switching to the base branch: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. ❌'
315-
)
316-
}
317-
})
318106
})
319107

320108
describe('deploy', () => {
@@ -488,31 +276,5 @@ describe('git', () => {
488276
expect(rmRF).toBeCalledTimes(1)
489277
expect(response).toBe(Status.SKIPPED)
490278
})
491-
492-
it('should throw an error if one of the required parameters is not available', async () => {
493-
Object.assign(action, {
494-
silent: false,
495-
folder: 'assets',
496-
branch: 'branch',
497-
ssh: null,
498-
accessToken: null,
499-
gitHubToken: null,
500-
pusher: {
501-
name: 'asd',
502-
email: 'as@cat'
503-
},
504-
isTest: false // Setting this env variable to false means there will never be anything to commit and the action will exit early.
505-
})
506-
507-
try {
508-
await deploy(action)
509-
} catch (e) {
510-
expect(execute).toBeCalledTimes(1)
511-
expect(rmRF).toBeCalledTimes(1)
512-
expect(e.message).toMatch(
513-
'The deploy step encountered an error: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. ❌'
514-
)
515-
}
516-
})
517279
})
518280
})

0 commit comments

Comments
 (0)