improve tests

This commit is contained in:
Lucas Yarid 2024-05-17 11:45:06 +02:00
parent 9f68be011c
commit a87ec7a8d9
2 changed files with 51 additions and 13 deletions

51
__tests__/export.test.ts Normal file
View 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}
})
}

View File

@ -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)
})
})