Skip to content

Commit b6ad854

Browse files
committed
feat: making tests run in browser and node
1 parent 70db1b2 commit b6ad854

14 files changed

+835
-108
lines changed

.aegir.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
'use strict'
22

3-
const tasks = require('./src/remote-factory/tasks')
3+
const server = require('./src/remote/server')
44

55
module.exports = {
6+
karma: {
7+
files: [{
8+
pattern: 'test/fixtures/**/*',
9+
watched: false,
10+
served: true,
11+
included: false
12+
}],
13+
singleRun: true
14+
},
615
hooks: {
716
browser: {
8-
pre: tasks.start,
9-
post: tasks.stop
17+
pre: server.start,
18+
post: server.stop
1019
}
1120
}
1221
}

package.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
"scripts": {
77
"lint": "aegir lint",
88
"coverage": "aegir coverage",
9-
"test": "aegir test -t node --timeout 50000",
9+
"test": "aegir test -t node -t browser --no-cors --timeout 50000",
10+
"test:node": "aegir test -t node --timeout 50000",
11+
"test:browser": "aegir test -t browser --no-cors --timeout 50000",
1012
"docs": "aegir docs",
1113
"release": "aegir release -t node",
1214
"release-minor": "aegir release --type minor -t node",
1315
"release-major": "aegir release --type major -t node",
1416
"coverage-publish": "aegir coverage -u"
1517
},
18+
"browser": {
19+
"./src/daemon.js": false,
20+
"glob": false,
21+
"fs": false,
22+
"stream": "readable-stream",
23+
"http": "stream-http"
24+
},
1625
"engines": {
1726
"node": ">=6.0.0",
1827
"npm": ">=3.0.0"
@@ -51,16 +60,26 @@
5160
"license": "MIT",
5261
"dependencies": {
5362
"async": "^2.6.0",
63+
"debug": "^3.1.0",
5464
"detect-node": "^2.0.3",
5565
"eslint-config-standard-jsx": "^4.0.2",
5666
"go-ipfs-dep": "0.4.13",
67+
"guid": "0.0.12",
68+
"hapi": "^16.6.2",
69+
"http-browserify": "^1.7.0",
5770
"ipfs-api": "^17.1.3",
71+
"lodash.clonewith": "^4.5.0",
5872
"lodash.get": "^4.4.2",
73+
"lodash.mapvalues": "^4.6.0",
5974
"lodash.merge": "^4.6.0",
6075
"multiaddr": "^3.0.1",
6176
"once": "^1.4.0",
77+
"qs": "^6.5.1",
78+
"readable-stream": "^2.3.3",
79+
"request": "^2.83.0",
6280
"rimraf": "^2.6.2",
6381
"shutdown": "^0.3.0",
82+
"stream-http": "^2.7.2",
6483
"subcomandante": "^1.0.5",
6584
"truthy": "0.0.1"
6685
},

src/daemon.js

+14
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Node {
109109
this.env = this.path ? Object.assign({}, process.env, { IPFS_PATH: this.path }) : process.env
110110
this._apiAddr = null
111111
this._gatewayAddr = null
112+
this._started = false
112113

113114
if (this.opts.env) {
114115
Object.assign(this.env, this.opts.env)
@@ -133,6 +134,15 @@ class Node {
133134
return this._gatewayAddr
134135
}
135136

137+
/**
138+
* Is the node started
139+
*
140+
* @return {boolean}
141+
*/
142+
get started () {
143+
return this._started
144+
}
145+
136146
_run (args, opts, callback) {
137147
return exec(this.exec, args, opts, callback)
138148
}
@@ -262,6 +272,7 @@ class Node {
262272

263273
if (output.match(/(?:daemon is running|Daemon is ready)/)) {
264274
// we're good
275+
this._started = true
265276
return callback(null, this.api)
266277
}
267278
}
@@ -335,6 +346,9 @@ class Node {
335346
callback = key
336347
key = 'show'
337348
}
349+
if (!key) {
350+
key = 'show'
351+
}
338352

339353
async.waterfall([
340354
(cb) => this._run(

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ const waterfall = require('async/waterfall')
66
const Node = require('./daemon')
77

88
const defaultOptions = {
9+
config: {
10+
'API.HTTPHeaders.Access-Control-Allow-Origin': ['*'],
11+
'API.HTTPHeaders.Access-Control-Allow-Methods': [
12+
'PUT',
13+
'POST',
14+
'GET'
15+
]
16+
},
917
disposable: true,
1018
start: true,
1119
init: true

0 commit comments

Comments
 (0)