Skip to content

Commit 5ab3a8d

Browse files
committed
improve tests
1 parent 9f68be0 commit 5ab3a8d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

__tests__/filter.test.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,39 @@ jest.mock('@actions/core', () => ({
1111
endGroup: jest.fn()
1212
}))
1313

14+
describe('set output post filtering', () => {
15+
test('correctly sets output', () => {
16+
const yaml = `
17+
backend:
18+
- '!(**/*.tsx|**/*.less)'
19+
`
20+
const filter = new Filter(yaml)
21+
const files = modified(['config/settings.yml'])
22+
const match = filter.match(files)
23+
exportResults(match, 'none')
24+
25+
expect(core.setOutput).toHaveBeenCalledWith('changes', '["backend"]')
26+
})
27+
test('correctly filters out shared from output', () => {
28+
const yaml = `
29+
shared: &shared
30+
- common/**/*
31+
- config/**/*
32+
src:
33+
- *shared
34+
- src/**/*
35+
backend:
36+
- '!(**/*.tsx|**/*.less)'
37+
`
38+
const filter = new Filter(yaml)
39+
const files = modified(['config/settings.yml'])
40+
const match = filter.match(files)
41+
exportResults(match, 'none')
42+
43+
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src","backend"]')
44+
})
45+
})
46+
1447
describe('yaml filter parsing tests', () => {
1548
test('throws if yaml is not a dictionary', () => {
1649
const yaml = 'not a dictionary'
@@ -170,9 +203,6 @@ describe('matching tests', () => {
170203
const filter = new Filter(yaml)
171204
const files = modified(['config/settings.yml'])
172205
const match = filter.match(files)
173-
exportResults(match, 'none')
174-
175-
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src"]')
176206
expect(match.src).toEqual(files)
177207
})
178208
})

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export function exportResults(results: FilterResults, format: ExportFormat): voi
255255

256256
if (results['changes'] === undefined) {
257257
const filteredShared = changes.filter(change => change !== 'shared')
258+
console.log({changes, filteredShared})
258259
const changesJson = JSON.stringify(filteredShared)
259260
core.info(`Changes output set to ${changesJson}`)
260261
core.setOutput('changes', changesJson)

0 commit comments

Comments
 (0)