This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from noffle/tests-setup-teardown
moves temp-repo creation into its own module
- Loading branch information
Showing
3 changed files
with
62 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const IPFSRepo = require('ipfs-repo') | ||
|
||
function createTempRepo () { | ||
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' | ||
|
||
var store | ||
var teardown | ||
|
||
const isNode = !global.window | ||
if (isNode) { | ||
store = require('fs-blob-store') | ||
teardown = (done) => { | ||
const rimraf = require('rimraf') | ||
rimraf(repoPath, (err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
} | ||
} else { | ||
const idb = window.indexedDB || | ||
window.mozIndexedDB || | ||
window.webkitIndexedDB || | ||
window.msIndexedDB | ||
store = require('idb-plus-blob-store') | ||
teardown = (done) => { | ||
idb.deleteDatabase(repoPath) | ||
idb.deleteDatabase(repoPath + '/blocks') | ||
done() | ||
} | ||
} | ||
|
||
const options = { | ||
bits: 64, | ||
stores: { | ||
keys: store, | ||
config: store, | ||
datastore: store, | ||
logs: store, | ||
locks: store, | ||
version: store | ||
} | ||
} | ||
|
||
var repo = new IPFSRepo(repoPath, options) | ||
|
||
repo.teardown = teardown | ||
|
||
return repo | ||
} | ||
|
||
module.exports = createTempRepo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters