Skip to content

Commit

Permalink
Fix Windows platform detection, Watchman detection in tests
Browse files Browse the repository at this point in the history
Summary:
While checking some `metro-file-map` behaviour on Windows I noticed the Watchman detection we use in integration tests was all wrong :)
 - `os.platform()` returns `win32` on Windows, not `windows`.
 - `where` works in a command prompt but not PowerShell - there it's usually an alias for `Where-Object`. `where.exe` works on both.
 - `where.exe` prints "INFO: Could not find files for the given pattern(s)" to stderr on no match. Use `/Q` for silent running - the exit code is all we need.

Reviewed By: motiz88

Differential Revision: D42266748

fbshipit-source-id: 4494cd39dd94da7dc17442264a3828a35aaf9c30
  • Loading branch information
robhogan authored and facebook-github-bot committed Dec 30, 2022
1 parent 216c5c4 commit 2d60a02
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import type {CrawlerOptions, FileData} from '../../flow-types';
// and will tend to exercise our Watchman tests whenever possible.
const isWatchmanOnPath = () => {
try {
execSync(os.platform() === 'windows' ? 'where watchman' : 'which watchman');
execSync(
os.platform() === 'win32' ? 'where.exe /Q watchman' : 'which watchman',
);
return true;
} catch {
return false;
Expand Down
4 changes: 3 additions & 1 deletion packages/metro-file-map/src/watchers/__tests__/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const {mkdtemp, writeFile} = fsPromises;
// and will tend to exercise our Watchman tests whenever possible.
const isWatchmanOnPath = () => {
try {
execSync(os.platform() === 'windows' ? 'where watchman' : 'which watchman');
execSync(
os.platform() === 'win32' ? 'where.exe /Q watchman' : 'which watchman',
);
return true;
} catch {
return false;
Expand Down

0 comments on commit 2d60a02

Please sign in to comment.