|
1 |
| -/* eslint-env mocha */ |
| 1 | +/* eslint-env mocha, browser */ |
2 | 2 | 'use strict'
|
3 | 3 |
|
4 | 4 | const chai = require('chai')
|
5 | 5 | const dirtyChai = require('dirty-chai')
|
6 | 6 | const expect = chai.expect
|
7 | 7 | chai.use(dirtyChai)
|
8 | 8 | const Multiaddr = require('multiaddr')
|
| 9 | +const { isBrowser, isWebWorker } = require('ipfs-utils/src/env') |
9 | 10 |
|
10 | 11 | const configure = require('../src/lib/configure')
|
11 | 12 |
|
12 | 13 | describe('lib/configure', () => {
|
13 | 14 | it('should accept no config', () => {
|
14 | 15 | 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 | + } |
16 | 21 | })()
|
17 | 22 | })
|
18 | 23 |
|
@@ -40,21 +45,33 @@ describe('lib/configure', () => {
|
40 | 45 | it('should accept object with protocol only', () => {
|
41 | 46 | const input = { protocol: 'https' }
|
42 | 47 | 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 | + } |
44 | 53 | })(input)
|
45 | 54 | })
|
46 | 55 |
|
47 | 56 | it('should accept object with host only', () => {
|
48 | 57 | const input = { host: 'ipfs.io' }
|
49 | 58 | 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 | + } |
51 | 64 | })(input)
|
52 | 65 | })
|
53 | 66 |
|
54 | 67 | it('should accept object with port only', () => {
|
55 | 68 | const input = { port: 138 }
|
56 | 69 | 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 | + } |
58 | 75 | })(input)
|
59 | 76 | })
|
60 | 77 | })
|
0 commit comments