Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit cea1bd5

Browse files
author
Alan Shaw
committed
fix: tests in browser
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 176556c commit cea1bd5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/lib.configure.spec.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
/* eslint-env mocha */
1+
/* eslint-env mocha, browser */
22
'use strict'
33

44
const chai = require('chai')
55
const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
88
const Multiaddr = require('multiaddr')
9+
const { isBrowser, isWebWorker } = require('ipfs-utils/src/env')
910

1011
const configure = require('../src/lib/configure')
1112

1213
describe('lib/configure', () => {
1314
it('should accept no config', () => {
1415
configure(config => {
15-
expect(config.apiAddr).to.eql('http://localhost:5001')
16+
if (isBrowser || isWebWorker) {
17+
expect(config.apiAddr).to.eql(location.origin)
18+
} else {
19+
expect(config.apiAddr).to.eql('http://localhost:5001')
20+
}
1621
})()
1722
})
1823

@@ -40,21 +45,33 @@ describe('lib/configure', () => {
4045
it('should accept object with protocol only', () => {
4146
const input = { protocol: 'https' }
4247
configure(config => {
43-
expect(config.apiAddr).to.eql('https://localhost')
48+
if (isBrowser || isWebWorker) {
49+
expect(config.apiAddr).to.eql(`https://${location.host}`)
50+
} else {
51+
expect(config.apiAddr).to.eql('https://localhost')
52+
}
4453
})(input)
4554
})
4655

4756
it('should accept object with host only', () => {
4857
const input = { host: 'ipfs.io' }
4958
configure(config => {
50-
expect(config.apiAddr).to.eql('http://ipfs.io')
59+
if (isBrowser || isWebWorker) {
60+
expect(config.apiAddr).to.eql(`http://ipfs.io:${location.port}`)
61+
} else {
62+
expect(config.apiAddr).to.eql('http://ipfs.io')
63+
}
5164
})(input)
5265
})
5366

5467
it('should accept object with port only', () => {
5568
const input = { port: 138 }
5669
configure(config => {
57-
expect(config.apiAddr).to.eql('http://localhost:138')
70+
if (isBrowser || isWebWorker) {
71+
expect(config.apiAddr).to.eql(`http://${location.hostname}:138`)
72+
} else {
73+
expect(config.apiAddr).to.eql('http://localhost:138')
74+
}
5875
})(input)
5976
})
6077
})

0 commit comments

Comments
 (0)