Skip to content

Commit a87ec7a

Browse files
committed
improve tests
1 parent 9f68be0 commit a87ec7a

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

__tests__/export.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as core from '@actions/core'
2+
import {Filter} from '../src/filter'
3+
import {File, ChangeStatus} from '../src/file'
4+
import {exportResults} from '../src/main'
5+
6+
jest.mock('@actions/core', () => ({
7+
info: jest.fn(),
8+
setFailed: jest.fn(),
9+
startGroup: jest.fn(),
10+
setOutput: jest.fn(),
11+
endGroup: jest.fn()
12+
}))
13+
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+
47+
function modified(paths: string[]): File[] {
48+
return paths.map(filename => {
49+
return {filename, status: ChangeStatus.Modified}
50+
})
51+
}

__tests__/filter.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import * as core from '@actions/core'
21
import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter'
32
import {File, ChangeStatus} from '../src/file'
4-
import {exportResults} from '../src/main'
5-
6-
jest.mock('@actions/core', () => ({
7-
info: jest.fn(),
8-
setFailed: jest.fn(),
9-
startGroup: jest.fn(),
10-
setOutput: jest.fn(),
11-
endGroup: jest.fn()
12-
}))
133

144
describe('yaml filter parsing tests', () => {
155
test('throws if yaml is not a dictionary', () => {
@@ -170,9 +160,6 @@ describe('matching tests', () => {
170160
const filter = new Filter(yaml)
171161
const files = modified(['config/settings.yml'])
172162
const match = filter.match(files)
173-
exportResults(match, 'none')
174-
175-
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src"]')
176163
expect(match.src).toEqual(files)
177164
})
178165
})

0 commit comments

Comments
 (0)