|
| 1 | +import execa from 'execa' |
| 2 | +import mock from 'mock-fs' |
| 3 | + |
| 4 | +import prettyQuick from 'pretty-quick' |
| 5 | + |
| 6 | +jest.mock('execa') |
| 7 | + |
| 8 | +afterEach(() => { |
| 9 | + mock.restore() |
| 10 | + jest.clearAllMocks() |
| 11 | +}) |
| 12 | + |
| 13 | +describe('match pattern', () => { |
| 14 | + it('issue #73 #125 - regex grouping (round pattern)', () => { |
| 15 | + const onFoundChangedFiles = jest.fn() |
| 16 | + |
| 17 | + mock({ |
| 18 | + '/.git': {}, |
| 19 | + '/src/apps/hello/foo.js': "export const foo = 'foo'", |
| 20 | + '/src/libs/hello/bar.js': "export const bar = 'bar'", |
| 21 | + '/src/tools/hello/baz.js': "export const baz = 'baz'", |
| 22 | + '/src/should-not-be-included/hello/zoo.js': "export const zoo = 'zoo'", |
| 23 | + }) |
| 24 | + |
| 25 | + // @ts-expect-error -- Need to find a better way to mock this |
| 26 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 27 | + execa.sync.mockImplementation((_command: string, args: string[]) => { |
| 28 | + switch (args[0]) { |
| 29 | + case 'ls-files': { |
| 30 | + return { stdout: '' } |
| 31 | + } |
| 32 | + case 'diff': { |
| 33 | + return args[2] === '--cached' |
| 34 | + ? { stdout: '' } |
| 35 | + : { |
| 36 | + stdout: [ |
| 37 | + '/src/apps/hello/foo.js', |
| 38 | + '/src/libs/hello/bar.js', |
| 39 | + '/src/tools/hello/baz.js', |
| 40 | + '/src/should-not-be-included/hello/zoo.js', |
| 41 | + ].join('\n'), |
| 42 | + } |
| 43 | + } |
| 44 | + default: { |
| 45 | + throw new Error(`unexpected arg0: ${args[0]}`) |
| 46 | + } |
| 47 | + } |
| 48 | + }) |
| 49 | + |
| 50 | + prettyQuick('root', { |
| 51 | + pattern: '**/(apps|libs|tools)/**/*', |
| 52 | + since: 'fox', // This is required to prevent `scm.getSinceRevision` call |
| 53 | + onFoundChangedFiles, |
| 54 | + }) |
| 55 | + |
| 56 | + expect(onFoundChangedFiles).toHaveBeenCalledWith([ |
| 57 | + '/src/apps/hello/foo.js', |
| 58 | + '/src/libs/hello/bar.js', |
| 59 | + '/src/tools/hello/baz.js', |
| 60 | + ]) |
| 61 | + }) |
| 62 | +}) |
0 commit comments