Skip to content

Commit e74ebb4

Browse files
committed
update tests and bundle
1 parent a91332c commit e74ebb4

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

__tests__/functions/exclude.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import * as core from '@actions/core'
22
import {Exclude} from '../../src/functions/exclude'
33

44
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
5+
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation(() => {})
6+
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
57

68
var exclude
79
beforeEach(() => {
810
jest.clearAllMocks()
911
jest.spyOn(core, 'debug').mockImplementation(() => {})
12+
jest.spyOn(core, 'setFailed').mockImplementation(() => {})
13+
jest.spyOn(core, 'info').mockImplementation(() => {})
1014
process.env.INPUT_EXCLUDE_FILE = '__tests__/fixtures/exclude/exclude.txt'
1115
process.env.INPUT_GIT_IGNORE_PATH = '.gitignore'
1216
process.env.INPUT_USE_GITIGNORE = 'true'
17+
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'true'
1318
exclude = new Exclude()
1419
})
1520

@@ -44,6 +49,31 @@ test('does not exclude any files when no exclude file is used', () => {
4449
expect(exclude.isExcluded('exclude-me.json')).toBe(false)
4550
})
4651

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+
4777
test('excludes a file that is not tracked by git', () => {
4878
process.env.INPUT_EXCLUDE_FILE = ''
4979
const exclude = new Exclude()

__tests__/main.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ beforeEach(() => {
1616
})
1717

1818
process.env.INPUT_USE_GITIGNORE = 'false'
19+
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'true'
1920
})
2021

2122
test('successfully runs the action', async () => {

dist/index.js

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)