-
Notifications
You must be signed in to change notification settings - Fork 935
Expand file tree
/
Copy pathclean.test.ts
More file actions
82 lines (65 loc) · 1.92 KB
/
clean.test.ts
File metadata and controls
82 lines (65 loc) · 1.92 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
import {execa} from 'execa';
import os from 'os';
import prompts from 'prompts';
import {clean, cleanDir} from '../clean';
import {cleanup, getTempDirectory, writeFiles} from '../../../../jest/helpers';
import fs from 'fs';
const DIR = getTempDirectory('temp-cache');
jest.mock('execa', () => ({
execa: jest.fn(),
}));
jest.mock('prompts', () => jest.fn());
afterEach(() => {
cleanup(DIR);
});
describe('clean', () => {
const mockConfig: any = {};
afterEach(() => {
jest.resetAllMocks();
});
it('throws if project root is not set', async () => {
await expect(clean([], mockConfig, mockConfig)).rejects.toThrow();
});
it('prompts if `--include` is omitted', async () => {
(prompts as jest.MockedFunction<typeof prompts>).mockReturnValue(
Promise.resolve({
cache: [],
}),
);
await clean([], mockConfig, {include: '', projectRoot: process.cwd()});
expect(execa).not.toBeCalled();
expect(prompts).toBeCalled();
});
it('stops Watchman and clears out caches', async () => {
await clean([], mockConfig, {
include: 'watchman',
projectRoot: process.cwd(),
});
expect(prompts).not.toBeCalled();
expect(execa).toBeCalledWith(
os.platform() === 'win32' ? 'tskill' : 'killall',
['watchman'],
expect.anything(),
);
expect(execa).toBeCalledWith(
'watchman',
['watch-del-all'],
expect.anything(),
);
});
it('should remove paths defined with patterns', async () => {
writeFiles(DIR, {
'metro-cache/cache.txt': 'cache file',
'metro-zxcvbnm/cache.txt': 'cache file',
});
await cleanDir(`${DIR}/metro-*`);
expect(fs.readdirSync(DIR)).toEqual([]);
});
it('should remove paths defined without patterns', async () => {
writeFiles(DIR, {
'metro-cache/cache.txt': 'cache file',
});
await cleanDir(`${DIR}/metro-cache`);
expect(fs.readdirSync(DIR)).toEqual([]);
});
});