-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
54 lines (42 loc) · 1.44 KB
/
test.js
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
/* eslint xo/no-process-exit: 0 */
import test from 'ava';
const path = require('path');
const execa = require('execa');
const fs = require('fs-extra');
const pathExists = require('path-exists');
const tempfile = require('tempfile');
const cliLocation = './cli.js';
function exists(t, files) {
[].concat(files).forEach(file => t.true(pathExists.sync(path.join(t.context.tmp, file))));
}
function notExists(t, files) {
[].concat(files).forEach(file => t.false(pathExists.sync(path.join(t.context.tmp, file))));
}
const fixtures = [
'1.tmp',
'2.tmp',
'3.tmp',
'4.tmp',
'.dot.tmp'
];
test.beforeEach(t => {
t.context.tmp = tempfile();
fixtures.forEach(fixture => fs.ensureFileSync(path.join(t.context.tmp, fixture)));
});
test('skrub - invalid args', t => {
t.throws(execa(cliLocation));
});
test('skrub - dry-run does not remove files', async t => {
t.truthy(await execa(cliLocation, ['*.tpm', '!1*', '--dry-run']));
exists(t, ['1.tmp', '2.tmp', '3.tmp', '3.tmp', '.dot.tmp']);
});
test('skrub - removes files 1 iteration', async t => {
t.truthy(await execa(cliLocation, ['*.tmp', '!1*', '--cwd', t.context.tmp]));
exists(t, ['1.tmp', '.dot.tmp']);
notExists(t, ['2.tmp', '3.tmp', '4.tmp']);
});
test('skrub - removes files 7 iterations', async t => {
t.truthy(await execa(cliLocation, ['*.tmp', '!1*', '--cwd', t.context.tmp, '--iterations', 7]));
exists(t, ['1.tmp', '.dot.tmp']);
notExists(t, ['2.tmp', '3.tmp', '4.tmp']);
});