diff --git a/__tests__/export.test.ts b/__tests__/export.test.ts new file mode 100644 index 0000000..e649fc4 --- /dev/null +++ b/__tests__/export.test.ts @@ -0,0 +1,51 @@ +import * as core from '@actions/core' +import {Filter} from '../src/filter' +import {File, ChangeStatus} from '../src/file' +import {exportResults} from '../src/main' + +jest.mock('@actions/core', () => ({ + info: jest.fn(), + setFailed: jest.fn(), + startGroup: jest.fn(), + setOutput: jest.fn(), + 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"]') + }) +}) + +function modified(paths: string[]): File[] { + return paths.map(filename => { + return {filename, status: ChangeStatus.Modified} + }) +} diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index 6f5a9b4..7d7da94 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -1,15 +1,5 @@ -import * as core from '@actions/core' import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter' import {File, ChangeStatus} from '../src/file' -import {exportResults} from '../src/main' - -jest.mock('@actions/core', () => ({ - info: jest.fn(), - setFailed: jest.fn(), - startGroup: jest.fn(), - setOutput: jest.fn(), - endGroup: jest.fn() -})) describe('yaml filter parsing tests', () => { test('throws if yaml is not a dictionary', () => { @@ -170,9 +160,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) }) })