From 096bfaee35a8146707ec0ed50c1ccf074a741f56 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 27 Jan 2016 16:40:58 +0000 Subject: [PATCH 1/3] move to latest ipfs-repo --- package.json | 5 +++-- src/ipfs-core/default-repo/browser.js | 2 +- tests/test-core/browser.js | 32 ++++++++++++++++----------- tests/test-core/test-block.js | 1 + 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index d87a42eb7c..67fca4e721 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "lint": "standard", "coverage": "istanbul cover --print both -- _mocha tests/test-*/index.js", - "test": "npm run test:node", + "test": "npm run test:node && npm run test:browser", "test:node": "mocha tests/test-*/index.js", "test:browser": "karma start karma.conf.js", "test:core": "mocha tests/test-core/index.js", @@ -39,6 +39,7 @@ "brfs": "^1.4.3", "chai": "^3.4.1", "fs-blob-store": "^5.2.1", + "idb-plus-blob-store": "^1.0.0", "istanbul": "^0.4.1", "json-loader": "^0.5.4", "karma": "^0.13.19", @@ -66,7 +67,7 @@ "bs58": "^3.0.0", "debug": "^2.2.0", "hapi": "^12.0.0", - "ipfs-repo": "^0.4.1", + "ipfs-repo": "^0.5.0", "ipfs-merkle-dag": "vijayee/js-ipfs-merkle-dag", "lodash.get": "^4.0.0", "lodash.set": "^4.0.0", diff --git a/src/ipfs-core/default-repo/browser.js b/src/ipfs-core/default-repo/browser.js index 5da960b209..42315855cf 100644 --- a/src/ipfs-core/default-repo/browser.js +++ b/src/ipfs-core/default-repo/browser.js @@ -1,6 +1,6 @@ 'use strict' -const localStorage = require('local-storage-blob-store') +const localStorage = require('idb-plus-blob-store') const IPFSRepo = require('ipfs-repo') const options = { diff --git a/tests/test-core/browser.js b/tests/test-core/browser.js index d72ed845b3..3d03ee511a 100644 --- a/tests/test-core/browser.js +++ b/tests/test-core/browser.js @@ -1,38 +1,44 @@ /* globals describe, before */ -// const expect = require('chai').expect const async = require('async') -const store = require('local-storage-blob-store') +const store = require('idb-plus-blob-store') const _ = require('lodash') -var repoContext = require.context('binary!../repo-example', true) +const repoContext = require.context('raw!./../repo-example', true) -describe('core', function () { - before(function (done) { - window.localStorage.clear() +const idb = window.indexedDB || + window.mozIndexedDB || + window.webkitIndexedDB || + window.msIndexedDB + +idb.deleteDatabase('ipfs') +idb.deleteDatabase('ipfs/blocks') +describe('IPFS Repo Tests on the Browser', function () { + before(function (done) { var repoData = [] repoContext.keys().forEach(function (key) { repoData.push({ key: key.replace('./', ''), - value: new Buffer(require('binary!./../repo-example/' + key.replace('./', '')), 'binary') + value: repoContext(key) }) }) - var mainBlob = store('ipfs') - var blocksBlob = store('ipfs/') + const mainBlob = store('ipfs') + const blocksBlob = store('ipfs/blocks') async.eachSeries(repoData, (file, cb) => { if (_.startsWith(file.key, 'datastore/')) { return cb() } - const blob = _.startsWith(file.key, 'blocks/') - ? blocksBlob - : mainBlob + const blocks = _.startsWith(file.key, 'blocks/') + const blob = blocks ? blocksBlob : mainBlob + + const key = blocks ? file.key.replace(/^blocks\//, '') : file.key blob.createWriteStream({ - key: file.key + key: key }).end(file.value, cb) }, done) }) diff --git a/tests/test-core/test-block.js b/tests/test-core/test-block.js index faa7090992..b4f3b54de0 100644 --- a/tests/test-core/test-block.js +++ b/tests/test-core/test-block.js @@ -27,6 +27,7 @@ describe('block', () => { ipfs.block.get(mh, (err, block) => { expect(err).to.not.exist const eq = fileA.equals(block.data) + console.log(block) expect(eq).to.equal(true) done() }) From 2a2699f985cb535f529d6a2e32c5f041ad6215c3 Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Thu, 28 Jan 2016 11:43:01 +0000 Subject: [PATCH 2/3] Use buffer-loader for tests --- package.json | 3 +-- tests/test-core/browser.js | 2 +- tests/test-core/test-block.js | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 67fca4e721..a9cf32c707 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { "async": "^1.5.2", - "binary-loader": "0.0.1", "brfs": "^1.4.3", + "buffer-loader": "0.0.1", "chai": "^3.4.1", "fs-blob-store": "^5.2.1", "idb-plus-blob-store": "^1.0.0", @@ -55,7 +55,6 @@ "ncp": "^2.0.0", "nexpect": "^0.5.0", "pre-commit": "^1.1.2", - "raw-loader": "^0.5.1", "rimraf": "^2.4.4", "standard": "^5.4.1", "transform-loader": "^0.2.3", diff --git a/tests/test-core/browser.js b/tests/test-core/browser.js index 3d03ee511a..aff5aa7833 100644 --- a/tests/test-core/browser.js +++ b/tests/test-core/browser.js @@ -4,7 +4,7 @@ const async = require('async') const store = require('idb-plus-blob-store') const _ = require('lodash') -const repoContext = require.context('raw!./../repo-example', true) +const repoContext = require.context('buffer!./../repo-example', true) const idb = window.indexedDB || window.mozIndexedDB || diff --git a/tests/test-core/test-block.js b/tests/test-core/test-block.js index b4f3b54de0..6ea044fc1d 100644 --- a/tests/test-core/test-block.js +++ b/tests/test-core/test-block.js @@ -10,9 +10,12 @@ const Block = require('ipfs-merkle-dag').Block const isNode = !global.window +// FIXME remove this (it is only here because otherwise webpack is not loading Buffer and it is needed to the tests bellow) +const noop = new Buffer([]) // eslint-disable-line + const fileA = isNode ? fs.readFileSync(process.cwd() + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') - : new Buffer(require('binary!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data'), 'binary') + : require('buffer!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') // console.log('=>', fileA) // console.log('=>', fileA.length) @@ -27,7 +30,6 @@ describe('block', () => { ipfs.block.get(mh, (err, block) => { expect(err).to.not.exist const eq = fileA.equals(block.data) - console.log(block) expect(eq).to.equal(true) done() }) From b97133731a3202660aed66fdd8e779cd19e119d2 Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Thu, 28 Jan 2016 14:16:54 +0000 Subject: [PATCH 3/3] Use regular functions on tests that use Buffer --- tests/test-core/test-block.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/test-core/test-block.js b/tests/test-core/test-block.js index 6ea044fc1d..a2c19b979b 100644 --- a/tests/test-core/test-block.js +++ b/tests/test-core/test-block.js @@ -10,20 +10,15 @@ const Block = require('ipfs-merkle-dag').Block const isNode = !global.window -// FIXME remove this (it is only here because otherwise webpack is not loading Buffer and it is needed to the tests bellow) -const noop = new Buffer([]) // eslint-disable-line - const fileA = isNode ? fs.readFileSync(process.cwd() + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') : require('buffer!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') -// console.log('=>', fileA) -// console.log('=>', fileA.length) - -describe('block', () => { +// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed +describe('block', function () { var ipfs - it('get', done => { + it('get', function (done) { ipfs = new IPFS() const b58mh = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe' const mh = new Buffer(base58.decode(b58mh)) @@ -64,7 +59,7 @@ describe('block', () => { }) }) - it('stat', done => { + it('stat', function (done) { const mh = new Buffer(base58 .decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe')) ipfs.block.stat(mh, (err, stats) => {