Skip to content

Commit

Permalink
testing default options
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Jun 27, 2017
1 parent 4e53843 commit c455e0e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "IPFS Repo implementation",
"main": "src/index.js",
"browser": {
"rimraf": false,
"datastore-fs": "datastore-level",
"leveldown": "level-js",
"./src/lock.js": "./src/lock-memory.js",
"./src/default-options.js": "./src/default-options-browser.js"
},
Expand Down
1 change: 1 addition & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const series = require('async/series')
const IPFSRepo = require('../src')

describe('IPFS Repo Tests on the Browser', () => {
require('./options-test')
const repo = new IPFSRepo('myrepo')

before((done) => {
Expand Down
2 changes: 2 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const expect = chai.expect
const IPFSRepo = require('../src')

describe('IPFS Repo Tests on on Node.js', () => {
require('./options-test')

const repos = [{
name: 'default',
opts: undefined,
Expand Down
52 changes: 52 additions & 0 deletions test/options-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const path = require('path')
const rimraf = require('rimraf')
if (!rimraf.sync) {
// browser
rimraf.sync = noop
}
const Repo = require('../')

describe('IPFS Repo options Tests', () => {
const repoPath = path.join(__dirname, 'slash', 'path')
after(() => {
rimraf.sync(repoPath)
})

it('missing repoPath', () => {
expect(
() => new Repo()
).to.throw('missing repoPath')
})

it('default options', () => {
const repo = new Repo(repoPath)
expect(repo.options).to.deep.equal(expectedRepoOptions())
})
})

function noop () {}

function expectedRepoOptions () {
const options = {
// packages are exchanged to browser-compatible
// equivalents via package.browser.
fs: require('datastore-fs'),
level: require('leveldown'),
lock: process.browser ? 'memory' : 'fs',
sharding: !process.browser
}

if (process.browser) {
options.fsOptions = {
db: require('leveldown')
}
}

return options
}
11 changes: 0 additions & 11 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ const expect = chai.expect
const series = require('async/series')
const waterfall = require('async/waterfall')

const Repo = require('../src')

module.exports = (repo) => {
describe('IPFS Repo Tests', () => {
describe('new', () => {
it('missing arguments', () => {
expect(
() => new Repo()
).to.throw(Error)
})
})

it('check if Repo exists', (done) => {
repo.exists((err, exists) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -83,7 +73,6 @@ module.exports = (repo) => {
(cb) => repo.open(cb),
(cb) => repo.version.get(cb),
(version, cb) => {
console.log(version)
expect(version).to.exist()
cb()
}
Expand Down

0 comments on commit c455e0e

Please sign in to comment.