Skip to content

Commit

Permalink
Add tests for the filter with negation
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Dann committed Mar 1, 2022
1 parent 6706fee commit 37445a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" && 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
31 changes: 31 additions & 0 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37445a7

Please sign in to comment.