-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-haste-map): Make watchman existence check lazy+async (#12675)
- Loading branch information
Showing
5 changed files
with
87 additions
and
22 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
37 changes: 37 additions & 0 deletions
37
packages/jest-haste-map/src/lib/__tests__/isWatchmanInstalled.test.js
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,37 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {execFile} from 'child_process'; | ||
import isWatchmanInstalled from '../isWatchmanInstalled'; | ||
|
||
jest.mock('child_process'); | ||
|
||
describe('isWatchmanInstalled', () => { | ||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('executes watchman --version and returns true on success', async () => { | ||
execFile.mockImplementation((file, args, cb) => { | ||
expect(file).toBe('watchman'); | ||
expect(args).toStrictEqual(['--version']); | ||
cb(null, {stdout: 'v123'}); | ||
}); | ||
expect(await isWatchmanInstalled()).toBe(true); | ||
expect(execFile).toHaveBeenCalledWith( | ||
'watchman', | ||
['--version'], | ||
expect.any(Function), | ||
); | ||
}); | ||
|
||
it('returns false when execFile fails', async () => { | ||
execFile.mockImplementation((file, args, cb) => { | ||
cb(new Error()); | ||
}); | ||
expect(await isWatchmanInstalled()).toBe(false); | ||
expect(execFile).toHaveBeenCalled(); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {execFile} from 'child_process'; | ||
import {promisify} from 'util'; | ||
|
||
export default async function isWatchmanInstalled(): Promise<boolean> { | ||
try { | ||
await promisify(execFile)('watchman', ['--version']); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} |