-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
executable file
·53 lines (36 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import test from 'tape'
import { makeFetch, makeRoutedFetch } from './index.js'
test('Basic makeFetch test', async (t) => {
const fetch = makeFetch(({ url }) => {
return {
status: 200,
statusText: 'OK',
headers: {
url
},
body: intoAsyncIterable(url)
}
})
const toFetch = 'example://hostname/pathname'
const response = await fetch(toFetch)
t.ok(response.ok, 'response was OK')
const body = await response.text()
t.equal(body, toFetch, 'got expected response body')
t.equal(response.headers.get('url'), toFetch, 'got expected response headers')
t.equal(response.statusText, 'OK', 'got expected status text')
t.end()
})
test('Basic router tests', async (t) => {
const { fetch, router } = makeRoutedFetch()
router.get('ipfs://localhost/ipfs/**', ({ url }) => {
return { body: url }
})
const toFetch = 'ipfs://localhost/ipfs/cidwould/gohere'
const response = await fetch(toFetch)
t.ok(response.ok, 'response was OK')
const body = await response.text()
t.equal(body, toFetch, 'got expected body')
})
async function * intoAsyncIterable (data) {
yield data
}