Skip to content

Commit 1536657

Browse files
SukkaWJounQin
andauthored
test(#73/#125): add glob regex group cases (#184)
Co-authored-by: JounQin <[email protected]>
1 parent 71aab56 commit 1536657

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/pattern.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)