forked from ya7ya/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
64 lines (55 loc) · 1.46 KB
/
gulpfile.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
'use strict'
const gulp = require('gulp')
const parallel = require('async/parallel')
const series = require('async/series')
const createTempRepo = require('./test/utils/create-repo-nodejs.js')
const HTTPAPI = require('./src/http-api')
const leftPad = require('left-pad')
let nodes = []
/*
* spawns a daemon with ports numbers starting in 10 and ending in `num`
*/
function spawnDaemon (num, callback) {
num = leftPad(num, 3, 0)
const config = {
Addresses: {
Swarm: [
`/ip4/127.0.0.1/tcp/10${num}`,
`/ip4/127.0.0.1/tcp/20${num}/ws`
],
API: `/ip4/127.0.0.1/tcp/31${num}`,
Gateway: `/ip4/127.0.0.1/tcp/32${num}`
},
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}
const daemon = new HTTPAPI(createTempRepo(), config)
nodes.push(daemon)
daemon.start(true, callback)
}
gulp.task('libnode:start', (done) => {
nodes = []
parallel([
(cb) => spawnDaemon(7, cb),
(cb) => spawnDaemon(8, cb),
(cb) => spawnDaemon(12, cb),
(cb) => spawnDaemon(13, cb)
], done)
})
gulp.task('libnode:stop', (done) => {
series(nodes.map((node) => (cb) => {
setTimeout(() => node.stop(cb), 100)
}), done)
})
gulp.task('test:browser:before', ['libnode:start'])
gulp.task('test:node:before', ['libnode:start'])
gulp.task('test:browser:after', ['libnode:stop'])
gulp.task('test:node:after', ['libnode:stop'])
require('aegir/gulp')(gulp)