-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.tests.ts
62 lines (51 loc) · 1.75 KB
/
app.tests.ts
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
import nurl, { BaseUrlResolver, ResolvedMediaItem } from '../app.js';
import test from 'ava';
test('resolve is defined', t => {
(typeof nurl['resolve'] == 'function') ? t.pass() : t.fail();
});
test('resolveRecursive is defined', t => {
(typeof nurl['resolveRecursive'] == 'function') ? t.pass() : t.fail();
});
test('custom resolver registration', async t => {
const resolvedFile = 'http://mylink/resolvedfile.mkv';
class customResolver extends BaseUrlResolver {
constructor() {
super({
domains: [/https?:\/\/(testdomain)/],
speedRank: 70
});
}
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem | ResolvedMediaItem[]> {
return {
link: resolvedFile
} as ResolvedMediaItem;
}
}
const result = await nurl.resolve('http://testdomain.com/file.mkv', {
timeout: 100,
customResolvers: [customResolver]
});
t.is(result[0].link, resolvedFile);
});
test('resolver deregistration', async t => {
const resolvedFile = 'http://mylink/resolvedfile.mkv';
class customResolver extends BaseUrlResolver {
constructor() {
super({
domains: [/https?:\/\/(testdomain)/],
speedRank: 70
});
}
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem | ResolvedMediaItem[]> {
return {
link: resolvedFile
} as ResolvedMediaItem;
}
}
const result = await nurl.resolve('http://testdomain.com/file.mkv', {
timeout: 100,
customResolvers: [customResolver],
ignoreResolvers: [/customResolver/]
});
t.is(result.length, 0);
});