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

Commit

Permalink
fix: refactor missing pieces and await clean in bitswap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Dec 11, 2019
1 parent b2dff1d commit 186c886
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
"multihashing-async": "^0.8.0",
"node-fetch": "^2.3.0",
"p-iteration": "^1.1.8",
"p-map": "^3.0.0",
"p-queue": "^6.1.0",
"peer-book": "^0.9.1",
"peer-id": "~0.12.2",
Expand Down Expand Up @@ -213,6 +212,7 @@
"lodash": "^4.17.15",
"ncp": "^2.0.0",
"p-event": "^4.1.0",
"p-map": "^3.0.0",
"qs": "^6.5.2",
"rimraf": "^3.0.0",
"sinon": "^7.4.2",
Expand Down
8 changes: 4 additions & 4 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('bitswap', function () {
const b = await remote.block.get(block.cid)

expect(b.data).to.eql(block.data)
df.clean()
await df.clean()
})

it('3 peers', async () => {
Expand All @@ -55,7 +55,7 @@ describe('bitswap', function () {
expect(await remote2.block.get(block.cid)).to.eql(block)
expect(await proc.block.get(block.cid)).to.eql(block)
}, { concurrency: 3 })
df.clean()
await df.clean()
})
})

Expand All @@ -71,7 +71,7 @@ describe('bitswap', function () {
const files = await remote.add([{ path: 'awesome.txt', content: file }])
const data = await proc.cat(files[0].hash)
expect(data).to.eql(file)
df.clean()
await df.clean()
})
})

Expand All @@ -84,7 +84,7 @@ describe('bitswap', function () {
expect(err).to.exist()
expect(err.code).to.equal('ERR_INVALID_CID')
} finally {
df.clean()
await df.clean()
}
})
})
Expand Down
6 changes: 1 addition & 5 deletions test/core/dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ describe.skip('dht', () => {
ipfs = ipfsd.api
})

after(() => {
if (ipfsd) {
return ipfsd.stop()
}
})
after(() => df.clean())

describe('put', () => {
it('should error when DHT not available', async () => {
Expand Down
55 changes: 10 additions & 45 deletions test/core/name.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe('name', function () {

// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
describe.skip('work with dht', () => {
let nodes
let nodeA
let nodeB
let nodeC
Expand Down Expand Up @@ -115,7 +114,6 @@ describe('name', function () {
], (err, _nodes) => {
expect(err).to.not.exist()

nodes = _nodes
nodeA = _nodes[0].api
nodeB = _nodes[1].api
nodeC = _nodes[2].api
Expand All @@ -136,11 +134,7 @@ describe('name', function () {
})
})

after(function (done) {
this.timeout(80 * 1000)

parallel(nodes.map((node) => (cb) => node.stop(cb)), done)
})
after(() => df.clean())

it('should publish and then resolve correctly with the default options', function (done) {
this.timeout(380 * 1000)
Expand Down Expand Up @@ -175,32 +169,17 @@ describe('name', function () {
before(async function () {
this.timeout(40 * 1000)
ipfsd = await df.spawn({
exec: IPFS,
args: ['--pass', hat()],
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
},
preload: { enabled: false }
ipfsOptions: {
pass: hat()
}
})
node = ipfsd.api

const res = await node.id()
nodeId = res.id
})

after(() => {
if (ipfsd) {
return ipfsd.stop()
}
})
after(() => df.clean())

it('should error to publish if does not receive private key', function () {
return expect(node._ipns.publisher.publish(null, ipfsRef))
Expand Down Expand Up @@ -322,32 +301,18 @@ describe('name', function () {
before(async function () {
this.timeout(40 * 1000)
ipfsd = await df.spawn({
exec: IPFS,
args: ['--pass', hat(), '--offline'],
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
},
preload: { enabled: false }
ipfsOptions: {
pass: hat(),
offline: true
}
})
node = ipfsd.api

const res = await node.id()
nodeId = res.id
})

after(() => {
if (ipfsd) {
return ipfsd.stop()
}
})
after(() => df.clean())

it('should resolve an ipfs path correctly', async function () {
const res = await node.add(fixture)
Expand Down
6 changes: 1 addition & 5 deletions test/core/pin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ describe('pin', function () {
ipfs = ipfsd.api
})

after(() => {
if (ipfsd) {
return ipfsd.stop()
}
})
after(() => df.clean())

describe('ls', () => {
it('should callback with error for invalid non-string pin type option', (done) => {
Expand Down
18 changes: 1 addition & 17 deletions test/core/ping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,7 @@ describe('ping', function () {
})
})

after(async () => {
if (ipfsdA) {
await ipfsdA.stop()
}
})

after(async () => {
if (ipfsdB) {
await ipfsdB.stop()
}
})

after(async () => {
if (ipfsdC) {
await ipfsdC.stop()
}
})
after(() => df.clean())

it('if enabled uses the DHT peer routing to find peer', (done) => {
let messageNum = 0
Expand Down
5 changes: 1 addition & 4 deletions test/utils/on-and-off.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ function on (tests) {

after(function () {
resetLocaleToSystem()
if (ipfsd) {
this.timeout(15 * 1000)
return ipfsd.stop()
}
df.clean()
})

tests(thing)
Expand Down

0 comments on commit 186c886

Please sign in to comment.