forked from sindresorhus/unicorn-magic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (43 loc) · 1.17 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
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,
} 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);
});