From d2834fd15da67161871e162f15703ea4f92c2ae6 Mon Sep 17 00:00:00 2001 From: Jarno Rajahalme Date: Fri, 12 May 2023 09:40:27 +0300 Subject: [PATCH] tests: Add test with multiple negate groups Validate that a filter with multiple negate groups works as expected. Signed-off-by: Jarno Rajahalme --- __tests__/filter.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index be2a148..0a2663e 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -117,6 +117,26 @@ describe('matching tests', () => { expect(pyMatch.backend).toEqual(pyFiles) }) + test('matches all except tests or docs and tsx or less files (multiple negate groups)', () => { + const yaml = ` + backend: + - '!(test|docs)/**/!(*.tsx|*.less)' + ` + const filter = new Filter(yaml) + const tsxFiles = modified(['src/ui.tsx']) + const lessFiles = modified(['src/ui.less']) + const pyFiles = modified(['src/server.py', 'test/test.py', 'test/test.less', 'docs/readme.txt', 'src/server.tsx', 'src/client.py']) + const srcFiles = modified(['src/server.py', 'src/client.py']) + + const tsxMatch = filter.match(tsxFiles) + const lessMatch = filter.match(lessFiles) + const pyMatch = filter.match(pyFiles) + + expect(tsxMatch.backend).toEqual([]) + expect(lessMatch.backend).toEqual([]) + expect(pyMatch.backend).toEqual(srcFiles) + }) + test('matches path based on rules included using YAML anchor', () => { const yaml = ` shared: &shared