Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e5ddc7f175fa^
Choose a base ref
...
head repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0c31e40f4d9d
Choose a head ref
  • 11 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 19, 2015

  1. Copy the full SHA
    e5ddc7f View commit details
  2. Copy the full SHA
    700d6f6 View commit details
  3. Ready for travis

    dignifiedquire committed Oct 19, 2015
    Copy the full SHA
    a184f1a View commit details
  4. Fix path

    dignifiedquire committed Oct 19, 2015
    Copy the full SHA
    105fb32 View commit details

Commits on Oct 20, 2015

  1. another try

    dignifiedquire committed Oct 20, 2015
    Copy the full SHA
    1934220 View commit details
  2. fix

    dignifiedquire committed Oct 20, 2015
    Copy the full SHA
    2ea7f73 View commit details
  3. fix

    dignifiedquire committed Oct 20, 2015
    Copy the full SHA
    dc39d98 View commit details
  4. fix3

    dignifiedquire committed Oct 20, 2015
    Copy the full SHA
    1665b27 View commit details

Commits on Oct 21, 2015

  1. Add saucelabs support

    dignifiedquire committed Oct 21, 2015
    Copy the full SHA
    11b07d3 View commit details
  2. Remove debugging cmd

    dignifiedquire committed Oct 21, 2015
    Copy the full SHA
    6ddd117 View commit details
  3. Copy the full SHA
    0c31e40 View commit details
Showing with 173 additions and 43 deletions.
  1. +4 −0 .travis.yml
  2. +75 −0 karma.conf.js
  3. +11 −2 package.json
  4. +83 −41 test/test.js
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
node_js:
- "4.0"

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
75 changes: 75 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module.exports = function (config) {
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.')
process.exit(1)
}

// Browsers to run on Sauce Labs
// Check out https://saucelabs.com/platforms for all browser/OS combos
var customLaunchers = {
'SL_Chrome': {
base: 'SauceLabs',
platform: 'OS X 10.11',
browserName: 'chrome'
},
'SL_Firefox': {
base: 'SauceLabs',
platform: 'OS X 10.11',
browserName: 'firefox'
},
'SL_Safari': {
base: 'SauceLabs',
platform: 'OS X 10.11',
browserName: 'safari'
},
'SL_Edge': {
base: 'SauceLabs',
platform: 'Windows 10',
browserName: 'microsoftedge'
},
'SL_IE11': {
base: 'SauceLabs',
platform: 'Windows 10',
browserName: 'internet explorer',
version: '11.0'
}
}

config.set({
basePath: '',
frameworks: ['browserify', 'mocha'],
files: [
'test/test.js'
],
exclude: [],
preprocessors: {
'test/**/*.js': ['browserify']
},

browserify: {
debug: true,
transform: [
'brfs'
]
},

sauceLabs: {
testName: 'node-ipfs-api',
recordScreenshots: false,
connectOptions: {
port: 5757,
logfile: 'sauce_connect.log'
}
},

reporters: ['progress', 'saucelabs'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
customLaunchers: customLaunchers,
browsers: Object.keys(customLaunchers),
singleRun: false,
concurrency: 2
})
}
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -25,15 +25,24 @@
"url": "https://github.com/ipfs/node-ipfs-api"
},
"devDependencies": {
"brfs": "^1.4.1",
"browserify": "^11.0.0",
"concurrently": "^0.1.1",
"go-ipfs": "^0.3.7-3",
"ipfsd-ctl": "^0.5.1",
"mocha": "^2.2.5",
"karma": "^0.13.11",
"karma-browserify": "^4.4.0",
"karma-mocha": "^0.2.0",
"karma-sauce-launcher": "^0.3.0",
"mocha": "^2.3.3",
"pre-commit": "^1.0.6",
"standard": "^5.2.2",
"uglify-js": "^2.4.24"
},
"scripts": {
"test": "./node_modules/.bin/mocha",
"test": "npm run test:node && npm run test:browser",
"test:node": "./node_modules/.bin/mocha",
"test:browser": "./node_modules/.bin/ipfs init && API_ORIGIN=\"*\" ./node_modules/.bin/concurrent --kill-others \"./node_modules/.bin/ipfs daemon\" \"./node_modules/.bin/karma start --single-run=true karma.conf.js\"",
"lint": "./node_modules/.bin/standard",
"build": "./node_modules/.bin/browserify -t brfs -s ipfsAPI -e ./src/index.js | tee dist/ipfsapi.js | ./node_modules/.bin/uglifyjs -m > dist/ipfsapi.min.js"
},
124 changes: 83 additions & 41 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
var ipfsd = require('ipfsd-ctl')
var isNode = !global.window

var ipfsApi = require('../src/index.js')
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var File = require('vinyl')

if (isNode) {
var ipfsd = require('ipfsd-ctl')
}

// this comment is used by mocha, do not delete
/*global describe, before, it*/

@@ -14,27 +19,33 @@ function log () {
console.log.apply(console, args)
}

var testfile = __dirname + '/testfile.txt'
var testfilePath = __dirname + '/testfile.txt'
var testfile = fs.readFileSync(__dirname + '/testfile.txt')

describe('ipfs node api', function () {
var ipfs, ipfsNode
before(function (done) {
this.timeout(20000)
log('ipfs node setup')

ipfsd.disposable(function (err, node) {
if (err) throw err
log('ipfs init done')
ipfsNode = node

ipfsNode.startDaemon(function (err, ignore) {
if (isNode) {
this.timeout(20000)
ipfsd.disposable(function (err, node) {
if (err) throw err
log('ipfs daemon running')
log('ipfs init done')
ipfsNode = node

ipfs = ipfsApi(ipfsNode.apiAddr)
done()
ipfsNode.startDaemon(function (err, ignore) {
if (err) throw err
log('ipfs daemon running')

ipfs = ipfsApi(ipfsNode.apiAddr)
done()
})
})
})
} else {
ipfs = ipfsApi('localhost', '5001')
done()
}
})

it('has the api object', function () {
@@ -46,42 +57,44 @@ describe('ipfs node api', function () {
this.timeout(10000)

var file = new File({
cwd: path.dirname(testfile),
base: path.dirname(testfile),
path: testfile,
contents: fs.createReadStream(testfile)
cwd: path.dirname(testfilePath),
base: path.dirname(testfilePath),
path: testfilePath,
contents: new Buffer(testfile)
})

ipfs.add(file, function (err, res) {
if (err) throw err

var added = res[0]
var added = res[0] != null ? res[0] : res
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
assert.equal(added.Name, path.basename(testfile))
assert.equal(added.Name, path.basename(testfilePath))
done()
})
})

it('add buffer', function (done) {
this.timeout(10000)

var buf = new Buffer(fs.readFileSync(testfile))
var buf = new Buffer(testfile)
ipfs.add(buf, function (err, res) {
if (err) throw err

assert.equal(res.length, 1)
assert.equal(res[0].Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
// assert.equal(res.length, 1)
var added = res[0] != null ? res[0] : res
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
done()
})
})

// Not working due to fs.lstat not being available in the browser
it('add path', function (done) {
this.timeout(10000)

ipfs.add(testfile, function (err, res) {
ipfs.add(testfilePath, function (err, res) {
if (err) throw err

var added = res[0]
var added = res[0] != null ? res[0] : res
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
done()
})
@@ -90,14 +103,22 @@ describe('ipfs node api', function () {
it('cat', function (done) {
this.timeout(10000)

ipfs.cat('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', function (err, stream) {
ipfs.cat('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', function (err, res) {
if (err) throw err

if (typeof res === 'string') {
// Just a string
assert.equal(res, testfile)
done()
return
}

var buf = ''
stream
res
.on('error', function (err) { throw err })
.on('data', function (data) { buf += data })
.on('end', function () {
assert.equal(buf, fs.readFileSync(testfile))
assert.equal(buf, testfile)
done()
})
})
@@ -185,6 +206,14 @@ describe('ipfs node api', function () {

ipfs.block.get(blorbKey, function (err, res) {
if (err) throw err

if (typeof res === 'string') {
// Just a string
assert.equal(res, 'blorb')
done()
return
}

var buf = ''
res
.on('data', function (data) { buf += data })
@@ -220,10 +249,18 @@ describe('ipfs node api', function () {

it('object.data', function (done) {
this.timeout(10000)
ipfs.object.data(testObjectHash, function (err, stream) {
ipfs.object.data(testObjectHash, function (err, res) {
if (err) throw err

if (typeof res === 'string') {
// Just a string
assert.equal(res, 'testdata')
done()
return
}

var buf = ''
stream
res
.on('error', function (err) { throw err })
.on('data', function (data) { buf += data })
.on('end', function () {
@@ -260,6 +297,7 @@ describe('ipfs node api', function () {
})
})

// No idea why this fails
it('returns an error when getting a non-existent key from the DHT',
function (done) {
this.timeout(20000)
@@ -269,6 +307,7 @@ describe('ipfs node api', function () {
})
})

// No idea why this fails
it('puts and gets a key value pair in the DHT', function (done) {
this.timeout(20000)

@@ -287,17 +326,20 @@ describe('ipfs node api', function () {
})
})

it('test for error after daemon stops', function (done) {
this.timeout(6000)
var nodeStopped
ipfsNode.stopDaemon(function () {
if (!nodeStopped) {
nodeStopped = true
ipfs.id(function (err, res) {
assert.equal(err.code, 'ECONNREFUSED')
done()
})
}
if (isNode) {
// Not available in the browser
it('test for error after daemon stops', function (done) {
this.timeout(6000)
var nodeStopped
ipfsNode.stopDaemon(function () {
if (!nodeStopped) {
nodeStopped = true
ipfs.id(function (err, res) {
assert.equal(err.code, 'ECONNREFUSED')
done()
})
}
})
})
})
}
})