-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest-promise.js
57 lines (53 loc) · 1.21 KB
/
test-promise.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
var test = require('tape')
var tiny = require('./dist.js')
test('env', t=> {
t.plan(7)
t.ok(tiny, 'got a tiny')
t.ok(tiny.get, 'got a tiny.get')
t.ok(tiny.post, 'got a tiny.post')
t.ok(tiny.put, 'got a tiny.put')
t.ok(tiny.patch, 'got a tiny.patch')
t.ok(tiny.del, 'got a tiny.delete')
t.ok(tiny.delete, 'got a tiny.delete')
console.log(tiny)
})
test('can get a url', async t=> {
t.plan(3)
var url = 'https://brian.io'
try {
var result = await tiny.get({url})
t.ok(result, 'got a result')
t.ok(result.headers, 'got headers')
t.ok(result.body, 'got body')
console.log(result)
}
catch(e) {
t.fail(err.statusCode, 'failed to get')
console.log(err)
}
})
test('get fails gracefully', t=> {
t.plan(1)
var url = 'http://nop333.ca'
tiny.get({url}, function __ruhroh(err, result) {
if (err) {
t.ok(err, 'got err as expected')
console.log(err)
}
else {
t.fail(result, 'should not succeed')
}
})
})
test('bad url gives a acually useful error with a fucking line number holy shit', async t=> {
t.plan(1)
try {
var res = await tiny.get('')
t.fail(res)
console.log(res)
}
catch(e) {
t.ok(e, 'res')
console.log(e)
}
})