-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathdisk-cache.ts
More file actions
56 lines (46 loc) · 1.77 KB
/
disk-cache.ts
File metadata and controls
56 lines (46 loc) · 1.77 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
import { expectFileNotToExist, expectFileToExist, rimraf, writeFile } from '../../utils/fs';
import { silentNg } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
const defaultCachePath = '.angular/cache';
const overriddenCachePath = '.cache/angular-cli';
export default async function () {
const originalCIValue = process.env['CI'];
// No need to include all applications code to verify disk cache existence.
await writeFile('src/main.ts', 'console.log(1);');
try {
// Should be enabled by default.
process.env['CI'] = '0';
await configureAndRunTest();
// Should not write cache when it's disabled
await configureAndRunTest({ enabled: false });
await expectFileNotToExist(defaultCachePath);
// Should not write cache by default when in CI.
process.env['CI'] = '1';
await configureAndRunTest();
await expectFileNotToExist(defaultCachePath);
// Should write cache when it's enabled and 'environment' is set to 'all' or 'ci'.
await configureAndRunTest({ environment: 'all' });
await expectFileToExist(defaultCachePath);
// Should write cache to custom path when configured.
await configureAndRunTest({ environment: 'ci', path: overriddenCachePath });
await expectFileNotToExist(defaultCachePath);
await expectFileToExist(overriddenCachePath);
} finally {
process.env['CI'] = originalCIValue;
}
}
async function configureAndRunTest(cacheOptions?: {
environment?: 'ci' | 'local' | 'all';
enabled?: boolean;
path?: string;
}): Promise<void> {
await Promise.all([
rimraf(overriddenCachePath),
rimraf(defaultCachePath),
updateJsonFile('angular.json', (config) => {
config.cli ??= {};
config.cli.cache = cacheOptions;
}),
]);
await silentNg('build');
}