mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 12:37:48 +00:00
Add unit tests for toMatchConfig
This commit is contained in:
@@ -87,6 +87,7 @@ describe('checkBranch', () => {
|
|||||||
describe('toBranchMatchConfig', () => {
|
describe('toBranchMatchConfig', () => {
|
||||||
describe('when there are no branch keys in the config', () => {
|
describe('when there are no branch keys in the config', () => {
|
||||||
const config = {'changed-files': [{any: ['testing']}]};
|
const config = {'changed-files': [{any: ['testing']}]};
|
||||||
|
|
||||||
it('returns an empty object', () => {
|
it('returns an empty object', () => {
|
||||||
const result = toBranchMatchConfig(config);
|
const result = toBranchMatchConfig(config);
|
||||||
expect(result).toMatchObject({});
|
expect(result).toMatchObject({});
|
||||||
@@ -95,6 +96,7 @@ describe('toBranchMatchConfig', () => {
|
|||||||
|
|
||||||
describe('when the config contains a head-branch option', () => {
|
describe('when the config contains a head-branch option', () => {
|
||||||
const config = {'head-branch': ['testing']};
|
const config = {'head-branch': ['testing']};
|
||||||
|
|
||||||
it('sets headBranch in the matchConfig', () => {
|
it('sets headBranch in the matchConfig', () => {
|
||||||
const result = toBranchMatchConfig(config);
|
const result = toBranchMatchConfig(config);
|
||||||
expect(result).toMatchObject<BranchMatchConfig>({
|
expect(result).toMatchObject<BranchMatchConfig>({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {checkMatchConfigs, MatchConfig} from '../src/labeler';
|
import {checkMatchConfigs, MatchConfig, toMatchConfig} from '../src/labeler';
|
||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
@@ -10,9 +10,47 @@ beforeAll(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const matchConfig: MatchConfig[] = [{changedFiles: {any: ['*.txt']}}];
|
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']
|
||||||
|
};
|
||||||
|
|
||||||
|
it('returns a MatchConfig object with all options', () => {
|
||||||
|
const result = toMatchConfig(config);
|
||||||
|
expect(result).toMatchObject<MatchConfig>({
|
||||||
|
changedFiles: {
|
||||||
|
all: ['testing-all'],
|
||||||
|
any: ['testing-any']
|
||||||
|
},
|
||||||
|
headBranch: ['testing-head'],
|
||||||
|
baseBranch: ['testing-base']
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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).toMatchObject<MatchConfig>({
|
||||||
|
changedFiles: {
|
||||||
|
all: ['testing-all'],
|
||||||
|
any: ['testing-any']
|
||||||
|
},
|
||||||
|
headBranch: ['testing-head'],
|
||||||
|
baseBranch: ['testing-base']
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('checkMatchConfigs', () => {
|
describe('checkMatchConfigs', () => {
|
||||||
|
const matchConfig: MatchConfig[] = [{changedFiles: {any: ['*.txt']}}];
|
||||||
|
|
||||||
it('returns true when our pattern does match changed files', () => {
|
it('returns true when our pattern does match changed files', () => {
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
const result = checkMatchConfigs(changedFiles, matchConfig);
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ function getLabelConfigMapFromObject(
|
|||||||
return labelMap;
|
return labelMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toMatchConfig(config: any): MatchConfig {
|
export function toMatchConfig(config: any): MatchConfig {
|
||||||
const changedFilesConfig = toChangedFilesMatchConfig(config);
|
const changedFilesConfig = toChangedFilesMatchConfig(config);
|
||||||
const branchConfig = toBranchMatchConfig(config);
|
const branchConfig = toBranchMatchConfig(config);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user