|
| 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 | +} |
0 commit comments