mirror of
https://github.com/dorny/paths-filter.git
synced 2026-03-10 16:34:28 +00:00
tests
This commit is contained in:
parent
40e5598aa5
commit
40c5546f56
@ -58,6 +58,8 @@ don't allow this because they don't work on a level of individual jobs or steps.
|
||||
run: ...
|
||||
```
|
||||
|
||||
For a more complete example, see [sample-filters.yml](./sample-filters.yml).
|
||||
|
||||
For more scenarios see [examples](#examples) section.
|
||||
|
||||
## Notes
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import {csvEscape} from '../src/list-format/csv-escape'
|
||||
|
||||
describe('csvEscape() backslash escapes every character except subset of definitely safe characters', () => {
|
||||
test('empty string is returned unchanged', () => {
|
||||
expect(csvEscape('')).toBe('')
|
||||
})
|
||||
test('simple filename should not be modified', () => {
|
||||
expect(csvEscape('file.txt')).toBe('file.txt')
|
||||
})
|
||||
|
||||
42
__tests__/export-format.test.ts
Normal file
42
__tests__/export-format.test.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import {ChangeStatus} from '../src/file'
|
||||
import {exportResults} from '../src/main'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
info: jest.fn(),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn(),
|
||||
setOutput: jest.fn()
|
||||
}))
|
||||
|
||||
describe('exportResults file listing formats', () => {
|
||||
const files = [
|
||||
{filename: 'simple.txt', status: ChangeStatus.Modified},
|
||||
{filename: 'file with space.txt', status: ChangeStatus.Added}
|
||||
]
|
||||
const results = {sample: files}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
test('exports csv formatted list', () => {
|
||||
exportResults(results, 'csv')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('sample_files', 'simple.txt,"file with space.txt"')
|
||||
})
|
||||
|
||||
test('exports json formatted list', () => {
|
||||
exportResults(results, 'json')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('sample_files', JSON.stringify(['simple.txt', 'file with space.txt']))
|
||||
})
|
||||
|
||||
test('exports shell escaped list', () => {
|
||||
exportResults(results, 'shell')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('sample_files', "simple.txt 'file with space.txt'")
|
||||
})
|
||||
|
||||
test('exports escape formatted list', () => {
|
||||
exportResults(results, 'escape')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('sample_files', 'simple.txt file\\ with\\ space.txt')
|
||||
})
|
||||
})
|
||||
2
__tests__/fixtures/sample-filter.yml
Normal file
2
__tests__/fixtures/sample-filter.yml
Normal file
@ -0,0 +1,2 @@
|
||||
sample:
|
||||
- 'src/**/*.ts'
|
||||
@ -14,6 +14,17 @@ describe('parsing output of the git diff command', () => {
|
||||
expect(files[2].filename).toBe('src/main.ts')
|
||||
expect(files[2].status).toBe(ChangeStatus.Deleted)
|
||||
})
|
||||
|
||||
test('parseGitDiffOutput handles copied, renamed and unmerged statuses', async () => {
|
||||
const files = git.parseGitDiffOutput(
|
||||
'C\u0000src/copied.ts\u0000' + 'R\u0000src/renamed.ts\u0000' + 'U\u0000src/conflict.ts\u0000'
|
||||
)
|
||||
expect(files).toEqual([
|
||||
{filename: 'src/copied.ts', status: ChangeStatus.Copied},
|
||||
{filename: 'src/renamed.ts', status: ChangeStatus.Renamed},
|
||||
{filename: 'src/conflict.ts', status: ChangeStatus.Unmerged}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('git utility function tests (those not invoking git)', () => {
|
||||
|
||||
15
__tests__/predicate-quantifier.test.ts
Normal file
15
__tests__/predicate-quantifier.test.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {isPredicateQuantifier, SUPPORTED_PREDICATE_QUANTIFIERS} from '../src/filter'
|
||||
|
||||
describe('isPredicateQuantifier', () => {
|
||||
test('returns true for supported values', () => {
|
||||
for (const value of SUPPORTED_PREDICATE_QUANTIFIERS) {
|
||||
expect(isPredicateQuantifier(value)).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('returns false for unsupported values including sample', () => {
|
||||
expect(isPredicateQuantifier('sample')).toBe(false)
|
||||
expect(isPredicateQuantifier('')).toBe(false)
|
||||
expect(isPredicateQuantifier(undefined)).toBe(false)
|
||||
})
|
||||
})
|
||||
15
__tests__/sample-config.test.ts
Normal file
15
__tests__/sample-config.test.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import {Filter} from '../src/filter'
|
||||
import {ChangeStatus} from '../src/file'
|
||||
|
||||
describe('sample configuration file', () => {
|
||||
test('parses filter rules from sample file', () => {
|
||||
const yamlPath = path.join(__dirname, 'fixtures', 'sample-filter.yml')
|
||||
const yaml = fs.readFileSync(yamlPath, 'utf8')
|
||||
const filter = new Filter(yaml)
|
||||
const files = [{filename: 'src/index.ts', status: ChangeStatus.Modified}]
|
||||
const match = filter.match(files)
|
||||
expect(match.sample).toEqual(files)
|
||||
})
|
||||
})
|
||||
26
__tests__/sample.test.ts
Normal file
26
__tests__/sample.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import {Filter} from '../src/filter'
|
||||
import {ChangeStatus} from '../src/file'
|
||||
|
||||
describe('sample filter usage', () => {
|
||||
test('matches files in sample folder', () => {
|
||||
const yaml = `
|
||||
sample:
|
||||
- sample/**
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = [{filename: 'sample/example.ts', status: ChangeStatus.Modified}]
|
||||
const match = filter.match(files)
|
||||
expect(match.sample).toEqual(files)
|
||||
})
|
||||
|
||||
test('does not match files outside sample folder', () => {
|
||||
const yaml = `
|
||||
sample:
|
||||
- sample/**
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = [{filename: 'other/example.ts', status: ChangeStatus.Modified}]
|
||||
const match = filter.match(files)
|
||||
expect(match.sample).toEqual([])
|
||||
})
|
||||
})
|
||||
@ -1,6 +1,9 @@
|
||||
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape'
|
||||
|
||||
describe('escape() backslash escapes every character except subset of definitely safe characters', () => {
|
||||
test('empty string is returned unchanged', () => {
|
||||
expect(backslashEscape('')).toBe('')
|
||||
})
|
||||
test('simple filename should not be modified', () => {
|
||||
expect(backslashEscape('file.txt')).toBe('file.txt')
|
||||
})
|
||||
|
||||
11
sample-filters.yml
Normal file
11
sample-filters.yml
Normal file
@ -0,0 +1,11 @@
|
||||
# Sample filters configuration for paths-filter action
|
||||
# Demonstrates basic usage of filters and change status qualifiers
|
||||
shared: &shared
|
||||
- common/**
|
||||
- config/**
|
||||
backend:
|
||||
- *shared
|
||||
- src/backend/**
|
||||
docs:
|
||||
- added: docs/**
|
||||
- modified: README.md
|
||||
Loading…
Reference in New Issue
Block a user