-
Notifications
You must be signed in to change notification settings - Fork 417
/
changedFiles.test.ts
113 lines (92 loc) · 3.18 KB
/
changedFiles.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import {
ChangedFilesMatchConfig,
checkAllChangedFiles,
checkAnyChangedFiles,
toChangedFilesMatchConfig
} from '../src/changedFiles';
import {PrFileType} from '../src/labeler';
jest.mock('@actions/core');
jest.mock('@actions/github');
describe('checkAllChangedFiles', () => {
const changedFiles: PrFileType[] = [
{name: 'foo.txt', size: 6},
{name: 'bar.txt', size: 20}
];
describe('when the globs match every file that has been changed', () => {
const globs = ['*.txt'];
it('returns true', () => {
const result = checkAllChangedFiles(changedFiles, globs);
expect(result).toBe(true);
});
});
describe(`when the globs don't match every file that has changed`, () => {
const globs = ['foo.txt'];
it('returns false', () => {
const result = checkAllChangedFiles(changedFiles, globs);
expect(result).toBe(false);
});
});
});
describe('checkAnyChangedFiles', () => {
const changedFiles: PrFileType[] = [
{name: 'foo.txt', size: 6},
{name: 'bar.txt', size: 20}
];
describe('when any glob matches any of the files that have changed', () => {
const globs = ['*.txt', '*.md'];
it('returns true', () => {
const result = checkAnyChangedFiles(changedFiles, globs);
expect(result).toBe(true);
});
});
describe('when none of the globs match any files that have changed', () => {
const globs = ['*.md'];
it('returns false', () => {
const result = checkAnyChangedFiles(changedFiles, globs);
expect(result).toBe(false);
});
});
});
describe('toChangedFilesMatchConfig', () => {
describe(`when there is no 'changed-files' key in the config`, () => {
const config = {'head-branch': 'test'};
it('returns an empty object', () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({});
});
});
describe(`when there is a 'changed-files' key in the config`, () => {
describe('and the value is an array of strings', () => {
const config = {'changed-files': ['testing']};
it('sets the value in the config object', () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: ['testing']
});
});
});
describe('and the value is a string', () => {
const config = {'changed-files': 'testing'};
it(`sets the string as an array in the config object`, () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({
changedFiles: ['testing']
});
});
});
describe('but the value is an empty string', () => {
const config = {'changed-files': ''};
it(`returns an empty object`, () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({});
});
});
describe('but the value is an empty array', () => {
const config = {'changed-files': []};
it(`returns an empty object`, () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({});
});
});
});
});