This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
.aegir.cjs
65 lines (53 loc) · 1.55 KB
/
.aegir.cjs
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
'use strict'
const wrtc = require('wrtc')
// TODO: Temporary fix per wrtc issue
// https://github.com/node-webrtc/node-webrtc/issues/636#issuecomment-774171409
process.on('beforeExit', (code) => process.exit(code))
const ECHO_PROTOCOL = '/echo/1.0.0'
async function before () {
const { webRTCDirect } = await import('./dist/src/index.js')
const { pipe } = await import('it-pipe')
const { multiaddr } = await import('@multiformats/multiaddr')
const { mockUpgrader, mockRegistrar } = await import('@libp2p/interface-mocks')
const { EventEmitter } = await import('@libp2p/interfaces/events')
const REMOTE_MULTIADDR_IP4 = multiaddr('/ip4/127.0.0.1/tcp/12345/http/p2p-webrtc-direct')
const REMOTE_MULTIADDR_IP6 = multiaddr('/ip6/::1/tcp/12346/http/p2p-webrtc-direct')
const registrar = mockRegistrar()
void registrar.handle(ECHO_PROTOCOL, ({ stream }) => {
void pipe(
stream,
stream
).catch()
})
const upgrader = mockUpgrader({
registrar,
events: new EventEmitter()
})
const wd = webRTCDirect({
wrtc
})()
const listeners = await Promise.all(
[REMOTE_MULTIADDR_IP4, REMOTE_MULTIADDR_IP6].map(async ma => {
const listener = wd.createListener({
upgrader
})
await listener.listen(ma)
return listener
})
)
return {
listeners
}
}
async function after (testOptions, beforeReturn) {
await Promise.all(
beforeReturn.listeners.map(listener => listener.close())
)
}
/** @type {import('aegir').PartialOptions} */
module.exports = {
test: {
before,
after
}
}