-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtest.js
More file actions
48 lines (43 loc) · 1.59 KB
/
test.js
File metadata and controls
48 lines (43 loc) · 1.59 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
import path from 'node:path';
import fs from 'node:fs';
import test from 'ava';
import tempWrite from 'temp-write';
import {pathExists} from 'path-exists';
import {execa} from 'execa';
test('trash file', async t => {
const filename = tempWrite.sync('foo');
await execa('./cli.js', [filename]);
t.false(await pathExists(filename));
});
test('ignore rm flags', async t => {
const filename = tempWrite.sync('foo');
await execa('./cli.js', ['-rf', filename]);
t.false(await pathExists(filename));
});
test('dot flag matches dotfiles', async t => {
const directory = path.join(import.meta.dirname, '_fixture_dot');
fs.mkdirSync(directory, {recursive: true});
const dotfile = path.join(directory, '.hidden');
fs.writeFileSync(dotfile, 'foo');
await execa('./cli.js', ['--dot', `${directory}/*`]);
t.false(await pathExists(dotfile));
fs.mkdirSync(directory, {recursive: true});
});
test('dotfiles are not matched without dot flag', async t => {
const directory = path.join(import.meta.dirname, '_fixture_nodot');
fs.mkdirSync(directory, {recursive: true});
const dotfile = path.join(directory, '.hidden');
fs.writeFileSync(dotfile, 'foo');
const visible = path.join(directory, 'visible');
fs.writeFileSync(visible, 'foo');
await execa('./cli.js', [`${directory}/*`]);
t.true(await pathExists(dotfile));
t.false(await pathExists(visible));
fs.rmSync(directory, {recursive: true});
});
test('verbose mode', async t => {
const filename = tempWrite.sync('foo');
const {stdout} = await execa('./cli.js', ['--verbose', filename]);
t.false(await pathExists(filename));
t.true(stdout.includes(filename));
});