This repository has been archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
75 lines (63 loc) · 1.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import test from 'ava'
import getIpfs from '.'
test.beforeEach(() => {
global.window = {}
global.document = {}
})
test.serial('should use window.ipfs if available', async t => {
window.ipfs = {}
const ipfs = await getIpfs()
t.is(ipfs, window.ipfs)
})
test.serial('should use window.ipfs.enable if available', async t => {
window.ipfs = { enable: async (args) => args }
const permissions = Object.freeze({ foo: ['a', 'b', 'c'], bar: ['1', '2', '3'], buzz: false })
const ipfs = await getIpfs({ permissions })
t.deepEqual(ipfs, permissions)
})
test.serial('should use window.Ipfs if available', async t => {
const instance = {
once (event, handler) {
if (event === 'ready') process.nextTick(() => handler())
return instance
},
removeListener: () => instance
}
window.Ipfs = function () { return instance }
const ipfs = await getIpfs()
t.is(ipfs, instance)
})
test.serial('should load IPFS from CDN if window.ipfs unavailable', async t => {
const instance = {
once (event, handler) {
if (event === 'ready') process.nextTick(() => handler())
return instance
},
removeListener: () => instance
}
document.createElement = () => ({})
document.body = {
appendChild (el) {
process.nextTick(() => {
window.Ipfs = function () { return instance }
el.onload()
})
}
}
const ipfs = await getIpfs()
t.is(ipfs, instance)
})
test.serial('should load IPFS API', async t => {
const instance = {}
document.createElement = () => ({})
document.body = {
appendChild (el) {
process.nextTick(() => {
window.IpfsApi = function () { return instance }
el.onload()
})
}
}
const ipfs = await getIpfs({ api: true })
t.is(ipfs, instance)
})