Commit ee2ec06375d8aa1dbc04ba175e9de5085bfa8c42
don't start the ipfs node in tests
wanderer committed on 5/25/2017, 1:49:11 AMParent: 600f990b0583a4766c0311209cbe69cad38d2459
Files changed
exoInterface.js | changed |
port.js | changed |
portManager.js | changed |
tests/index.js | changed |
exoInterface.js | ||
---|---|---|
@@ -156,10 +156,10 @@ | ||
156 | 156 | * @param {Object} portRef - the port |
157 | 157 | * @param {Message} message - the message |
158 | 158 | */ |
159 | 159 | async send (portRef, message) { |
160 | - if (!this.ports.isValid(portRef)) { | |
161 | - throw new Error('invalid port') | |
160 | + if (!this.ports.isBound(portRef)) { | |
161 | + throw new Error('cannot send message with an unbound port') | |
162 | 162 | } |
163 | 163 | |
164 | 164 | // set the port that the message came from |
165 | 165 | message._fromPort = this.entryPort |
port.js | ||
---|---|---|
@@ -3,11 +3,12 @@ | ||
3 | 3 | * a simple repsentation of a port |
4 | 4 | * @property {Interger} ticks - the last know number of ticks the |
5 | 5 | * corrisponding container is at |
6 | 6 | */ |
7 | - constructor () { | |
7 | + constructor (name) { | |
8 | 8 | this._queue = [] |
9 | 9 | this.ticks = 0 |
10 | + this.name = name | |
10 | 11 | } |
11 | 12 | |
12 | 13 | /** |
13 | 14 | * queues a message on the port |
portManager.js | ||
---|---|---|
@@ -62,9 +62,9 @@ | ||
62 | 62 | }) |
63 | 63 | } |
64 | 64 | |
65 | 65 | _bindRef (portRef, name) { |
66 | - const port = new Port() | |
66 | + const port = new Port(name) | |
67 | 67 | this._portMap.set(portRef, port) |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -97,21 +97,22 @@ | ||
97 | 97 | |
98 | 98 | /** |
99 | 99 | * deletes a port given its name |
100 | 100 | * @param {String} name |
101 | + * @returns {boolean} whether or not the port was deleted | |
101 | 102 | */ |
102 | 103 | delete (name) { |
103 | 104 | const port = this.ports[name] |
104 | 105 | delete this.ports[name] |
105 | - this._portMap.delete(port) | |
106 | + return this._portMap.delete(port) | |
106 | 107 | } |
107 | 108 | |
108 | 109 | /** |
109 | 110 | * check if a port object is still valid |
110 | 111 | * @param {Object} port |
111 | 112 | * @return {Boolean} |
112 | 113 | */ |
113 | - isValid (port) { | |
114 | + isBound (port) { | |
114 | 115 | return this._portMap.has(port) |
115 | 116 | } |
116 | 117 | |
117 | 118 | _createPortObject (type, link) { |
@@ -139,14 +140,15 @@ | ||
139 | 140 | |
140 | 141 | /** |
141 | 142 | * creates a new Port given the container type |
142 | 143 | * @param {String} type |
144 | + * @param {*} data - the data to populate the initail state with | |
143 | 145 | * @returns {Object} the newly created port |
144 | 146 | */ |
145 | - create (type) { | |
147 | + create (type, data) { | |
146 | 148 | const Container = this.hypervisor._containerTypes[type] |
147 | 149 | return this._createPortObject(type, { |
148 | - '/': Container.createState() | |
150 | + '/': Container.createState(data) | |
149 | 151 | }) |
150 | 152 | } |
151 | 153 | |
152 | 154 | /** |
@@ -183,9 +185,9 @@ | ||
183 | 185 | * @param {Array} ports |
184 | 186 | * @returns {Promise} |
185 | 187 | */ |
186 | 188 | async getNextMessage (ports = [...this._portMap]) { |
187 | - if (this._portMap.size) { | |
189 | + if (ports.length) { | |
188 | 190 | // find the oldest message |
189 | 191 | const ticks = ports.map(([name, port]) => { |
190 | 192 | return port.size ? port.ticks : this.exoInterface.ticks |
191 | 193 | }).reduce((ticksA, ticksB) => { |
tests/index.js | ||
---|---|---|
@@ -1,9 +1,11 @@ | ||
1 | 1 | const tape = require('tape') |
2 | 2 | const IPFS = require('ipfs') |
3 | 3 | const Hypervisor = require('../') |
4 | 4 | |
5 | -const node = new IPFS() | |
5 | +const node = new IPFS({ | |
6 | + start: false | |
7 | +}) | |
6 | 8 | |
7 | 9 | class BaseContainer { |
8 | 10 | constructor (kernel) { |
9 | 11 | this.kernel = kernel |
@@ -16,19 +18,9 @@ | ||
16 | 18 | } |
17 | 19 | } |
18 | 20 | } |
19 | 21 | |
20 | -node.on('error', err => { | |
21 | - console.log(err) | |
22 | -}) | |
23 | - | |
24 | -node.on('start', () => { | |
25 | - tape.onFinish(() => { | |
26 | - node.stop(() => { | |
27 | - process.exit() | |
28 | - }) | |
29 | - }) | |
30 | - | |
22 | +node.on('ready', () => { | |
31 | 23 | tape('basic', async t => { |
32 | 24 | t.plan(2) |
33 | 25 | let message |
34 | 26 | const expectedState = { |
Built with git-ssb-web