mirror of
https://github.com/dorny/paths-filter.git
synced 2026-03-10 16:34:28 +00:00
Add tests for all_changed and any_changed outputs (#12)
* test: add coverage for output flags * push
This commit is contained in:
parent
4fad01a9ab
commit
c4baf3b6ea
46
__tests__/outputs.test.ts
Normal file
46
__tests__/outputs.test.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import {ChangeStatus} from '../src/file'
|
||||
import {exportResults} from '../src/main'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
setOutput: jest.fn(),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn(),
|
||||
info: jest.fn()
|
||||
}))
|
||||
|
||||
describe('all_changed and any_changed outputs', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
test('reports true when all filters changed', () => {
|
||||
const results = {
|
||||
src: [{filename: 'src/file.ts', status: ChangeStatus.Modified}],
|
||||
docs: [{filename: 'docs/readme.md', status: ChangeStatus.Added}]
|
||||
}
|
||||
exportResults(results, 'none')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('all_changed', true)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('any_changed', true)
|
||||
})
|
||||
|
||||
test('reports false for all_changed when some filters unchanged', () => {
|
||||
const results = {
|
||||
src: [{filename: 'src/file.ts', status: ChangeStatus.Modified}],
|
||||
docs: []
|
||||
}
|
||||
exportResults(results, 'none')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('all_changed', false)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('any_changed', true)
|
||||
})
|
||||
|
||||
test('reports false for any_changed when no filter changed', () => {
|
||||
const results = {
|
||||
src: [],
|
||||
docs: []
|
||||
}
|
||||
exportResults(results, 'none')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('all_changed', true)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('any_changed', false)
|
||||
})
|
||||
})
|
||||
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -553,6 +553,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = exports.exportResults = void 0;
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
@ -595,6 +596,7 @@ async function run() {
|
||||
core.setFailed(getErrorMessage(error));
|
||||
}
|
||||
}
|
||||
exports.run = run;
|
||||
function isPathInput(text) {
|
||||
return !(text.includes('\n') || text.includes(':'));
|
||||
}
|
||||
@ -782,6 +784,7 @@ function exportResults(results, format) {
|
||||
core.info('Cannot set changes output variable - name already used by filter output');
|
||||
}
|
||||
}
|
||||
exports.exportResults = exportResults;
|
||||
function serializeExport(files, format) {
|
||||
const fileNames = files.map(file => file.filename);
|
||||
switch (format) {
|
||||
@ -805,7 +808,9 @@ function getErrorMessage(error) {
|
||||
return error.message;
|
||||
return String(error);
|
||||
}
|
||||
run();
|
||||
if (require.main === require.cache[eval('__filename')]) {
|
||||
run();
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
@ -228,7 +228,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequestEve
|
||||
}
|
||||
}
|
||||
|
||||
function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
export function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
core.info('Results:')
|
||||
const changes: string[] = []
|
||||
let anyChanged = false
|
||||
@ -295,4 +295,8 @@ function getErrorMessage(error: unknown): string {
|
||||
return String(error)
|
||||
}
|
||||
|
||||
run()
|
||||
if (require.main === module) {
|
||||
run()
|
||||
}
|
||||
|
||||
export {run}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user