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

Commit

Permalink
fix: passing browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Mar 23, 2017
1 parent 993f746 commit 29b2740
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 59 deletions.
2 changes: 0 additions & 2 deletions src/importer/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const DAGLink = dagPB.DAGLink
const DAGNode = dagPB.DAGNode

class DirFlat {

constructor (props) {
this._children = {}
Object.assign(this, props)
Expand Down Expand Up @@ -81,7 +80,6 @@ class DirFlat {
],
callback)
}

}

module.exports = createDirFlat
Expand Down
1 change: 0 additions & 1 deletion src/importer/tree-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,3 @@ function createTreeBuilder (ipldResolver, _options) {
function notEmpty (str) {
return Boolean(str)
}

1 change: 0 additions & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe('IPFS data importing tests on the Browser', function () {
require('./test-consumable-buffer')
require('./test-consumable-hash')
require('./test-hamt')
require('./test-exporter')(repo)
require('./test-importer')(repo)
require('./test-importer-flush')(repo)
require('./test-import-export')(repo)
Expand Down
12 changes: 7 additions & 5 deletions test/test-consumable-hash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const crypto = require('crypto')
const whilst = require('async/whilst')

Expand All @@ -18,15 +20,15 @@ describe('consumable hash', () => {

it('can take a 0 length value', (callback) => {
hash('some value').take(0, (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(result).to.be.eql(0)
callback()
})
})

it('can take a 10 bit value', (callback) => {
hash('some value').take(10, (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(result).to.be.eql(110)
callback()
})
Expand All @@ -39,7 +41,7 @@ describe('consumable hash', () => {
() => iter > 0,
(callback) => {
h.take(10, (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
values.push(result)
expect(result).to.be.below(1024)
expect(result).to.be.above(0)
Expand All @@ -61,7 +63,7 @@ describe('consumable hash', () => {
() => iter > 0,
(callback) => {
h.take(10, (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
values.push(result)
expect(result).to.be.eql(values.shift())
iter--
Expand Down
48 changes: 25 additions & 23 deletions test/test-dirbuilder-sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
const importer = require('./../src').importer
const exporter = require('./../src').exporter

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const mh = require('multihashes')
const expect = require('chai').expect
const BlockService = require('ipfs-block-service')
const IPLDResolver = require('ipld-resolver')
const pull = require('pull-stream')
const pushable = require('pull-pushable')
const whilst = require('async/whilst')
const timers = require('timers')
const setImmediate = require('async/setImmediate')
const leftPad = require('left-pad')

module.exports = (repo) => {
Expand Down Expand Up @@ -40,12 +42,12 @@ module.exports = (repo) => {
]),
importer(ipldResolver, options),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
expect(nodes[0].path).to.be.eql('a/b')
expect(nodes[1].path).to.be.eql('a')
nonShardedHash = nodes[1].multihash
expect(nonShardedHash).to.exist
expect(nonShardedHash).to.exist()
done()
})
)
Expand All @@ -65,7 +67,7 @@ module.exports = (repo) => {
]),
importer(ipldResolver, options),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
expect(nodes[0].path).to.be.eql('a/b')
expect(nodes[1].path).to.be.eql('a')
Expand All @@ -81,7 +83,7 @@ module.exports = (repo) => {
pull(
exporter(nonShardedHash, ipldResolver),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
const expectedHash = mh.toB58String(nonShardedHash)
expect(nodes[0].path).to.be.eql(expectedHash)
Expand All @@ -96,7 +98,7 @@ module.exports = (repo) => {
)

function collected (err, content) {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(content.length).to.be.eql(1)
expect(content[0].toString()).to.be.eql('i have the best bytes')
done()
Expand All @@ -107,7 +109,7 @@ module.exports = (repo) => {
pull(
exporter(shardedHash, ipldResolver),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
const expectedHash = mh.toB58String(shardedHash)
expect(nodes[0].path).to.be.eql(expectedHash)
Expand All @@ -122,7 +124,7 @@ module.exports = (repo) => {
)

function collected (err, content) {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(content.length).to.be.eql(1)
expect(content[0].toString()).to.be.eql('i have the best bytes')
done()
Expand All @@ -140,7 +142,7 @@ module.exports = (repo) => {
push,
importer(ipldResolver),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(maxDirs + 1)
const last = nodes[nodes.length - 1]
expect(last.path).to.be.eql('big')
Expand All @@ -162,10 +164,10 @@ module.exports = (repo) => {
content: pull.values([new Buffer(i.toString())])
}
push.push(pushable)
timers.setTimeout(callback, 1)
setImmediate(callback)
},
(err) => {
expect(err).to.not.exist
expect(err).to.not.exist()
push.end()
}
)
Expand All @@ -188,13 +190,13 @@ module.exports = (repo) => {
}

function collected (err, content) {
expect(err).to.not.exist
expect(err).to.not.exist()
entries[node.path] = { content: content.toString() }
callback(null, node)
}
}),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
const paths = Object.keys(entries).sort()
expect(paths.length).to.be.eql(2001)
paths.forEach(eachPath)
Expand All @@ -207,8 +209,8 @@ module.exports = (repo) => {
// first dir
expect(path).to.be.eql(mh.toB58String(rootHash))
const entry = entries[path]
expect(entry).to.exist
expect(entry.content).to.not.exist
expect(entry).to.exist()
expect(entry.content).to.not.exist()
return
}
// dir entries
Expand All @@ -232,7 +234,7 @@ module.exports = (repo) => {
push,
importer(ipldResolver),
pull.collect((err, nodes) => {
expect(err).to.not.exist
expect(err).to.not.exist()
const last = nodes[nodes.length - 1]
expect(last.path).to.be.eql('big')
rootHash = last.multihash
Expand Down Expand Up @@ -265,10 +267,10 @@ module.exports = (repo) => {
i = 0
depth++
}
timers.setTimeout(callback, 1)
setImmediate(callback)
},
(err) => {
expect(err).to.not.exist
expect(err).to.not.exist()
push.end()
}
)
Expand All @@ -290,7 +292,7 @@ module.exports = (repo) => {
}

function collected (err, content) {
expect(err).to.not.exist
expect(err).to.not.exist()
entries[node.path] = { content: content.toString() }
callback(null, node)
}
Expand All @@ -299,7 +301,7 @@ module.exports = (repo) => {
)

function collected (err, nodes) {
expect(err).to.not.exist
expect(err).to.not.exist()
const paths = Object.keys(entries).sort()
expect(paths.length).to.be.eql(maxDepth * maxDirs + maxDepth)
let index = 0
Expand All @@ -314,8 +316,8 @@ module.exports = (repo) => {
expect(path).to.be.eql(mh.toB58String(rootHash))
}
const entry = entries[path]
expect(entry).to.exist
expect(entry.content).to.not.exist
expect(entry).to.exist()
expect(entry.content).to.not.exist()
} else {
// dir entries
const pathElements = path.split('/')
Expand Down
32 changes: 17 additions & 15 deletions test/test-hamt.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const crypto = require('crypto')
const expect = require('chai').expect
const each = require('async/each')
const eachSeries = require('async/eachSeries')

Expand All @@ -28,8 +30,8 @@ describe('HAMT', () => {

it('get unknown key returns undefined', (callback) => {
bucket.get('unknown', (err, result) => {
expect(err).to.not.exist
expect(result).to.be.undefined
expect(err).to.not.exist()
expect(result).to.be.undefined()
callback()
})
})
Expand All @@ -40,7 +42,7 @@ describe('HAMT', () => {

it('can get that value', (callback) => {
bucket.get('key', (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(result).to.be.eql('value')
callback()
})
Expand All @@ -52,7 +54,7 @@ describe('HAMT', () => {

it('can get that value', (callback) => {
bucket.get('key', (err, result) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(result).to.be.eql('a different value')
callback()
})
Expand All @@ -68,8 +70,8 @@ describe('HAMT', () => {

it('get deleted key returns undefined', (callback) => {
bucket.get('key', (err, result) => {
expect(err).to.not.exist
expect(result).to.be.undefined
expect(err).to.not.exist()
expect(result).to.be.undefined()
callback()
})
})
Expand Down Expand Up @@ -104,19 +106,19 @@ describe('HAMT', () => {
}

bucket.get(head, (err, value) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(value).to.be.eql(head)
bucket.del(head, afterDel)
})

function afterDel (err) {
expect(err).to.not.exist
expect(err).to.not.exist()
bucket.get(head, afterGet)
}

function afterGet (err, value) {
expect(err).to.not.exist
expect(value).to.be.undefined
expect(err).to.not.exist()
expect(value).to.be.undefined()

each(
keys,
Expand All @@ -128,14 +130,14 @@ describe('HAMT', () => {

function onEachKey (key, callback) {
bucket.get(key, (err, value) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(value).to.be.eql(key)
callback()
})
}

function reiterate (err) {
expect(err).to.not.exist
expect(err).to.not.exist()
// break from stack on next iteration
process.nextTick(iterate)
}
Expand All @@ -147,7 +149,7 @@ describe('HAMT', () => {

it('can still find sole head', (callback) => {
bucket.get(masterHead, (err, value) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(value).to.be.eql(masterHead)
callback()
})
Expand All @@ -172,7 +174,7 @@ describe('HAMT', () => {
}

eachSeries(keys, (key, callback) => bucket.put(key, key, callback), (err) => {
expect(err).to.not.exist
expect(err).to.not.exist()
callback()
})
})
Expand Down
Loading

0 comments on commit 29b2740

Please sign in to comment.