Skip to content

Commit

Permalink
chore: change interface tests to async node creation (ipfs#1176)
Browse files Browse the repository at this point in the history
* chore: change interface tests to async node creation

* chore: update interface-ipfs-core dep

* chore: code review changes
  • Loading branch information
PedroMiguelSS authored and Alan Shaw committed Nov 27, 2019
1 parent 876ae7c commit 64a44f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"cross-env": "^6.0.0",
"detect-node": "^2.0.4",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.121.0",
"interface-ipfs-core": "^0.122.0",
"ipfsd-ctl": "^0.47.1",
"ndjson": "^1.5.0",
"nock": "^11.4.0",
Expand Down
11 changes: 5 additions & 6 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const CommonFactory = require('./utils/interface-common-factory')
const isWindows = process.platform && process.platform === 'win32'

describe('interface-ipfs-core tests', () => {
const defaultCommonFactory = CommonFactory.create()
const defaultCommonFactory = CommonFactory.createAsync()

tests.bitswap(defaultCommonFactory, {
skip: [
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('interface-ipfs-core tests', () => {
]
})

tests.name(CommonFactory.create({
tests.name(CommonFactory.createAsync({
spawnOptions: {
args: ['--offline']
}
Expand All @@ -186,8 +186,7 @@ describe('interface-ipfs-core tests', () => {
]
})

// TODO: uncomment after https://github.com/ipfs/interface-ipfs-core/pull/361 being merged and a new release
tests.namePubsub(CommonFactory.create({
tests.namePubsub(CommonFactory.createAsync({
spawnOptions: {
args: ['--enable-namesys-pubsub'],
initOptions: { bits: 1024, profile: 'test' }
Expand Down Expand Up @@ -228,7 +227,7 @@ describe('interface-ipfs-core tests', () => {
]
})

tests.pubsub(CommonFactory.create({
tests.pubsub(CommonFactory.createAsync({
spawnOptions: {
args: ['--enable-pubsub-experiment'],
initOptions: { bits: 1024, profile: 'test' }
Expand All @@ -251,5 +250,5 @@ describe('interface-ipfs-core tests', () => {

tests.stats(defaultCommonFactory)

tests.swarm(CommonFactory.createAsync())
tests.swarm(defaultCommonFactory)
})
21 changes: 12 additions & 9 deletions test/utils/interface-common-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const IPFSFactory = require('ipfsd-ctl')
const ipfsClient = require('../../src')
const merge = require('merge-options')

const DEFAULT_FACTORY_OPTIONS = {
IpfsClient: ipfsClient
}

function createFactory (options) {
options = options || {}

options.factoryOptions = options.factoryOptions || { IpfsClient: ipfsClient }
options.factoryOptions = options.factoryOptions || { ...DEFAULT_FACTORY_OPTIONS }
options.spawnOptions = options.spawnOptions || { initOptions: { bits: 1024, profile: 'test' } }

const ipfsFactory = IPFSFactory.create(options.factoryOptions)
Expand Down Expand Up @@ -52,19 +56,18 @@ function createFactory (options) {
}
}

function createAsync (createFactoryOptions, createSpawnOptions) {
function createAsync (options = {}) {
return () => {
const nodes = []
const setup = async (factoryOptions = {}, spawnOptions) => {
const setup = async (setupOptions = {}) => {
const ipfsFactory = IPFSFactory.create(merge(
{ IpfsClient: ipfsClient },
factoryOptions,
createFactoryOptions
options.factoryOptions ? {} : { ...DEFAULT_FACTORY_OPTIONS },
setupOptions.factoryOptions,
options.factoryOptions
))
const node = await ipfsFactory.spawn(merge(
{ initOptions: { profile: 'test' } },
spawnOptions,
createSpawnOptions
setupOptions.spawnOptions,
options.spawnOptions || { initOptions: { profile: 'test' } }
))
nodes.push(node)

Expand Down

0 comments on commit 64a44f5

Please sign in to comment.