-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
69 lines (57 loc) · 1.63 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
66
67
68
69
'use strict';
const createSymlink = require('create-symlink');
const lstat = require('.');
const rmfr = require('rmfr');
const {Stats} = require('fs');
const test = require('tape');
test('lstat()', async t => {
t.plan(7);
const fail = t.fail.bind(t, 'Unexpectedly succeeded.');
lstat(new Set()).then(fail, ({message}) => {
t.strictEqual(
message,
'Expected a file path (string), but got a non-string value Set {}.',
'should fail when it takes a non-string argument.'
);
});
lstat('').then(fail, ({message}) => {
t.strictEqual(
message,
'Expected a file path, but got \'\' (empty string).',
'should fail when it takes an empty string.'
);
});
lstat().then(fail, ({message}) => {
t.strictEqual(
message,
'Expected 1 argument (string), but got no arguments instead.',
'should fail when it takes no arguments.'
);
});
lstat('a', 'b').then(fail, ({message}) => {
t.strictEqual(
message,
'Expected 1 argument (string), but got 2 arguments instead.',
'should fail when it takes too many arguments.'
);
});
lstat('none').then(fail, ({message}) => {
t.strictEqual(
message,
'ENOENT: no such file or directory, lstat \'none\'',
'should fail when it cannot find the file.'
);
});
await createSymlink(__filename, '__tmp_symlink__');
const stat = await lstat('__tmp_symlink__');
t.ok(
stat instanceof Stats,
'should be fulfilled with `fs.Stats` instance.'
);
t.strictEqual(
stat.isSymbolicLink(),
true,
'should get file info `lstat` way.'
);
await rmfr('__tmp_symlink__');
});