|
| 1 | +import { getIncludePatterns, getExcludePatterns } from '../src/glob-patterns'; |
| 2 | + |
| 3 | +jest.mock('node:fs', () => ({ |
| 4 | + existsSync: jest.fn().mockReturnValue(false), |
| 5 | +})); |
| 6 | + |
| 7 | +describe('glob patterns tests', () => { |
| 8 | + describe('getIncludePatterns tests', () => { |
| 9 | + it('returns a default pattern when neither template nor include are specified', () => { |
| 10 | + const args = { template: '', include: '' }; |
| 11 | + |
| 12 | + const result = getIncludePatterns(args); |
| 13 | + |
| 14 | + expect(result).toEqual(['**/*']); |
| 15 | + }); |
| 16 | + |
| 17 | + it('returns a composite-action pattern when template is composite-action', () => { |
| 18 | + const args = { template: 'composite-action', include: '' }; |
| 19 | + |
| 20 | + const result = getIncludePatterns(args); |
| 21 | + |
| 22 | + expect(result).toEqual(['action.{yml,yaml}', 'LICENSE']); |
| 23 | + }); |
| 24 | + |
| 25 | + it('returns a javascript-action pattern when template is javascript-action', () => { |
| 26 | + const args = { template: 'javascript-action', include: '' }; |
| 27 | + |
| 28 | + const result = getIncludePatterns(args); |
| 29 | + |
| 30 | + expect(result).toEqual(['action.{yml,yaml}', 'dist/**', 'LICENSE']); |
| 31 | + }); |
| 32 | + |
| 33 | + it('throws an error when an invalid template is specified', () => { |
| 34 | + const args = { template: 'invalid-template', include: '' }; |
| 35 | + |
| 36 | + expect(() => getIncludePatterns(args)).toThrowError("'invalid-template' is not a valid template"); |
| 37 | + }); |
| 38 | + |
| 39 | + it('returns a list of patterns when include is specified', () => { |
| 40 | + const args = { |
| 41 | + template: '', |
| 42 | + include: ` |
| 43 | + README.md |
| 44 | + LICENSE |
| 45 | + |
| 46 | + src/** |
| 47 | + dist/ |
| 48 | +
|
| 49 | + !src/*.ts`, |
| 50 | + }; |
| 51 | + |
| 52 | + const result = getIncludePatterns(args); |
| 53 | + |
| 54 | + expect(result).toEqual([ |
| 55 | + 'README.md', |
| 56 | + 'LICENSE', |
| 57 | + 'src/**', |
| 58 | + 'dist/**', |
| 59 | + '!src/*.ts', |
| 60 | + ]); |
| 61 | + }); |
| 62 | + |
| 63 | + it('extends the template with include patterns when both are specified', () => { |
| 64 | + const args = { |
| 65 | + template: 'javascript-action', |
| 66 | + include: ` |
| 67 | + README.md |
| 68 | + !src/*.ts`, |
| 69 | + }; |
| 70 | + |
| 71 | + const result = getIncludePatterns(args); |
| 72 | + |
| 73 | + expect(result).toEqual([ |
| 74 | + 'action.{yml,yaml}', |
| 75 | + 'dist/**', |
| 76 | + 'LICENSE', |
| 77 | + 'README.md', |
| 78 | + '!src/*.ts', |
| 79 | + ]); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('getExcludePatterns tests', () => { |
| 84 | + it('returns an empty array when no exclude is specified', async () => { |
| 85 | + const exclude = ''; |
| 86 | + |
| 87 | + const result = await getExcludePatterns(exclude); |
| 88 | + |
| 89 | + expect(result).toEqual([]); |
| 90 | + }); |
| 91 | + |
| 92 | + it('returns a list of patterns when exclude is specified', async () => { |
| 93 | + const exclude = ` |
| 94 | + README.md |
| 95 | + LICENSE |
| 96 | + |
| 97 | + src/** |
| 98 | + dist/ |
| 99 | +
|
| 100 | + !src/*.ts`; |
| 101 | + |
| 102 | + const result = await getExcludePatterns(exclude); |
| 103 | + |
| 104 | + expect(result).toEqual([ |
| 105 | + 'README.md', |
| 106 | + 'LICENSE', |
| 107 | + 'src/**', |
| 108 | + 'dist/**', |
| 109 | + '!src/*.ts', |
| 110 | + ]); |
| 111 | + }); |
| 112 | + }); |
| 113 | +}); |
0 commit comments