Skip to content

Commit

Permalink
update tests and bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Aug 15, 2024
1 parent a91332c commit e74ebb4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
30 changes: 30 additions & 0 deletions __tests__/functions/exclude.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import * as core from '@actions/core'
import {Exclude} from '../../src/functions/exclude'

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

var exclude
beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'debug').mockImplementation(() => {})
jest.spyOn(core, 'setFailed').mockImplementation(() => {})
jest.spyOn(core, 'info').mockImplementation(() => {})
process.env.INPUT_EXCLUDE_FILE = '__tests__/fixtures/exclude/exclude.txt'
process.env.INPUT_GIT_IGNORE_PATH = '.gitignore'
process.env.INPUT_USE_GITIGNORE = 'true'
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'true'
exclude = new Exclude()
})

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

test('raises an exception when no exclude file is found', () => {
process.env.INPUT_EXCLUDE_FILE = 'oh_no_i_dont_exist.txt'
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'true'

expect(() => {
new Exclude()
}).toThrow(
`Error: ENOENT: no such file or directory, open 'oh_no_i_dont_exist.txt'`
)
expect(setFailedMock).toHaveBeenCalledWith(
`error reading exclude_file: oh_no_i_dont_exist.txt`
)
})

test('does not raise an exception when no exclude file is found and it is not required', () => {
process.env.INPUT_EXCLUDE_FILE = 'oh_no_i_dont_exist.txt'
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'false'

const exclude = new Exclude()
expect(exclude.isExcluded('exclude-me.json')).toBe(false)
expect(infoMock).toHaveBeenCalledWith(
`exclude_file was not found, but it is not required - OK`
)
})

test('excludes a file that is not tracked by git', () => {
process.env.INPUT_EXCLUDE_FILE = ''
const exclude = new Exclude()
Expand Down
1 change: 1 addition & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ beforeEach(() => {
})

process.env.INPUT_USE_GITIGNORE = 'false'
process.env.INPUT_EXCLUDE_FILE_REQUIRED = 'true'
})

test('successfully runs the action', async () => {
Expand Down
14 changes: 12 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit e74ebb4

Please sign in to comment.