mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-07 16:49:03 +00:00
Export files matching rules (#32)
* Export files matching rules * Improve debug output * Fix PR test workflow * Always quote output path + fix PR test * Use proper single quote escaping in workflow file * Improve error handling and docs for list-files input parameter
This commit is contained in:
parent
483986d0a7
commit
3f845744aa
8 changed files with 205 additions and 125 deletions
|
@ -1,4 +1,4 @@
|
|||
import Filter from '../src/filter'
|
||||
import {Filter} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
|
||||
describe('yaml filter parsing tests', () => {
|
||||
|
@ -25,8 +25,9 @@ describe('matching tests', () => {
|
|||
src: "src/**/*.js"
|
||||
`
|
||||
let filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['src/app/module/file.js']))
|
||||
expect(match.src).toBeTruthy()
|
||||
const files = modified(['src/app/module/file.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
})
|
||||
test('matches single rule in single group', () => {
|
||||
const yaml = `
|
||||
|
@ -34,8 +35,9 @@ describe('matching tests', () => {
|
|||
- src/**/*.js
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['src/app/module/file.js']))
|
||||
expect(match.src).toBeTruthy()
|
||||
const files = modified(['src/app/module/file.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
})
|
||||
|
||||
test('no match when file is in different folder', () => {
|
||||
|
@ -45,7 +47,7 @@ describe('matching tests', () => {
|
|||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['not_src/other_file.js']))
|
||||
expect(match.src).toBeFalsy()
|
||||
expect(match.src).toEqual([])
|
||||
})
|
||||
|
||||
test('match only within second groups ', () => {
|
||||
|
@ -56,9 +58,10 @@ describe('matching tests', () => {
|
|||
- test/**/*.js
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['test/test.js']))
|
||||
expect(match.src).toBeFalsy()
|
||||
expect(match.test).toBeTruthy()
|
||||
const files = modified(['test/test.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual([])
|
||||
expect(match.test).toEqual(files)
|
||||
})
|
||||
|
||||
test('match only withing second rule of single group', () => {
|
||||
|
@ -68,18 +71,20 @@ describe('matching tests', () => {
|
|||
- test/**/*.js
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['test/test.js']))
|
||||
expect(match.src).toBeTruthy()
|
||||
const files = modified(['test/test.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
})
|
||||
|
||||
test('matches anything', () => {
|
||||
const yaml = `
|
||||
any:
|
||||
- "**/*"
|
||||
- "**"
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['test/test.js']))
|
||||
expect(match.any).toBeTruthy()
|
||||
const files = modified(['test/test.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.any).toEqual(files)
|
||||
})
|
||||
|
||||
test('globbing matches path where file or folder name starts with dot', () => {
|
||||
|
@ -88,8 +93,9 @@ describe('matching tests', () => {
|
|||
- "**/*.js"
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['.test/.test.js']))
|
||||
expect(match.dot).toBeTruthy()
|
||||
const files = modified(['.test/.test.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.dot).toEqual(files)
|
||||
})
|
||||
|
||||
test('matches path based on rules included using YAML anchor', () => {
|
||||
|
@ -101,9 +107,10 @@ describe('matching tests', () => {
|
|||
- *shared
|
||||
- src/**/*
|
||||
`
|
||||
let filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['config/settings.yml']))
|
||||
expect(match.src).toBeTruthy()
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -115,7 +122,7 @@ describe('matching specific change status', () => {
|
|||
`
|
||||
let filter = new Filter(yaml)
|
||||
const match = filter.match(modified(['file.js']))
|
||||
expect(match.add).toBeFalsy()
|
||||
expect(match.add).toEqual([])
|
||||
})
|
||||
|
||||
test('match added file as added', () => {
|
||||
|
@ -124,17 +131,20 @@ describe('matching specific change status', () => {
|
|||
- added: "**/*"
|
||||
`
|
||||
let filter = new Filter(yaml)
|
||||
const match = filter.match([{status: ChangeStatus.Added, filename: 'file.js'}])
|
||||
expect(match.add).toBeTruthy()
|
||||
const files = [{status: ChangeStatus.Added, filename: 'file.js'}]
|
||||
const match = filter.match(files)
|
||||
expect(match.add).toEqual(files)
|
||||
})
|
||||
|
||||
test('matches when multiple statuses are configured', () => {
|
||||
const yaml = `
|
||||
addOrModify:
|
||||
- added|modified: "**/*"
|
||||
`
|
||||
let filter = new Filter(yaml)
|
||||
const match = filter.match([{status: ChangeStatus.Modified, filename: 'file.js'}])
|
||||
expect(match.addOrModify).toBeTruthy()
|
||||
const files = [{status: ChangeStatus.Modified, filename: 'file.js'}]
|
||||
const match = filter.match(files)
|
||||
expect(match.addOrModify).toEqual(files)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
16
__tests__/shell-escape.test.ts
Normal file
16
__tests__/shell-escape.test.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import shellEscape from '../src/shell-escape'
|
||||
|
||||
test('simple path escaped', () => {
|
||||
expect(shellEscape('file')).toBe("'file'")
|
||||
})
|
||||
|
||||
test('path with space is wrapped with single quotes', () => {
|
||||
expect(shellEscape('file with space')).toBe("'file with space'")
|
||||
})
|
||||
|
||||
test('path with quote is divided into quoted segments and escaped quote', () => {
|
||||
expect(shellEscape("file'with quote")).toBe("'file'\\''with quote'")
|
||||
})
|
||||
test('path with leading quote does not have double quotes at beginning', () => {
|
||||
expect(shellEscape("'file-leading-quote")).toBe("\\''file-leading-quote'")
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue