diff --git a/fs.js b/fs.js index 081e958..fa9eb15 100644 --- a/fs.js +++ b/fs.js @@ -1,13 +1,15 @@ const fs = require('fs') const path = require('path') const once = require('once') -const util = require('util') const createHasher = require('hashes-stream') const isDirectory = dir => fs.statSync(dir).isDirectory() class FileSystemContentAddressableStorage { constructor (dir, algo = 'sha256', _createHasher = createHasher) { + /* This statement is tested but because it gets wrapped in a try/catch + the coverage report doesn't notice. */ + /* istanbul ignore if */ if (!isDirectory(dir)) throw new Error('Not a directory.') this.dir = dir this._algo = algo diff --git a/lib/test-basics.js b/lib/test-basics.js index e2904fa..ff11463 100644 --- a/lib/test-basics.js +++ b/lib/test-basics.js @@ -123,7 +123,4 @@ module.exports = (name, store) => { store.hash('asdf', err => t.type(err, 'Error')) store.hash(1123454, err => t.type(err, 'Error')) }) - - } - diff --git a/package.json b/package.json index ab481d1..6772ca6 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "tests" }, "scripts": { - "test": "tap tests/*.js", + "test": "tap tests/*.js && standard", "cover": "tap tests/*.js --cov --coverage-report=lcov", "precommit": "npm test", "prepush": "npm test", @@ -33,6 +33,7 @@ "husky": "^0.14.3", "rimraf": "^2.6.1", "semantic-release": "^6.3.6", + "standard": "^10.0.2", "validate-commit-msg": "^2.12.2" }, "config": { diff --git a/tests/test-fs.js b/tests/test-fs.js index 52ce4ed..aae2da7 100644 --- a/tests/test-fs.js +++ b/tests/test-fs.js @@ -23,8 +23,7 @@ test('fs(implementation): directory does not exist', t => { test('fs(implementation): hash error in hash()', t => { t.plan(1) - let store = fsStore(testdir) - store._createHasher = failHasher + let store = fsStore(testdir, 'noop', failHasher) store.hash(Buffer.from('asdf'), err => { t.type(err, 'Error') }) @@ -32,8 +31,7 @@ test('fs(implementation): hash error in hash()', t => { test('fs(implementation): hash error in set()', t => { t.plan(2) - let store = fsStore(testdir) - store._createHasher = failHasher + let store = fsStore(testdir, 'noop', failHasher) store.set(Buffer.from('asdf'), err => { t.type(err, 'Error') }) @@ -70,6 +68,21 @@ test('fs(implementation): filesystem errors, fs.writeFile()', t => { }) }) +test('fs(implementation): slow hasher', t => { + t.plan(2) + const slowHasher = (algo, cb) => { + return through(() => setTimeout(() => cb(null, 'asdf'), 100)) + } + let store = fsStore(testdir, 'noop', slowHasher) + let stream = bl() + store.set(stream, (err, hash) => { + t.error(err) + t.equal(hash, 'asdf') + }) + stream.write(Buffer.from('asdf')) + stream.end() +}) + let rimraf = require('rimraf') process.on('beforeExit', () => { diff --git a/tests/test-inmemory.js b/tests/test-inmemory.js index ebe15d2..1d7fabf 100644 --- a/tests/test-inmemory.js +++ b/tests/test-inmemory.js @@ -11,8 +11,7 @@ const failHasher = (algo, cb) => { test('inmemory: (implementation) hash error in hash()', t => { t.plan(1) - let store = inmemory() - store._createHasher = failHasher + let store = inmemory('noop', failHasher) store.hash(Buffer.from('asdf'), err => { t.type(err, 'Error') }) @@ -20,8 +19,7 @@ test('inmemory: (implementation) hash error in hash()', t => { test('inmemory: (implementation) hash error in set()', t => { t.plan(1) - let store = inmemory() - store._createHasher = failHasher + let store = inmemory('noop', failHasher) store.set(Buffer.from('asdf'), err => { t.type(err, 'Error') })