This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
on-and-off.js
76 lines (62 loc) · 1.62 KB
/
on-and-off.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
76
/* eslint-env mocha */
'use strict'
const Factory = require('../utils/ipfs-factory-daemon')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const ipfsExec = require('../utils/ipfs-exec')
const clean = require('../utils/clean')
const os = require('os')
function off (tests) {
describe('daemon off (directly to core)', () => {
let thing = {}
let repoPath
before(function () {
this.timeout(30 * 1000)
repoPath = os.tmpdir() + '/ipfs-' + Math.random().toString().substring(2, 16)
thing.ipfs = ipfsExec(repoPath)
thing.ipfs.repoPath = repoPath
return thing.ipfs('init')
})
after(function (done) {
this.timeout(20 * 1000)
clean(repoPath)
setImmediate(done)
})
tests(thing)
})
}
function on (tests) {
describe('daemon on (through http-api)', () => {
let factory
let thing = {}
before(function (done) {
// CI takes longer to instantiate the daemon,
// so we need to increase the timeout for the
// before step
this.timeout(30 * 1000)
factory = new Factory()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
thing.ipfs = ipfsExec(node.repoPath)
thing.ipfs.repoPath = node.repoPath
done()
})
})
after(function (done) {
this.timeout(20 * 1000)
factory.dismantle(done)
})
tests(thing)
})
}
/*
* CLI Utility to run the tests offline (daemon off) and online (daemon on)
*/
exports = module.exports = (tests) => {
off(tests)
on(tests)
}
exports.off = off
exports.on = on