1
1
import * as core from '@actions/core'
2
2
import { Exclude } from '../../src/functions/exclude'
3
3
4
- const debugMock = jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } )
5
4
const warningMock = jest . spyOn ( core , 'warning' ) . mockImplementation ( ( ) => { } )
6
5
7
6
var exclude
8
7
beforeEach ( ( ) => {
9
8
jest . clearAllMocks ( )
9
+ jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } )
10
10
process . env . INPUT_EXCLUDE_FILE = '__tests__/fixtures/exclude/exclude.txt'
11
11
process . env . INPUT_GIT_IGNORE_PATH = '.gitignore'
12
12
process . env . INPUT_USE_GITIGNORE = 'true'
@@ -15,60 +15,26 @@ beforeEach(() => {
15
15
16
16
test ( 'successfully excludes a file' , ( ) => {
17
17
expect ( exclude . isExcluded ( 'exclude-me.json' ) ) . toBe ( true )
18
- expect ( debugMock ) . toHaveBeenCalledWith (
19
- `file exactly matches exclude pattern: exclude-me.json`
20
- )
21
18
} )
22
19
23
20
test ( 'successfully excludes a with a glob match' , ( ) => {
24
21
expect ( exclude . isExcluded ( 'src/dev/app/nope.exclude' ) ) . toBe ( true )
25
- expect ( debugMock ) . toHaveBeenCalledWith (
26
- `file matches exclude glob pattern: *.exclude`
27
- )
28
- } )
29
-
30
- test ( 'successfully does not exclude a negate pattern match' , ( ) => {
31
- expect ( exclude . isExcluded ( 'cat.txt' ) ) . toBe ( false )
32
- expect ( debugMock ) . toHaveBeenCalledWith (
33
- `file matches exclude negation pattern: !cat.txt`
34
- )
35
- } )
36
-
37
- test ( 'successfully excludes a file where the negate pattern matches after' , ( ) => {
38
- expect ( exclude . isExcluded ( 'dog.txt' ) ) . toBe ( true )
39
- expect ( debugMock ) . toHaveBeenCalledWith (
40
- `file exactly matches exclude pattern: dog.txt`
41
- )
42
22
} )
43
23
44
24
test ( 'successfully excludes with a regex pattern match' , ( ) => {
45
25
expect ( exclude . isExcluded ( 'src/app/cars-and-a-bus.txt' ) ) . toBe ( true )
46
- expect ( debugMock ) . toHaveBeenCalledWith (
47
- `file matches exclude regex pattern: /^.*cars.*\\.txt$/`
48
- )
49
26
} )
50
27
51
28
test ( 'successfully excludes a file in a dir one level down' , ( ) => {
52
- expect ( exclude . isExcluded ( './evil-base-dir/exclude-me.json' ) ) . toBe ( true )
53
- expect ( debugMock ) . toHaveBeenCalledWith (
54
- `file is in exclude directory: evil-base-dir/`
55
- )
29
+ expect ( exclude . isExcluded ( 'evil-base-dir/exclude-me.json' ) ) . toBe ( true )
56
30
} )
57
31
58
32
test ( 'successfully excludes a file in a dir two levels down' , ( ) => {
59
- expect ( exclude . isExcluded ( './evil-base-dir/sub-dir/exclude-me.json' ) ) . toBe (
60
- true
61
- )
62
- expect ( debugMock ) . toHaveBeenCalledWith (
63
- `file is in exclude directory: evil-base-dir/`
64
- )
33
+ expect ( exclude . isExcluded ( 'evil-base-dir/sub-dir/exclude-me.json' ) ) . toBe ( true )
65
34
} )
66
35
67
36
test ( 'successfully checks a file and finds that it is not excluded' , ( ) => {
68
37
expect ( exclude . isExcluded ( 'exclude-me-nope.json' ) ) . toBe ( false )
69
- expect ( debugMock ) . toHaveBeenCalledWith (
70
- `file 'exclude-me-nope.json' did not match any exclude patterns`
71
- )
72
38
} )
73
39
74
40
test ( 'does not exclude any files when no exclude file is used' , ( ) => {
@@ -82,7 +48,6 @@ test('excludes a file that is not tracked by git', () => {
82
48
process . env . INPUT_EXCLUDE_FILE = ''
83
49
const exclude = new Exclude ( )
84
50
expect ( exclude . isExcluded ( 'tmp/test.json' ) ) . toBe ( true )
85
- expect ( debugMock ) . toHaveBeenCalledWith ( `file is in exclude directory: tmp/` )
86
51
} )
87
52
88
53
test ( 'fails to read the .gitignore file' , ( ) => {
0 commit comments