-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: JounQin <[email protected]>
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]) | ||
}) | ||
}) |