mirror of
https://gitea.com/actions/dorny-paths-filter.git
synced 2024-11-23 18:23:41 +08:00
improve tests
This commit is contained in:
parent
9f68be011c
commit
a87ec7a8d9
51
__tests__/export.test.ts
Normal file
51
__tests__/export.test.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Filter} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
import {exportResults} from '../src/main'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
info: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
startGroup: jest.fn(),
|
||||
setOutput: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}))
|
||||
|
||||
describe('set output post filtering', () => {
|
||||
test('correctly sets output', () => {
|
||||
const yaml = `
|
||||
backend:
|
||||
- '!(**/*.tsx|**/*.less)'
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
exportResults(match, 'none')
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('changes', '["backend"]')
|
||||
})
|
||||
test('correctly filters out shared from output', () => {
|
||||
const yaml = `
|
||||
shared: &shared
|
||||
- common/**/*
|
||||
- config/**/*
|
||||
src:
|
||||
- *shared
|
||||
- src/**/*
|
||||
backend:
|
||||
- '!(**/*.tsx|**/*.less)'
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
exportResults(match, 'none')
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src","backend"]')
|
||||
})
|
||||
})
|
||||
|
||||
function modified(paths: string[]): File[] {
|
||||
return paths.map(filename => {
|
||||
return {filename, status: ChangeStatus.Modified}
|
||||
})
|
||||
}
|
@ -1,15 +1,5 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
import {exportResults} from '../src/main'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
info: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
startGroup: jest.fn(),
|
||||
setOutput: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}))
|
||||
|
||||
describe('yaml filter parsing tests', () => {
|
||||
test('throws if yaml is not a dictionary', () => {
|
||||
@ -170,9 +160,6 @@ describe('matching tests', () => {
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
exportResults(match, 'none')
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src"]')
|
||||
expect(match.src).toEqual(files)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user