Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasyarid committed May 17, 2024
1 parent 9f68be0 commit 5ab3a8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
36 changes: 33 additions & 3 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@ jest.mock('@actions/core', () => ({
endGroup: jest.fn()
}))

describe('set output post filtering', () => {
test('correctly sets output', () => {
const yaml = `
backend:
- '!(**/*.tsx|**/*.less)'
`
const filter = new Filter(yaml)
const files = modified(['config/settings.yml'])
const match = filter.match(files)
exportResults(match, 'none')

expect(core.setOutput).toHaveBeenCalledWith('changes', '["backend"]')
})
test('correctly filters out shared from output', () => {
const yaml = `
shared: &shared
- common/**/*
- config/**/*
src:
- *shared
- src/**/*
backend:
- '!(**/*.tsx|**/*.less)'
`
const filter = new Filter(yaml)
const files = modified(['config/settings.yml'])
const match = filter.match(files)
exportResults(match, 'none')

expect(core.setOutput).toHaveBeenCalledWith('changes', '["src","backend"]')
})
})

describe('yaml filter parsing tests', () => {
test('throws if yaml is not a dictionary', () => {
const yaml = 'not a dictionary'
Expand Down Expand Up @@ -170,9 +203,6 @@ describe('matching tests', () => {
const filter = new Filter(yaml)
const files = modified(['config/settings.yml'])
const match = filter.match(files)
exportResults(match, 'none')

expect(core.setOutput).toHaveBeenCalledWith('changes', '["src"]')
expect(match.src).toEqual(files)
})
})
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export function exportResults(results: FilterResults, format: ExportFormat): voi

if (results['changes'] === undefined) {
const filteredShared = changes.filter(change => change !== 'shared')
console.log({changes, filteredShared})
const changesJson = JSON.stringify(filteredShared)
core.info(`Changes output set to ${changesJson}`)
core.setOutput('changes', changesJson)
Expand Down

0 comments on commit 5ab3a8d

Please sign in to comment.