Files
labeler/__tests__/labeler.test.ts
T

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-03-18 17:10:25 -04:00
import {checkMatchConfigs, MatchConfig, toMatchConfig} 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
});
});
2023-03-18 17:10:25 -04:00
describe('toMatchConfig', () => {
describe('when all expected config options are present', () => {
const config = {
'changed-files': [{any: ['testing-any']}, {all: ['testing-all']}],
'head-branch': ['testing-head'],
'base-branch': ['testing-base']
};
const expected: MatchConfig = {
changedFiles: {
all: ['testing-all'],
any: ['testing-any']
},
headBranch: ['testing-head'],
baseBranch: ['testing-base']
};
2023-03-18 17:10:25 -04:00
it('returns a MatchConfig object with all options', () => {
const result = toMatchConfig(config);
expect(result).toEqual(expected);
2023-03-18 17:10:25 -04:00
});
describe('and there are also unexpected options present', () => {
config['test-test'] = 'testing';
it('does not include the unexpected items in the returned MatchConfig object', () => {
const result = toMatchConfig(config);
expect(result).toEqual(expected);
2023-03-18 17:10:25 -04:00
});
});
});
});
2021-06-03 16:15:47 -04:00
describe('checkMatchConfigs', () => {
2023-03-18 17:10:25 -04:00
const matchConfig: MatchConfig[] = [{changedFiles: {any: ['*.txt']}}];
it('returns true when our pattern does match changed files', () => {
const changedFiles = ['foo.txt', 'bar.txt'];
const result = checkMatchConfigs(changedFiles, matchConfig);
2021-06-03 16:15:47 -04:00
expect(result).toBeTruthy();
});
it('returns false when our pattern does not match changed files', () => {
const changedFiles = ['foo.docx'];
const result = checkMatchConfigs(changedFiles, matchConfig);
2021-06-03 16:15:47 -04:00
expect(result).toBeFalsy();
});
});