Skip to content

Commit 0da08b5

Browse files
committed
fix: enable tests of addFromURL in browser
Context: ipfs-inactive/interface-js-ipfs-core#514 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 43b00d0 commit 0da08b5

File tree

4 files changed

+14
-31
lines changed

4 files changed

+14
-31
lines changed

.aegir.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
const IPFSFactory = require('ipfsd-ctl')
44
const parallel = require('async/parallel')
55
const MockPreloadNode = require('./test/utils/mock-preload-node')
6+
const EchoHttpServer = require('interface-ipfs-core/src/utils/echo-http-server')
67

78
const ipfsdServer = IPFSFactory.createServer()
89
const preloadNode = MockPreloadNode.createNode()
10+
const httpEchoServer = EchoHttpServer.createServer() // used by addFromURL
11+
12+
const batch = (call, done, ...srvs) => parallel(srvs.map(srv => cb => {
13+
if (srv === ipfsdServer) {
14+
srv[call]()
15+
cb()
16+
} else {
17+
srv[call](cb)
18+
}
19+
}), done)
920

1021
module.exports = {
1122
bundlesize: { maxSize: '692kB' },
@@ -30,24 +41,8 @@ module.exports = {
3041
post: (cb) => preloadNode.stop(cb)
3142
},
3243
browser: {
33-
pre: (cb) => {
34-
parallel([
35-
(cb) => {
36-
ipfsdServer.start()
37-
cb()
38-
},
39-
(cb) => preloadNode.start(cb)
40-
], cb)
41-
},
42-
post: (cb) => {
43-
parallel([
44-
(cb) => {
45-
ipfsdServer.stop()
46-
cb()
47-
},
48-
(cb) => preloadNode.stop(cb)
49-
], cb)
50-
}
44+
pre: (cb) => batch('start', cb, ipfsdServer, preloadNode, httpEchoServer),
45+
post: (cb) => batch('stop', cb, ipfsdServer, preloadNode, httpEchoServer)
5146
}
5247
}
5348
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
"execa": "^2.0.4",
194194
"form-data": "^2.5.0",
195195
"hat": "0.0.3",
196-
"interface-ipfs-core": "^0.110.0",
196+
"interface-ipfs-core": "https://github.com/ipfs/interface-js-ipfs-core/tarball/38794027dac19ebaab3fec710d324d297599c08d/interface-js-ipfs-core.tar.gz#PR-514",
197197
"ipfsd-ctl": "^0.43.0",
198198
"libp2p-websocket-star": "~0.10.2",
199199
"ncp": "^2.0.0",

src/core/components/files-regular/add-from-url.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
const { URL } = require('iso-url')
44
const nodeify = require('promise-nodeify')
5-
const { isElectronRenderer } = require('ipfs-utils/src/env')
6-
if (isElectronRenderer) {
7-
// `fetch` needs to be polyfilled before importing ky-universal:
8-
// ky-universal won't use node-fetch because electron-renderer already has global.fetch defined
9-
// and we can't use the one from electron-renderer as it returns different
10-
// errors and makes HTTPS mocking impossible in tests
11-
// TODO: remove when upstream fix lands
12-
global.fetch = require('node-fetch')
13-
}
145
const { default: ky } = require('ky-universal')
156

167
module.exports = (ipfs) => {

test/core/interface.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ describe('interface-ipfs-core tests', function () {
6363
}, {
6464
name: 'addFromFs',
6565
reason: 'Not designed to run in the browser'
66-
}, {
67-
name: 'addFromURL',
68-
reason: 'Not designed to run in the browser'
6966
}]
7067
})
7168

0 commit comments

Comments
 (0)