Files
labeler/__tests__/labeler.test.ts
T

34 lines
987 B
TypeScript
Raw Normal View History

2023-01-29 15:09:06 -05:00
import {checkGlobs, MatchConfig} from '../src/labeler';
2021-06-03 16:15:47 -04:00
import * as core from '@actions/core';
2021-06-03 16:15:47 -04:00
jest.mock('@actions/core');
2021-06-03 16:15:47 -04:00
beforeAll(() => {
jest.spyOn(core, 'getInput').mockImplementation((name, options) => {
return jest.requireActual('@actions/core').getInput(name, options);
2021-06-03 16:15:47 -04:00
});
});
// I have to double cast here as this is what the output from js-yaml looks like which then gets
// transformed in toMatchConfig
2023-01-29 15:09:06 -05:00
const matchConfig = [
{'changed-files': [{any: ['*.txt']}]}
] as unknown as MatchConfig[];
2021-06-03 16:15:47 -04:00
describe('checkGlobs', () => {
it('returns true when our pattern does match changed files', () => {
const changedFiles = ['foo.txt', 'bar.txt'];
2021-06-03 16:15:47 -04:00
const result = checkGlobs(changedFiles, matchConfig);
expect(result).toBeTruthy();
});
it('returns false when our pattern does not match changed files', () => {
const changedFiles = ['foo.docx'];
2021-06-03 16:15:47 -04:00
const result = checkGlobs(changedFiles, matchConfig);
expect(result).toBeFalsy();
});
});