From 5ab3a8d35e46f2e0408d5a65738a537fe72d0494 Mon Sep 17 00:00:00 2001 From: Lucas Yarid Date: Fri, 17 May 2024 11:45:06 +0200 Subject: [PATCH] improve tests --- __tests__/filter.test.ts | 36 +++++++++++++++++++++++++++++++++--- src/main.ts | 1 + 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index 6f5a9b4..b8e42cd 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -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' @@ -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) }) }) diff --git a/src/main.ts b/src/main.ts index e78b3b2..f7aee59 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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)