Skip to content

Commit 3638a95

Browse files
committed
Adds another repo creation test.
1 parent e770808 commit 3638a95

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
],
3030
"homepage": "https://github.com/ipfs/js-ipfs-repo",
3131
"devDependencies": {
32+
"abstract-blob-store": "^3.2.0",
3233
"aegir": "^2.1.1",
3334
"async": "^1.5.2",
3435
"bl": "^1.1.2",

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const stores = require('./stores')
44

55
function Repo (repoPath, options) {
6+
if (!(this instanceof Repo)) {
7+
return new Repo(repoPath, options)
8+
}
69
if (!options) { throw new Error('missing options param') }
710
if (!options.stores) { throw new Error('missing options.stores param') }
811

test/repo-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
'use strict'
44

5+
const Repo = require('../src/index')
56
const expect = require('chai').expect
67
const base58 = require('bs58')
78
const bl = require('bl')
@@ -14,6 +15,32 @@ const fileAExt = fs.readFileSync(join(__dirname, 'test-repo/blocks/12207028/1220
1415

1516
module.exports = function (repo) {
1617
describe('IPFS Repo Tests', function () {
18+
it('can init repo /wo new', (done) => {
19+
var repo
20+
function run () {
21+
repo = Repo('foo', { stores: require('abstract-blob-store') })
22+
}
23+
expect(run).to.not.throw(Error)
24+
expect(repo).to.be.an.instanceof(Repo)
25+
done()
26+
})
27+
28+
it('bad repo init 1', (done) => {
29+
function run () {
30+
new Repo()
31+
}
32+
expect(run).to.throw(Error)
33+
done()
34+
})
35+
36+
it('bad repo init 2', (done) => {
37+
function run () {
38+
new Repo('', {})
39+
}
40+
expect(run).to.throw(Error)
41+
done()
42+
})
43+
1744
it('check if Repo exists', (done) => {
1845
repo.exists((err, exists) => {
1946
expect(err).to.not.exist

0 commit comments

Comments
 (0)