2022-12-19 17:09:22 +01:00
|
|
|
import {checkGlobs} from '../src/labeler';
|
2021-06-03 16:15:47 -04:00
|
|
|
|
2022-12-19 17:09:22 +01:00
|
|
|
import * as core from '@actions/core';
|
2021-06-03 16:15:47 -04:00
|
|
|
|
2022-12-19 17:09:22 +01:00
|
|
|
jest.mock('@actions/core');
|
2021-06-03 16:15:47 -04:00
|
|
|
|
|
|
|
|
beforeAll(() => {
|
2022-12-19 17:09:22 +01:00
|
|
|
jest.spyOn(core, 'getInput').mockImplementation((name, options) => {
|
|
|
|
|
return jest.requireActual('@actions/core').getInput(name, options);
|
2021-06-03 16:15:47 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-19 17:09:22 +01:00
|
|
|
const matchConfig = [{any: ['*.txt']}];
|
2021-06-03 16:15:47 -04:00
|
|
|
|
2022-12-19 17:09:22 +01:00
|
|
|
describe('checkGlobs', () => {
|
|
|
|
|
it('returns true when our pattern does match changed files', () => {
|
|
|
|
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
2022-02-04 13:26:54 +00:00
|
|
|
const result = checkGlobs(changedFiles, matchConfig, false);
|
2021-06-03 16:15:47 -04:00
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-19 17:09:22 +01:00
|
|
|
it('returns false when our pattern does not match changed files', () => {
|
|
|
|
|
const changedFiles = ['foo.docx'];
|
2022-02-04 13:26:54 +00:00
|
|
|
const result = checkGlobs(changedFiles, matchConfig, false);
|
2021-06-03 16:15:47 -04:00
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
|
});
|
2022-02-04 13:26:54 +00:00
|
|
|
|
2023-01-16 17:36:24 +00:00
|
|
|
it('returns false for a file starting with dot if `dot` option is false', () => {
|
|
|
|
|
const changedFiles = ['.foo.txt'];
|
2022-02-04 13:26:54 +00:00
|
|
|
const result = checkGlobs(changedFiles, matchConfig, false);
|
|
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-16 17:36:24 +00:00
|
|
|
it('returns true for a file starting with dot if `dot` option is true', () => {
|
|
|
|
|
const changedFiles = ['.foo.txt'];
|
2022-02-04 13:26:54 +00:00
|
|
|
const result = checkGlobs(changedFiles, matchConfig, true);
|
|
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
|
});
|
2021-06-03 16:15:47 -04:00
|
|
|
});
|