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

Commit 0671a5e

Browse files
author
Pedro Santos
committed
chore: change interface tests to async node creation
1 parent 03396ba commit 0671a5e

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"execa": "^3.0.0",
205205
"form-data": "^3.0.0",
206206
"hat": "0.0.3",
207-
"interface-ipfs-core": "^0.119.0",
207+
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#chore/async-await-refactor",
208208
"ipfs-interop": "^0.1.1",
209209
"ipfsd-ctl": "^0.47.2",
210210
"libp2p-websocket-star": "~0.10.2",

test/core/interface.spec.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const isNode = require('detect-node')
88
describe('interface-ipfs-core tests', function () {
99
this.timeout(20 * 1000)
1010

11-
const defaultCommonFactory = CommonFactory.create()
11+
const defaultCommonFactory = CommonFactory.createAsync()
1212

1313
tests.bitswap(defaultCommonFactory, { skip: !isNode })
1414

@@ -20,7 +20,7 @@ describe('interface-ipfs-core tests', function () {
2020

2121
tests.dag(defaultCommonFactory)
2222

23-
tests.dht(CommonFactory.create({
23+
tests.dht(CommonFactory.createAsync({
2424
spawnOptions: {
2525
config: {
2626
Bootstrap: [],
@@ -53,7 +53,7 @@ describe('interface-ipfs-core tests', function () {
5353

5454
tests.filesMFS(defaultCommonFactory)
5555

56-
tests.key(CommonFactory.create({
56+
tests.key(CommonFactory.createAsync({
5757
spawnOptions: {
5858
args: ['--pass ipfs-is-awesome-software'],
5959
initOptions: { bits: 512 },
@@ -71,21 +71,19 @@ describe('interface-ipfs-core tests', function () {
7171
}
7272
}))
7373

74-
tests.miscellaneous(CommonFactory.create({
75-
// No need to stop, because the test suite does a 'stop' test.
76-
createTeardown: () => cb => cb(),
74+
tests.miscellaneous(CommonFactory.createAsync({
7775
spawnOptions: {
7876
args: ['--pass ipfs-is-awesome-software', '--offline']
7977
}
8078
}))
8179

82-
tests.name(CommonFactory.create({
80+
tests.name(CommonFactory.createAsync({
8381
spawnOptions: {
8482
args: ['--pass ipfs-is-awesome-software', '--offline']
8583
}
8684
}))
8785

88-
tests.namePubsub(CommonFactory.create({
86+
tests.namePubsub(CommonFactory.createAsync({
8987
spawnOptions: {
9088
args: ['--enable-namesys-pubsub'],
9189
initOptions: { bits: 1024 },
@@ -120,7 +118,7 @@ describe('interface-ipfs-core tests', function () {
120118
}
121119
})
122120

123-
tests.pubsub(CommonFactory.create({
121+
tests.pubsub(CommonFactory.createAsync({
124122
spawnOptions: {
125123
initOptions: { bits: 512 }
126124
}
@@ -134,5 +132,5 @@ describe('interface-ipfs-core tests', function () {
134132

135133
tests.stats(defaultCommonFactory)
136134

137-
tests.swarm(CommonFactory.createAsync(), { skip: !isNode })
135+
tests.swarm(defaultCommonFactory, { skip: !isNode })
138136
})

test/http-api/interface.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CommonFactory = require('../utils/interface-common-factory')
66
const path = require('path')
77

88
describe('interface-ipfs-core over ipfs-http-client tests', () => {
9-
const defaultCommonFactory = CommonFactory.create({
9+
const defaultCommonFactory = CommonFactory.createAsync({
1010
factoryOptions: { exec: path.resolve(`${__dirname}/../../src/cli/bin.js`) }
1111
})
1212

@@ -28,7 +28,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
2828
}]
2929
})
3030

31-
tests.dht(CommonFactory.create({
31+
tests.dht(CommonFactory.createAsync({
3232
spawnOptions: {
3333
initOptions: { bits: 512 },
3434
config: {
@@ -54,7 +54,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
5454

5555
tests.filesMFS(defaultCommonFactory)
5656

57-
tests.key(CommonFactory.create({
57+
tests.key(CommonFactory.createAsync({
5858
spawnOptions: {
5959
args: ['--pass ipfs-is-awesome-software'],
6060
initOptions: { bits: 512 },
@@ -73,21 +73,19 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
7373
}
7474
}))
7575

76-
tests.miscellaneous(CommonFactory.create({
77-
// No need to stop, because the test suite does a 'stop' test.
78-
createTeardown: () => cb => cb(),
76+
tests.miscellaneous(CommonFactory.createAsync({
7977
spawnOptions: {
8078
args: ['--pass ipfs-is-awesome-software', '--offline']
8179
}
8280
}))
8381

84-
tests.name(CommonFactory.create({
82+
tests.name(CommonFactory.createAsync({
8583
spawnOptions: {
8684
args: ['--pass ipfs-is-awesome-software', '--offline']
8785
}
8886
}))
8987

90-
tests.namePubsub(CommonFactory.create({
88+
tests.namePubsub(CommonFactory.createAsync({
9189
spawnOptions: {
9290
args: ['--enable-namesys-pubsub'],
9391
initOptions: { bits: 1024 },
@@ -118,7 +116,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
118116

119117
tests.ping(defaultCommonFactory)
120118

121-
tests.pubsub(CommonFactory.create({
119+
tests.pubsub(CommonFactory.createAsync({
122120
spawnOptions: {
123121
initOptions: { bits: 512 }
124122
}

test/utils/interface-common-factory.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ const callbackify = require('callbackify')
88
const mergeOptions = require('merge-options')
99
const IPFS = require('../../src')
1010

11+
const DEFAULT_FACTORY_OPTIONS = {
12+
type: 'proc',
13+
exec: IPFS
14+
}
15+
1116
function createFactory (options) {
1217
options = options || {}
1318

14-
options.factoryOptions = options.factoryOptions || { type: 'proc', exec: IPFS }
19+
options.factoryOptions = options.factoryOptions || DEFAULT_FACTORY_OPTIONS
1520
options.spawnOptions = mergeOptions({
1621
initOptions: { bits: 512 },
1722
config: {
@@ -68,25 +73,23 @@ function createFactory (options) {
6873
}
6974
}
7075

71-
function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
76+
function createAsync (options = {}) {
7277
return () => {
7378
const nodes = []
74-
const setup = async (factoryOptions = {}, spawnOptions = {}) => {
75-
factoryOptions = mergeOptions(
76-
{
77-
type: 'proc',
78-
exec: IPFS
79-
},
80-
factoryOptions,
81-
createFactoryOptions
79+
const setup = async (setupOptions = {}) => {
80+
options.factoryOptions = mergeOptions(
81+
setupOptions.factoryOptions,
82+
options.factoryOptions || DEFAULT_FACTORY_OPTIONS
8283
)
84+
8385
// When not an in proc daemon use the http-client js-ipfs depends on, not the one from ipfsd-ctl
84-
if (factoryOptions.type !== 'proc') {
85-
factoryOptions.IpfsClient = factoryOptions.IpfsClient || ipfsClient
86+
if (options.factoryOptions.type !== 'proc') {
87+
options.factoryOptions.IpfsClient = options.factoryOptions.IpfsClient || ipfsClient
8688
}
8789

88-
const ipfsFactory = IPFSFactory.create(factoryOptions)
89-
const node = await ipfsFactory.spawn(mergeOptions(
90+
const ipfsFactory = IPFSFactory.create(options.factoryOptions)
91+
92+
options.spawnOptions = mergeOptions(
9093
{
9194
config: {
9295
Bootstrap: [],
@@ -101,9 +104,12 @@ function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
101104
},
102105
preload: { enabled: false }
103106
},
104-
spawnOptions,
105-
createSpawnOptions
106-
))
107+
setupOptions.spawnOptions,
108+
options.spawnOptions
109+
)
110+
111+
const node = await ipfsFactory.spawn(options.spawnOptions)
112+
107113
nodes.push(node)
108114

109115
const id = await node.api.id()

0 commit comments

Comments
 (0)