This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
- /* eslint-env mocha */
1
+ /* eslint-env mocha, browser */
2
2
'use strict'
3
3
4
4
const tests = require ( 'interface-ipfs-core' )
5
5
const CommonFactory = require ( '../utils/interface-common-factory' )
6
6
const isNode = require ( 'detect-node' )
7
+ const dnsFetchStub = require ( '../utils/dns-fetch-stub' )
7
8
8
9
describe ( 'interface-ipfs-core tests' , ( ) => {
10
+ // ipfs.dns in the browser calls out to https://ipfs.io/api/v0/dns.
11
+ // The following code stubs self.fetch to return a static CID for calls
12
+ // to https://ipfs.io/api/v0/dns?arg=ipfs.io.
13
+ if ( ! isNode ) {
14
+ const fetch = self . fetch
15
+
16
+ before ( ( ) => {
17
+ self . fetch = dnsFetchStub ( fetch )
18
+ } )
19
+
20
+ after ( ( ) => {
21
+ self . fetch = fetch
22
+ } )
23
+ }
24
+
9
25
const defaultCommonFactory = CommonFactory . create ( )
10
26
11
27
tests . bitswap ( defaultCommonFactory , { skip : ! isNode } )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ // Create a fetch stub with a fall through to the provided fetch implementation
4
+ // if the URL doesn't match https://ipfs.io/api/v0/dns?arg=ipfs.io.
5
+ module . exports = ( fetch ) => {
6
+ return function ( ) {
7
+ if ( arguments [ 0 ] . startsWith ( 'https://ipfs.io/api/v0/dns?arg=ipfs.io' ) ) {
8
+ return Promise . resolve ( {
9
+ json : ( ) => Promise . resolve ( {
10
+ Path : '/ipfs/QmYNQJoKGNHTpPxCBPh9KkDpaExgd2duMa3aF6ytMpHdao'
11
+ } )
12
+ } )
13
+ }
14
+ return fetch . apply ( this , arguments )
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments