From 5af776fb70f3adb1f11dbf056179adf3c5f724b6 Mon Sep 17 00:00:00 2001 From: Daniil Samoylov Date: Tue, 1 Mar 2022 15:35:18 +1300 Subject: [PATCH] Add tests for the filter with negation --- .../workflows/pull-request-verification.yml | 41 ------------------- __tests__/filter.test.ts | 31 ++++++++++++++ 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/.github/workflows/pull-request-verification.yml b/.github/workflows/pull-request-verification.yml index b3f6952..a773f2f 100644 --- a/.github/workflows/pull-request-verification.yml +++ b/.github/workflows/pull-request-verification.yml @@ -94,44 +94,3 @@ jobs: - name: count-test if: steps.filter.outputs.local_count != 1 run: exit 1 - - test-change-type: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: configure GIT user - run: git config user.email "john@nowhere.local" && git config user.name "John Doe" - - name: modify working tree - run: touch add.txt && rm README.md && echo "TEST" > LICENSE - - name: commit changes - run: git add -A && git commit -a -m 'testing this action' - - uses: ./ - id: filter - with: - token: '' - list-files: shell - filters: | - added: - - added: "add.txt" - deleted: - - deleted: "README.md" - modified: - - modified: "LICENSE" - any: - - added|deleted|modified: "*" - - name: Print 'added_files' - run: echo ${{steps.filter.outputs.added_files}} - - name: Print 'modified_files' - run: echo ${{steps.filter.outputs.modified_files}} - - name: Print 'deleted_files' - run: echo ${{steps.filter.outputs.deleted_files}} - - name: filter-test - if: | - steps.filter.outputs.added != 'true' - || steps.filter.outputs.deleted != 'true' - || steps.filter.outputs.modified != 'true' - || steps.filter.outputs.any != 'true' - || steps.filter.outputs.added_files != 'add.txt' - || steps.filter.outputs.modified_files != 'LICENSE' - || steps.filter.outputs.deleted_files != 'README.md' - run: exit 1 diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index 8e02370..d61a451 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -117,6 +117,37 @@ describe('matching tests', () => { expect(pyMatch.backend).toEqual(pyFiles) }) + test('matches single rule with negation', () => { + const yaml = ` + src: + - '!src/**/*.js' + ` + const filter = new Filter(yaml) + const files = modified(['src/app/module/file.js']) + const match = filter.match(files) + expect(match.src).toEqual([]) + }) + + test('matches multiple rules with negation', () => { + const yaml = ` + src: + - 'src/**/*.ts' + - '!src/**/*.test.ts' + ` + const filter = new Filter(yaml) + const jsFiles = modified(['src/app/module/file.js']) + const tsFiles = modified(['src/app/module/file.ts']) + const tsTestFiles = modified(['src/app/module/file.test.ts']) + + const jsMatch = filter.match(jsFiles) + const tsMatch = filter.match(tsFiles) + const tsTestMatch = filter.match(tsTestFiles) + + expect(jsMatch.src).toEqual([]) + expect(tsMatch.src).toEqual(tsFiles) + expect(tsTestMatch.src).toEqual([]) + }) + test('matches path based on rules included using YAML anchor', () => { const yaml = ` shared: &shared