Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

chore: change interface tests to async node creation #1176

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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