Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 76ae81c

Browse files
committed
fix(ci): disable preload when NODE_ENV is 'test'
Preload tests failed in browser because preload is enabled in browser context by default and while js-ipfs tests disable preload in tests, interface-ipfs-core does not. This means interface-ipfs-core tests triggered dozens of slow/hanging requests to `nodeX.preload.iofs.io/api/v0/refs` and js-ipfs executed only 4 at a time. By the time preload tests got executed, the queue was long and it did not finish before timeout. This change detects js-ipfs is running in test environment (`process.env.NODE_ENV === 'test'`) and disables preload by default. This way we are still be able to test preload by explicitly enabling it in config, but we won't have preload overhead when running unrelated interface-ipfs-core tests. License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 070e205 commit 76ae81c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/cli/commands/daemon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
})
3232
.option('enable-preload', {
3333
type: 'boolean',
34-
default: true
34+
default: process.env.NODE_ENV !== 'test' // preload by default, unless in test env
3535
})
3636
},
3737

src/core/config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const configSchema = s({
3131
enabled: 'boolean?',
3232
addresses: optional(s(['multiaddr'])),
3333
interval: 'number?'
34-
}, { enabled: true, interval: 30 * 1000 }),
34+
}, { // defaults if missing:
35+
enabled: process.env.NODE_ENV !== 'test', // preload by default, unless in test env
36+
interval: 30 * 1000
37+
}),
3538
init: optional(union(['boolean', s({
3639
bits: 'number?',
3740
emptyRepo: 'boolean?',

src/core/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class IPFS extends EventEmitter {
4545
start: true,
4646
EXPERIMENTAL: {},
4747
preload: {
48-
enabled: true,
48+
enabled: process.env.NODE_ENV !== 'test', // preload by default, unless in test env
4949
addresses: [
5050
'/dnsaddr/node0.preload.ipfs.io/https',
5151
'/dnsaddr/node1.preload.ipfs.io/https'

0 commit comments

Comments
 (0)