@@ -7,46 +7,98 @@ const dirtyChai = require('dirty-chai')
7
7
const expect = chai . expect
8
8
chai . use ( dirtyChai )
9
9
10
+ const isNode = require ( 'detect-node' )
11
+
10
12
const IPFSFactory = require ( 'ipfsd-ctl' )
11
13
const IPFS = require ( '../../src/core' )
12
14
13
15
describe ( 'dht' , ( ) => {
14
- let ipfsd , ipfs
16
+ describe ( 'enabled' , ( ) => {
17
+ if ( ! isNode ) { return }
18
+
19
+ let ipfsd , ipfs
20
+
21
+ before ( function ( done ) {
22
+ this . timeout ( 30 * 1000 )
15
23
16
- before ( function ( done ) {
17
- this . timeout ( 30 * 1000 )
24
+ const factory = IPFSFactory . create ( { type : 'proc' } )
18
25
19
- const factory = IPFSFactory . create ( { type : 'proc' } )
26
+ factory . spawn ( {
27
+ exec : IPFS ,
28
+ initOptions : { bits : 512 } ,
29
+ config : {
30
+ Bootstrap : [ ]
31
+ }
32
+ } , ( err , _ipfsd ) => {
33
+ expect ( err ) . to . not . exist ( )
34
+ ipfsd = _ipfsd
35
+ ipfs = _ipfsd . api
36
+ done ( )
37
+ } )
38
+ } )
20
39
21
- factory . spawn ( {
22
- exec : IPFS ,
23
- initOptions : { bits : 512 } ,
24
- config : {
25
- Bootstrap : [ ]
40
+ after ( ( done ) => {
41
+ if ( ipfsd ) {
42
+ ipfsd . stop ( done )
43
+ } else {
44
+ done ( )
26
45
}
27
- } , ( err , _ipfsd ) => {
28
- expect ( err ) . to . not . exist ( )
29
- ipfsd = _ipfsd
30
- ipfs = _ipfsd . api
31
- done ( )
32
46
} )
33
- } )
34
47
35
- after ( ( done ) => {
36
- if ( ipfsd ) {
37
- ipfsd . stop ( done )
38
- } else {
39
- done ( )
40
- }
48
+ describe ( 'findprovs' , ( ) => {
49
+ it ( 'should callback with error for invalid CID input' , ( done ) => {
50
+ ipfs . dht . findProvs ( 'INVALID CID' , ( err ) => {
51
+ expect ( err ) . to . exist ( )
52
+ expect ( err . code ) . to . equal ( 'ERR_INVALID_CID' )
53
+ done ( )
54
+ } )
55
+ } )
56
+ } )
41
57
} )
42
58
43
- describe ( 'findprovs' , ( ) => {
44
- it ( 'should callback with error for invalid CID input' , ( done ) => {
45
- ipfs . dht . findProvs ( 'INVALID CID' , ( err ) => {
46
- expect ( err ) . to . exist ( )
47
- expect ( err . code ) . to . equal ( 'ERR_INVALID_CID' )
59
+ describe ( 'disabled in browser' , ( ) => {
60
+ if ( isNode ) { return }
61
+
62
+ let ipfsd , ipfs
63
+
64
+ before ( function ( done ) {
65
+ this . timeout ( 30 * 1000 )
66
+
67
+ const factory = IPFSFactory . create ( { type : 'proc' } )
68
+
69
+ factory . spawn ( {
70
+ exec : IPFS ,
71
+ initOptions : { bits : 512 } ,
72
+ config : {
73
+ Bootstrap : [ ]
74
+ }
75
+ } , ( err , _ipfsd ) => {
76
+ expect ( err ) . to . not . exist ( )
77
+ ipfsd = _ipfsd
78
+ ipfs = _ipfsd . api
48
79
done ( )
49
80
} )
50
81
} )
82
+
83
+ after ( ( done ) => {
84
+ if ( ipfsd ) {
85
+ ipfsd . stop ( done )
86
+ } else {
87
+ done ( )
88
+ }
89
+ } )
90
+
91
+ describe ( 'put' , ( ) => {
92
+ it ( 'should callback with error for DHT not available' , async ( ) => {
93
+ let res
94
+ try {
95
+ res = await ipfs . dht . put ( Buffer . from ( 'a' ) , Buffer . from ( 'b' ) )
96
+ } catch ( err ) {
97
+ expect ( err ) . to . exist ( )
98
+ }
99
+
100
+ expect ( res ) . to . not . exist ( )
101
+ } )
102
+ } )
51
103
} )
52
104
} )
0 commit comments