-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@formatjs/cli): switch from glob to fast-glob
- Loading branch information
Showing
27 changed files
with
122 additions
and
99 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,63 +1,50 @@ | ||
import cliMain from '../../src/cli'; | ||
const glob = require('glob'); | ||
const glob = require('fast-glob'); | ||
const ts = require('typescript'); | ||
const transpileModule = jest.spyOn(ts, 'transpileModule'); | ||
// Commander.js will call this. | ||
jest.spyOn(process, 'exit').mockImplementation((() => null) as any); | ||
|
||
jest.mock('glob', () => ({ | ||
sync: jest.fn((p: string) => [p]), | ||
})); | ||
jest.spyOn(glob, 'sync').mockImplementation(p => [p]); | ||
|
||
jest.mock('fs-extra', () => ({ | ||
outputJSONSync: () => Promise.resolve(), | ||
readFile: () => Promise.resolve(';'), | ||
})); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('it passes camelCase-converted arguments to typescript API', async () => { | ||
await cliMain([ | ||
'node', | ||
'path/to/formatjs-cli', | ||
'extract', | ||
'--extract-source-location', | ||
'--remove-default-message', | ||
'--extract-from-format-message-call', | ||
'--throws', | ||
'--additional-component-names', | ||
'Foo,Bar', | ||
'--ignore=file3.ts', | ||
'file1.js', | ||
'file2.tsx', | ||
]); | ||
|
||
expect(transpileModule.mock.calls).toMatchSnapshot(); | ||
describe('unit', function () { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('it passes camelCase-converted arguments to typescript API', async () => { | ||
await cliMain([ | ||
'node', | ||
'path/to/formatjs-cli', | ||
'extract', | ||
'--extract-source-location', | ||
'--remove-default-message', | ||
'--extract-from-format-message-call', | ||
'--throws', | ||
'--additional-component-names', | ||
'Foo,Bar', | ||
'--ignore=file3.ts', | ||
'file1.js', | ||
'file2.tsx', | ||
]); | ||
|
||
expect(transpileModule.mock.calls).toMatchSnapshot(); | ||
}); | ||
|
||
it('does not read from stdin when the glob pattern does NOT match anything', async () => { | ||
// Does not match anything | ||
jest.spyOn(glob, 'sync').mockImplementation(() => []); | ||
// This should not hang | ||
await cliMain([ | ||
'node', | ||
'path/to/formatjs-cli', | ||
'extract', | ||
'*.doesnotexist', | ||
]); | ||
expect(transpileModule).not.toHaveBeenCalled(); | ||
}, 500); // 500ms timeout | ||
}); | ||
|
||
test('it passes ignore argument to glob sync', () => { | ||
cliMain([ | ||
'node', | ||
'path/to/formatjs-cli', | ||
'extract', | ||
'--ignore=ignore-1.ts', | ||
'include-1.js', | ||
]); | ||
|
||
expect(glob.sync).toHaveBeenCalled(); | ||
expect(glob.sync).toHaveBeenNthCalledWith( | ||
1, | ||
'include-1.js', | ||
expect.objectContaining({ignore: 'ignore-1.ts'}) | ||
); | ||
}); | ||
|
||
test('does not read from stdin when the glob pattern does NOT match anything', async () => { | ||
// Does not match anything | ||
jest.spyOn(glob, 'sync').mockImplementation(() => []); | ||
// This should not hang | ||
await cliMain(['node', 'path/to/formatjs-cli', 'extract', '*.doesnotexist']); | ||
expect(transpileModule).not.toHaveBeenCalled(); | ||
}, 500); // 500ms timeout |
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.