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

test: refactor for test sanity #733

Merged
merged 1 commit into from
Jan 28, 2017
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
1 change: 0 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ module.exports = {
}]
}
}

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"libp2p-ipfs-nodejs": "libp2p-ipfs-browser",
"./src/core/default-repo.js": "./src/core/default-repo-browser.js",
"./src/core/components/init-assets.js": false,
"./test/utils/temp-repo.js": "./test/utils/temp-repo-browser.js",
"./test/utils/create-repo-node.js": "./test/utils/create-repo-browser.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this just be create-repo rather?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could, I just standardize it because we always tag node and browser everywhere to distinguish the two, if distinction needs to happen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

"stream": "readable-stream"
},
"go-ipfs": {
Expand Down Expand Up @@ -170,4 +170,4 @@
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
3 changes: 0 additions & 3 deletions test/browser.js

This file was deleted.

37 changes: 23 additions & 14 deletions test/core/both/test-bitswap.js → test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const API = require('ipfs-api')
const multiaddr = require('multiaddr')
const isNode = require('detect-node')

const IPFS = require('../../../src/core')
// This gets replaced by require('../utils/create-repo-browser.js')
// in the browser
const createTempRepo = require('../utils/create-repo-node.js')

const IPFS = require('../../src/core')

function makeBlock (cb) {
return cb(null, new Block(`IPFS is awesome ${Math.random()}`))
Expand All @@ -27,19 +31,24 @@ describe('bitswap', () => {
let swarmAddrsBak

beforeEach((done) => {
inProcNode = new IPFS(require('../../utils/repo-path'))
if (!isNode) {
inProcNode.config.get('Addresses.Swarm', (err, swarmAddrs) => {
expect(err).to.not.exist
swarmAddrsBak = swarmAddrs
inProcNode.config.set('Addresses.Swarm', [], (err) => {
expect(err).to.not.exist
inProcNode.load(done)
})
})
} else {
inProcNode.load(done)
}
const repo = createTempRepo()
inProcNode = new IPFS(repo)
series([
(cb) => inProcNode.init({ bits: 2048 }, cb),
(cb) => {
if (!isNode) {
inProcNode.config.get('Addresses.Swarm', (err, swarmAddrs) => {
expect(err).to.not.exist
swarmAddrsBak = swarmAddrs
inProcNode.config.set('Addresses.Swarm', [], cb)
})
} else {
cb()
}
},
(cb) => inProcNode.config.set('Discovery.MDNS.Enabled', false, cb),
(cb) => inProcNode.load(cb)
], done)
})

afterEach((done) => {
Expand Down
20 changes: 16 additions & 4 deletions test/core/both/test-bootstrap.js → test/core/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@
'use strict'

const expect = require('chai').expect
const isNode = require('detect-node')
const series = require('async/series')

const IPFS = require('../../../src/core')
// This gets replaced by require('../utils/create-repo-browser.js')
// in the browser
const createTempRepo = require('../utils/create-repo-node.js')

const IPFS = require('../../src/core')

describe('bootstrap', () => {
var ipfs
if (!isNode) { return }

let ipfs

before((done) => {
ipfs = new IPFS(require('../../utils/repo-path'))
ipfs.load(done)
const repo = createTempRepo()
ipfs = new IPFS(repo)
series([
(cb) => ipfs.init({ bits: 1024 }, cb),
(cb) => ipfs.load(cb)
], done)
})

const defaultList = [
Expand Down
13 changes: 0 additions & 13 deletions test/core/both/index.js

This file was deleted.

59 changes: 0 additions & 59 deletions test/core/both/test-init.js

This file was deleted.

6 changes: 0 additions & 6 deletions test/core/browser-only/index.js

This file was deleted.

1 change: 0 additions & 1 deletion test/core/browser-only/test-swarm.js

This file was deleted.

51 changes: 0 additions & 51 deletions test/core/browser.js

This file was deleted.

81 changes: 81 additions & 0 deletions test/core/init.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const isNode = require('detect-node')
const IPFS = require('../../src/core')

// This gets replaced by require('../utils/create-repo-browser.js')
// in the browser
const createTempRepo = require('../utils/create-repo-node.js')

describe('init', () => {
if (!isNode) { return }

let ipfs
let repo

beforeEach(() => {
repo = createTempRepo()
ipfs = new IPFS(repo)
})

afterEach((done) => repo.teardown(done))

it('basic', (done) => {
ipfs.init({ bits: 1024 }, (err) => {
expect(err).to.not.exist

repo.exists((err, res) => {
expect(err).to.not.exist
expect(res).to.equal(true)

repo.config.get((err, config) => {
expect(err).to.not.exist
expect(config.Identity).to.exist
done()
})
})
})
})

it('set # of bits in key', (done) => {
ipfs.init({ bits: 2048 }, (err) => {
expect(err).to.not.exist

repo.config.get((err, config) => {
expect(err).to.not.exist
expect(config.Identity.PrivKey.length).is.above(256)
done()
})
})
})

it('init docs are written', (done) => {
ipfs.init({ bits: 1024 }, (err) => {
expect(err).to.not.exist
const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')

ipfs.object.get(multihash, {}, (err, node) => {
expect(err).to.not.exist
expect(node.links).to.exist
done()
})
})
})

it('empty repo', (done) => {
ipfs.init({ bits: 1024, emptyRepo: true }, (err) => {
expect(err).to.not.exist

// Should not have default assets
const multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')

ipfs.object.get(multihash, {}, (err, node) => {
expect(err).to.exist
done()
})
})
})
})
17 changes: 17 additions & 0 deletions test/core/interface/interface.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-env mocha */

'use strict'

const isNode = require('detect-node')

describe('interface-ipfs-core tests', () => {
require('./block')
require('./config')
require('./files')
require('./generic')
require('./object')
if (isNode) {
require('./swarm')
require('./pubsub')
}
})
36 changes: 0 additions & 36 deletions test/core/node-only/index.js

This file was deleted.

Loading