Skip to content

Commit

Permalink
test(#73/#125): add glob regex group cases (#184)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <[email protected]>
  • Loading branch information
SukkaW and JounQin authored Jan 17, 2024
1 parent 71aab56 commit 1536657
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/pattern.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import execa from 'execa'
import mock from 'mock-fs'

import prettyQuick from 'pretty-quick'

jest.mock('execa')

afterEach(() => {
mock.restore()
jest.clearAllMocks()
})

describe('match pattern', () => {
it('issue #73 #125 - regex grouping (round pattern)', () => {
const onFoundChangedFiles = jest.fn()

mock({
'/.git': {},
'/src/apps/hello/foo.js': "export const foo = 'foo'",
'/src/libs/hello/bar.js': "export const bar = 'bar'",
'/src/tools/hello/baz.js': "export const baz = 'baz'",
'/src/should-not-be-included/hello/zoo.js': "export const zoo = 'zoo'",
})

// @ts-expect-error -- Need to find a better way to mock this
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
execa.sync.mockImplementation((_command: string, args: string[]) => {
switch (args[0]) {
case 'ls-files': {
return { stdout: '' }
}
case 'diff': {
return args[2] === '--cached'
? { stdout: '' }
: {
stdout: [
'/src/apps/hello/foo.js',
'/src/libs/hello/bar.js',
'/src/tools/hello/baz.js',
'/src/should-not-be-included/hello/zoo.js',
].join('\n'),
}
}
default: {
throw new Error(`unexpected arg0: ${args[0]}`)
}
}
})

prettyQuick('root', {
pattern: '**/(apps|libs|tools)/**/*',
since: 'fox', // This is required to prevent `scm.getSinceRevision` call
onFoundChangedFiles,
})

expect(onFoundChangedFiles).toHaveBeenCalledWith([
'/src/apps/hello/foo.js',
'/src/libs/hello/bar.js',
'/src/tools/hello/baz.js',
])
})
})

0 comments on commit 1536657

Please sign in to comment.