-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
63 lines (54 loc) · 1.45 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
import process from 'node:process';
import path from 'node:path';
import test from 'ava';
import timeSpan from 'time-span';
import inRange from 'in-range';
import {
delay,
toPath,
rootDirectory,
traversePathUp,
execFile,
execFileSync,
} from './node.js';
test.serial('delay - seconds', async t => {
const end = timeSpan();
await delay({seconds: 0.1});
t.true(inRange(end(), {start: 80, end: 120}), 'is delayed');
});
test.serial('delay - milliseconds', async t => {
const end = timeSpan();
await delay({milliseconds: 100});
t.true(inRange(end(), {start: 80, end: 120}), 'is delayed');
});
test('toPath', t => {
const fixture = './foo.js';
t.is(toPath(new URL(fixture, import.meta.url)), path.resolve(fixture));
t.is(toPath(fixture), fixture);
});
test('rootDirectory', t => {
if (process.platform === 'win32') {
t.is(rootDirectory('C:\\Users\\Unicorn\\Projects\\Magic'), 'C:\\');
} else {
t.is(rootDirectory('/Users/Unicorn/Projects/Magic'), '/');
}
});
test('traversePathUp', t => {
const traversedPaths = [...traversePathUp('/some/nested/directory')];
const expectedPaths = [
'/some/nested/directory',
'/some/nested',
'/some',
'/',
];
t.deepEqual(traversedPaths, expectedPaths);
});
test('execFile', async t => {
const {stdout, stderr} = await execFile('echo', ['hello']);
t.is(stdout.trim(), 'hello');
t.is(stderr, '');
});
test('execFileSync', t => {
const output = execFileSync('echo', ['hello']);
t.is(output.trim(), 'hello');
});