Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(#73/#125): add glob regex group cases #184

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
])
})
})
Loading