-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
30 lines (22 loc) · 1.13 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
import test from 'ava';
import resolveFrom from '.';
test('resolveFrom()', t => {
t.throws(() => resolveFrom(1, './fixture'), /got `number`/);
t.throws(() => resolveFrom('fixture'), /got `undefined`/);
t.regex(resolveFrom('fixture', './fixture'), /fixture\/fixture\.js$/);
const moduleNotFoundError = t.throws(() => {
resolveFrom('fixture', './nonexistent');
}, Error);
t.is(moduleNotFoundError.code, 'MODULE_NOT_FOUND');
t.is(moduleNotFoundError.message.split(/[\n\r]+/)[0], 'Cannot find module \'./nonexistent\'');
const resolveFromfixture = resolveFrom.bind(null, 'fixture');
t.regex(resolveFromfixture('./fixture'), /fixture\/fixture\.js$/);
t.truthy(resolveFrom('./fixture/fixture-for-symlinks/symlink-target', 'foo'));
});
test('resolveFrom.silent()', t => {
t.regex(resolveFrom.silent('fixture', './fixture'), /fixture\/fixture\.js$/);
t.is(resolveFrom.silent('fixture', './nonexistent'), undefined);
const silentResolveFromfixture = resolveFrom.silent.bind(null, 'fixture');
t.regex(silentResolveFromfixture('./fixture'), /fixture\/fixture\.js$/);
t.is(resolveFrom.silent('fixture-not-exists', './fixture'), undefined);
});