-
Notifications
You must be signed in to change notification settings - Fork 12k
/
ask-analytics-command.ts
53 lines (46 loc) · 1.47 KB
/
ask-analytics-command.ts
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
import { execWithEnv } from '../../utils/process';
import { mockHome } from '../../utils/utils';
const ANALYTICS_PROMPT = /Would you like to share anonymous usage data/;
export default async function () {
// CLI should prompt for analytics permissions.
await mockHome(async () => {
const { stdout } = await execWithEnv(
'ng',
['version'],
{
...process.env,
NG_FORCE_TTY: '1',
NG_FORCE_AUTOCOMPLETE: 'false',
},
'y' /* stdin */,
);
if (!ANALYTICS_PROMPT.test(stdout)) {
throw new Error('CLI did not prompt for analytics permission.');
}
});
// CLI should skip analytics prompt with `NG_CLI_ANALYTICS=false`.
await mockHome(async () => {
const { stdout } = await execWithEnv('ng', ['version'], {
...process.env,
NG_FORCE_TTY: '1',
NG_CLI_ANALYTICS: 'false',
NG_FORCE_AUTOCOMPLETE: 'false',
});
if (ANALYTICS_PROMPT.test(stdout)) {
throw new Error('CLI prompted for analytics permission when it should be forced off.');
}
});
// CLI should skip analytics prompt during `ng update`.
await mockHome(async () => {
const { stdout } = await execWithEnv('ng', ['update', '--help'], {
...process.env,
NG_FORCE_TTY: '1',
NG_FORCE_AUTOCOMPLETE: 'false',
});
if (ANALYTICS_PROMPT.test(stdout)) {
throw new Error(
'CLI prompted for analytics permission during an update where it should not' + ' have.',
);
}
});
}