-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
65 lines (56 loc) · 1.55 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
55
56
57
58
59
60
61
62
63
64
65
import test from 'ava';
import fn from './';
import path from 'path';
const nm = path.join(__dirname, 'node_modules');
let absolutePath;
let relativePath;
let tildePath;
test('absolute path', t => {
const pkg = 'ava';
absolutePath = path.join(nm, pkg);
return fn(absolutePath, 'blue').then(res => {
t.is(res.code, 0);
t.is(res.tag, 'blue');
t.is(res.path, absolutePath);
t.true(res.command.length > 10);
}, t.fail);
});
test('relative path', t => {
const pkg = 'pify';
relativePath = './node_modules/' + pkg;
return fn(relativePath, 'green').then(res => {
t.is(res.code, 0);
t.is(res.tag, 'green');
t.is(res.path, path.join(nm, pkg));
t.true(res.command.length > 10);
}, t.fail);
});
test('tilde path', t => {
tildePath = '~/Desktop';
return fn(tildePath, 'yellow').then(res => {
t.is(res.code, 0);
t.is(res.tag, 'yellow');
t.true(res.path.includes('/Users/'));
t.true(res.command.length > 10);
}, t.fail);
});
test('path does not exist', t =>
fn(path.join(__dirname, 'node_modules/doesnotexist'), 'blue').then(
t.fail,
err => t.is(err.code, 'ENOENT')
));
test('color does not exist', t =>
fn(absolutePath, 'hotpink').then(t.fail, err =>
t.true(err.message.includes('color must be one of'))
));
test('path is not string', t =>
fn(92403, 'hotpink').then(t.fail, err =>
t.true(err.message.includes('path should be a string'))
));
test.after('clear test tags', () =>
Promise.all([
fn(absolutePath, 'clear'),
fn(relativePath, 'clear'),
fn(tildePath, 'clear')
])
);