mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 12:37:48 +00:00
Add a bunch more tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
getBranchName,
|
getBranchName,
|
||||||
checkAnyBranch,
|
checkAnyBranch,
|
||||||
|
checkAllBranch,
|
||||||
toBranchMatchConfig,
|
toBranchMatchConfig,
|
||||||
BranchMatchConfig
|
BranchMatchConfig
|
||||||
} from '../src/branch';
|
} from '../src/branch';
|
||||||
@@ -25,6 +26,65 @@ describe('getBranchName', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('checkAllBranch', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
github.context.payload.pull_request!.head = {
|
||||||
|
ref: 'test/feature/123'
|
||||||
|
};
|
||||||
|
github.context.payload.pull_request!.base = {
|
||||||
|
ref: 'main'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when a single pattern is provided', () => {
|
||||||
|
describe('and the pattern matches the head branch', () => {
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkAllBranch(['^test'], 'head');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and the pattern does not match the head branch', () => {
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkAllBranch(['^feature/'], 'head');
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when multiple patterns are provided', () => {
|
||||||
|
describe('and not all patterns matched', () => {
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkAllBranch(['^test/', '^feature/'], 'head');
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and all patterns match', () => {
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkAllBranch(['^test/', '/feature/'], 'head');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and no patterns match', () => {
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkAllBranch(['^feature/', '/test$'], 'head');
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the branch to check is specified as the base branch', () => {
|
||||||
|
describe('and the pattern matches the base branch', () => {
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkAllBranch(['^main$'], 'base');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('checkAnyBranch', () => {
|
describe('checkAnyBranch', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
github.context.payload.pull_request!.head = {
|
github.context.payload.pull_request!.head = {
|
||||||
|
|||||||
@@ -88,19 +88,53 @@ describe('toMatchConfig', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('checkMatchConfigs', () => {
|
describe('checkMatchConfigs', () => {
|
||||||
const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.txt']}]}];
|
describe('when a single match config is provided', () => {
|
||||||
|
const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.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);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when our pattern does not match changed files', () => {
|
||||||
|
const changedFiles = ['foo.docx'];
|
||||||
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
|
||||||
|
expect(result).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when either the branch or changed files patter matches', () => {
|
||||||
|
const matchConfig: MatchConfig[] = [
|
||||||
|
{any: [{changedFiles: ['*.txt']}, {headBranch: ['some-branch']}]}
|
||||||
|
];
|
||||||
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false when our pattern does not match changed files', () => {
|
describe('when multiple MatchConfigs are supplied', () => {
|
||||||
const changedFiles = ['foo.docx'];
|
const matchConfig: MatchConfig[] = [
|
||||||
const result = checkMatchConfigs(changedFiles, matchConfig);
|
{any: [{changedFiles: ['*.txt']}]},
|
||||||
|
{any: [{headBranch: ['some-branch']}]}
|
||||||
|
];
|
||||||
|
const changedFiles = ['foo.txt', 'bar.md'];
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
it('returns false when only one config matches', () => {
|
||||||
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when only both config matches', () => {
|
||||||
|
const matchConfig: MatchConfig[] = [
|
||||||
|
{any: [{changedFiles: ['*.txt']}]},
|
||||||
|
{any: [{headBranch: ['head-branch']}]}
|
||||||
|
];
|
||||||
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user