-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig.test.js
66 lines (60 loc) · 2.56 KB
/
config.test.js
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
/* eslint-disable no-undef */
const process = require('process')
const { getConfig } = require('./config')
test('establishes config from minimum required inputs', () => {
process.env['INPUT_MODE'] = 'validate'
process.env['INPUT_REPO-TOKEN'] = 'mockRepoToken'
const config = getConfig()
expect(config.mode).toBe('validate')
expect(config.releaseLabels).toEqual({
'major release': 'major',
'minor release': 'minor',
'patch release': 'patch',
})
expect(config.noopLabels).toEqual({})
expect(config.releaseNotesPrefixPattern).toBeUndefined()
expect(config.releaseNotesSuffixPattern).toBeUndefined()
expect(config.requireReleaseNotes).toBe(false)
expect(config.v).toBe('')
expect(config.octokit).toBeDefined()
expect(config.octokit).not.toBeNull()
})
test('establishes config from complete set of inputs', () => {
process.env['INPUT_MODE'] = 'validate'
process.env['INPUT_REPO-TOKEN'] = 'mockRepoToken'
process.env['INPUT_MAJOR-LABEL'] = 'major-label-name'
process.env['INPUT_MINOR-LABEL'] = 'minor-label-name'
process.env['INPUT_PATCH-LABEL'] = 'patch-label-name'
process.env['INPUT_NOOP-LABELS'] = 'documentation label\nanother-label'
process.env['INPUT_REQUIRE-RELEASE-NOTES'] = 'true'
process.env['INPUT_RELEASE-NOTES-PREFIX'] = 'release-notes-prefix-text'
process.env['INPUT_RELEASE-NOTES-SUFFIX'] = 'release-notes-suffix-text'
process.env['INPUT_WITH-V'] = 'true'
const config = getConfig()
expect(config.mode).toBe('validate')
expect(config.releaseLabels).toEqual({
'major-label-name': 'major',
'minor-label-name': 'minor',
'patch-label-name': 'patch',
})
expect(config.noopLabels).toEqual({
'another-label': 'skip',
'documentation label': 'skip',
})
expect(config.releaseNotesPrefixPattern).toEqual(/release-notes-prefix-text/)
expect(config.releaseNotesSuffixPattern).toEqual(/release-notes-suffix-text/)
expect(config.requireReleaseNotes).toBe(true)
expect(config.v).toBe('v')
expect(config.octokit).toBeDefined()
expect(config.octokit).not.toBeNull()
})
test('throws when a required input is missing', () => {
process.env['INPUT_MODE'] = ''
process.env['INPUT_REPO-TOKEN'] = 'mockRepoToken'
expect(getConfig).toThrow('Input required and not supplied: mode')
})
test('errors out when an invalid mode is specified', () => {
process.env['INPUT_MODE'] = 'invalid'
process.env['INPUT_REPO-TOKEN'] = 'mockRepoToken'
expect(getConfig).toThrow("mode must be either 'validate' or 'bump'")
})