@@ -2,14 +2,19 @@ import * as core from '@actions/core'
2
2
import { Exclude } from '../../src/functions/exclude'
3
3
4
4
const warningMock = jest . spyOn ( core , 'warning' ) . mockImplementation ( ( ) => { } )
5
+ const setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockImplementation ( ( ) => { } )
6
+ const infoMock = jest . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
5
7
6
8
var exclude
7
9
beforeEach ( ( ) => {
8
10
jest . clearAllMocks ( )
9
11
jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } )
12
+ jest . spyOn ( core , 'setFailed' ) . mockImplementation ( ( ) => { } )
13
+ jest . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
10
14
process . env . INPUT_EXCLUDE_FILE = '__tests__/fixtures/exclude/exclude.txt'
11
15
process . env . INPUT_GIT_IGNORE_PATH = '.gitignore'
12
16
process . env . INPUT_USE_GITIGNORE = 'true'
17
+ process . env . INPUT_EXCLUDE_FILE_REQUIRED = 'true'
13
18
exclude = new Exclude ( )
14
19
} )
15
20
@@ -44,6 +49,31 @@ test('does not exclude any files when no exclude file is used', () => {
44
49
expect ( exclude . isExcluded ( 'exclude-me.json' ) ) . toBe ( false )
45
50
} )
46
51
52
+ test ( 'raises an exception when no exclude file is found' , ( ) => {
53
+ process . env . INPUT_EXCLUDE_FILE = 'oh_no_i_dont_exist.txt'
54
+ process . env . INPUT_EXCLUDE_FILE_REQUIRED = 'true'
55
+
56
+ expect ( ( ) => {
57
+ new Exclude ( )
58
+ } ) . toThrow (
59
+ `Error: ENOENT: no such file or directory, open 'oh_no_i_dont_exist.txt'`
60
+ )
61
+ expect ( setFailedMock ) . toHaveBeenCalledWith (
62
+ `error reading exclude_file: oh_no_i_dont_exist.txt`
63
+ )
64
+ } )
65
+
66
+ test ( 'does not raise an exception when no exclude file is found and it is not required' , ( ) => {
67
+ process . env . INPUT_EXCLUDE_FILE = 'oh_no_i_dont_exist.txt'
68
+ process . env . INPUT_EXCLUDE_FILE_REQUIRED = 'false'
69
+
70
+ const exclude = new Exclude ( )
71
+ expect ( exclude . isExcluded ( 'exclude-me.json' ) ) . toBe ( false )
72
+ expect ( infoMock ) . toHaveBeenCalledWith (
73
+ `exclude_file was not found, but it is not required - OK`
74
+ )
75
+ } )
76
+
47
77
test ( 'excludes a file that is not tracked by git' , ( ) => {
48
78
process . env . INPUT_EXCLUDE_FILE = ''
49
79
const exclude = new Exclude ( )
0 commit comments