-
Notifications
You must be signed in to change notification settings - Fork 945
Expand file tree
/
Copy pathwatchman.test.ts
More file actions
110 lines (89 loc) · 3.33 KB
/
Copy pathwatchman.test.ts
File metadata and controls
110 lines (89 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import execa from 'execa';
import watchman from '../watchman';
import getEnvironmentInfo from '../../envinfo';
import {EnvironmentInfo} from '../../../types';
import {NoopLoader} from '@react-native-community/cli-tools';
import * as common from '../common';
import * as brewInstall from '../../brewInstall';
jest.mock('execa', () => jest.fn());
const logSpy = jest.spyOn(common, 'logManualInstallation');
const {logManualInstallation} = common;
describe('watchman', () => {
let environmentInfo: EnvironmentInfo;
beforeAll(async () => {
environmentInfo = await getEnvironmentInfo();
(execa as unknown as jest.Mock).mockResolvedValue({stdout: ''});
}, 60000);
afterEach(() => {
jest.resetAllMocks();
});
it('returns a message if the watchman is not installed', async () => {
// @ts-ignore - 'Not Found' is a valid return from envinfo but not typed here
environmentInfo.Binaries.Watchman = 'Not Found';
const diagnostics = await watchman.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(true);
});
it('returns false if watchman is installed with v4 version', async () => {
environmentInfo.Binaries.Watchman = {
version: '4.9.0',
path: '/unimportant/path',
};
const diagnostics = await watchman.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(false);
});
it('returns false if watchman is installed with new date-based versions', async () => {
environmentInfo.Binaries.Watchman = {
version: '2020.02.07.00',
path: '/unimportant/path',
};
const diagnostics = await watchman.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(false);
});
it('logs manual installation steps to the screen for the non-macOS fix', async () => {
// Pretend we are linux, all the time
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {
value: 'linux',
});
const loader = new NoopLoader();
await watchman.runAutomaticFix({
loader,
logManualInstallation,
environmentInfo,
});
// Restore the platform before we assert anything that might fail
Object.defineProperty(process, 'platform', {
value: originalPlatform,
});
expect(logSpy).toHaveBeenCalledTimes(1);
});
it('installs watchman on macOS when missing', async () => {
// Pretend we are darwin, all the time
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {
value: 'darwin',
});
const loaderSpy = new NoopLoader();
const loaderSuccessSpy = jest.spyOn(loaderSpy, 'success');
const loaderErrorSpy = jest.spyOn(loaderSpy, 'error');
const brewInstallSpy = jest
.spyOn(brewInstall, 'brewInstall')
.mockImplementation(({loader}) => {
loader.success();
return Promise.resolve();
});
await watchman.runAutomaticFix({
loader: loaderSpy,
logManualInstallation,
environmentInfo,
});
// Restore the platform before we assert anything that might fail
Object.defineProperty(process, 'platform', {
value: originalPlatform,
});
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
expect(logSpy).toHaveBeenCalledTimes(0);
expect(brewInstallSpy).toBeCalledTimes(1);
expect(loaderSuccessSpy).toBeCalledTimes(1);
});
});