From e9ac8b0efa091acde374b75540d6684b8a6a22e5 Mon Sep 17 00:00:00 2001 From: tcme Date: Sat, 2 Sep 2017 12:40:03 +0200 Subject: [PATCH 01/18] chrore: adds .appveryor.yml --- .appveyor.yml | 23 +++++++++++++++++++++++ test/index.spec.js | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 00000000..de3e3780 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,23 @@ +environment: + matrix: + - nodejs_version: "6" + - nodejs_version: "8" + +# cache: +# - node_modules + +platform: + - x64 + +install: + - ps: Install-Product node $env:nodejs_version $env:platform + - npm install + +test_script: + - node --version + - npm --version + - npm test + +build: off + +version: "{build}" diff --git a/test/index.spec.js b/test/index.spec.js index ebf06960..c6bebbfc 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -37,7 +37,7 @@ describe('ipfs executable path', () => { Node = require('../src/node.js') var node = new Node() expect(node.exec) - .to.eql('/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs') + .to.eql(path.normalize('/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs')) rimraf('/tmp/ipfsd-ctl-test', done) }) }) @@ -58,7 +58,7 @@ describe('ipfs executable path', () => { expect( node.exec ).to.be.eql( - '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs' + path.normalize('/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs') ) rimraf('/tmp/ipfsd-ctl-test', done) }) From c641866c2e6d0606db18138c7df95402e6e0aa4e Mon Sep 17 00:00:00 2001 From: thisconnect Date: Thu, 22 Jun 2017 11:03:26 +0200 Subject: [PATCH 02/18] replaces path to .asar.unpacked if cmd includes .asar/node_modules --- src/exec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/exec.js b/src/exec.js index 3830c3f0..25596e33 100644 --- a/src/exec.js +++ b/src/exec.js @@ -47,6 +47,15 @@ function exec (cmd, args, opts, handlers) { }) } + // If inside .asar try to load from .asar.unpacked + // this only works if asar was built with + // asar --unpack-dir=node_modules/go-ipfs-dep/** + // or + // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/** + if (cmd.includes('.asar/node_modules')) { + cmd = cmd.replace('.asar/node_modules', '.asar.unpacked/node_modules') + } + const command = run(cmd, args, opts) if (listeners.data) { From 03ea8d538e141aa2bafb2ace81771f948684c03d Mon Sep 17 00:00:00 2001 From: thisconnect Date: Sun, 2 Jul 2017 20:05:07 +0200 Subject: [PATCH 03/18] moves asar detection and win fix --- src/exec.js | 9 --------- src/node.js | 13 +++++++++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/exec.js b/src/exec.js index 25596e33..3830c3f0 100644 --- a/src/exec.js +++ b/src/exec.js @@ -47,15 +47,6 @@ function exec (cmd, args, opts, handlers) { }) } - // If inside .asar try to load from .asar.unpacked - // this only works if asar was built with - // asar --unpack-dir=node_modules/go-ipfs-dep/** - // or - // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/** - if (cmd.includes('.asar/node_modules')) { - cmd = cmd.replace('.asar/node_modules', '.asar.unpacked/node_modules') - } - const command = run(cmd, args, opts) if (listeners.data) { diff --git a/src/node.js b/src/node.js index 3bad47f4..09233787 100644 --- a/src/node.js +++ b/src/node.js @@ -19,8 +19,17 @@ const GRACE_PERIOD = 7500 // amount of ms to wait before sigkill function findIpfsExecutable () { const rootPath = process.env.testpath ? process.env.testpath : __dirname - const appRoot = path.join(rootPath, '..') - const depPath = path.join('go-ipfs-dep', 'go-ipfs', 'ipfs') + let appRoot = path.join(rootPath, '..') + // If inside .asar try to load from .asar.unpacked + // this only works if asar was built with + // asar --unpack-dir=node_modules/go-ipfs-dep/* (not tested) + // or + // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/* + if ( appRoot.includes(`.asar${path.sep}`) ) { + appPath = appPath.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) + } + const ipfsExecutable = os.platform() === 'win32' ? 'ipfs.exe' : 'ipfs' + const depPath = path.join('go-ipfs-dep', 'go-ipfs', ipfsExecutable) const npm3Path = path.join(appRoot, '../', depPath) const npm2Path = path.join(appRoot, 'node_modules', depPath) From 60fa9387daf607c8cb6507afd1c0d820f1c6bb20 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Sun, 2 Jul 2017 20:17:58 +0200 Subject: [PATCH 04/18] should be appRoot --- src/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 09233787..1e6df4c3 100644 --- a/src/node.js +++ b/src/node.js @@ -26,7 +26,7 @@ function findIpfsExecutable () { // or // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/* if ( appRoot.includes(`.asar${path.sep}`) ) { - appPath = appPath.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) + appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) } const ipfsExecutable = os.platform() === 'win32' ? 'ipfs.exe' : 'ipfs' const depPath = path.join('go-ipfs-dep', 'go-ipfs', ipfsExecutable) From a6b1347e98cd830648bfbaaead480f2e0da77bea Mon Sep 17 00:00:00 2001 From: thisconnect Date: Sun, 2 Jul 2017 20:25:03 +0200 Subject: [PATCH 05/18] forgot os --- src/node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node.js b/src/node.js index 1e6df4c3..5cbbd2e1 100644 --- a/src/node.js +++ b/src/node.js @@ -6,6 +6,7 @@ const ipfs = require('ipfs-api') const multiaddr = require('multiaddr') const rimraf = require('rimraf') const shutdown = require('shutdown') +const os = require('os') const path = require('path') const join = path.join const once = require('once') From 9f53ce8ba8fdfbca1b07f989a44a0321bdd3bf5d Mon Sep 17 00:00:00 2001 From: tcme Date: Sun, 2 Jul 2017 20:49:35 +0200 Subject: [PATCH 06/18] lints --- src/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 5cbbd2e1..3a16572c 100644 --- a/src/node.js +++ b/src/node.js @@ -26,7 +26,7 @@ function findIpfsExecutable () { // asar --unpack-dir=node_modules/go-ipfs-dep/* (not tested) // or // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/* - if ( appRoot.includes(`.asar${path.sep}`) ) { + if (appRoot.includes(`.asar${path.sep}`)) { appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) } const ipfsExecutable = os.platform() === 'win32' ? 'ipfs.exe' : 'ipfs' From 1b9dcf84c1529f02df66c0d13a16dca99c341618 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 3 Jul 2017 10:22:35 +0200 Subject: [PATCH 07/18] updates comment electron-packager with asar.unpackDir without wildcard (tested macos and win32) --- src/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 3a16572c..e7f10431 100644 --- a/src/node.js +++ b/src/node.js @@ -25,7 +25,7 @@ function findIpfsExecutable () { // this only works if asar was built with // asar --unpack-dir=node_modules/go-ipfs-dep/* (not tested) // or - // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep/* + // electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep if (appRoot.includes(`.asar${path.sep}`)) { appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) } From 279f58f221fc3601f652ff1c131373110c3d5c44 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 09:25:22 +0200 Subject: [PATCH 08/18] removes .exe in executable path on windos --- src/node.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/node.js b/src/node.js index e7f10431..9c409767 100644 --- a/src/node.js +++ b/src/node.js @@ -6,7 +6,6 @@ const ipfs = require('ipfs-api') const multiaddr = require('multiaddr') const rimraf = require('rimraf') const shutdown = require('shutdown') -const os = require('os') const path = require('path') const join = path.join const once = require('once') @@ -29,8 +28,7 @@ function findIpfsExecutable () { if (appRoot.includes(`.asar${path.sep}`)) { appRoot = appRoot.replace(`.asar${path.sep}`, `.asar.unpacked${path.sep}`) } - const ipfsExecutable = os.platform() === 'win32' ? 'ipfs.exe' : 'ipfs' - const depPath = path.join('go-ipfs-dep', 'go-ipfs', ipfsExecutable) + const depPath = path.join('go-ipfs-dep', 'go-ipfs', 'ipfs') const npm3Path = path.join(appRoot, '../', depPath) const npm2Path = path.join(appRoot, 'node_modules', depPath) From 3fc9347d11264faa0e37b0c9b5108fd5d81e0760 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 10:26:00 +0200 Subject: [PATCH 09/18] tests ipfs-api version response length and first item --- test/index.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index c6bebbfc..e01fb11d 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -390,10 +390,17 @@ describe('daemons', () => { if (err) throw err const added = res[res.length - 1] + expect(res.length).to.equal(2) + expect(added).to.have.property('path', 'fixtures') expect(added).to.have.property( 'hash', 'QmXkiTdnfRJjiQREtF5dWf2X4V9awNHQSn9YGofwVY4qUU' ) + expect(res[0]).to.have.property('path', 'fixtures/test.txt') + expect(res[0]).to.have.property( + 'hash', + 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD' + ) done() }) }) From 135dca49fb07b833669842ef30437a330e98a108 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 10:51:30 +0200 Subject: [PATCH 10/18] checks response of ipfs.util.addFromFs for windows --- test/index.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index e01fb11d..e674232e 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -401,6 +401,18 @@ describe('daemons', () => { 'hash', 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD' ) + expect(res).to.deep.equal([ + { + path: 'fixtures/test.txt', + hash: 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD', + size: 19 + }, + { + path: 'fixtures', + hash: 'QmXkiTdnfRJjiQREtF5dWf2X4V9awNHQSn9YGofwVY4qUU', + size: 73 + } + ]) done() }) }) From 46c422ebf1f5b11acecf81da74a553fbab4093d5 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 11:08:17 +0200 Subject: [PATCH 11/18] checks response of ipfs.util.addFromFs for windows again --- test/index.spec.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index e674232e..968c7791 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -390,17 +390,8 @@ describe('daemons', () => { if (err) throw err const added = res[res.length - 1] - expect(res.length).to.equal(2) - expect(added).to.have.property('path', 'fixtures') - expect(added).to.have.property( - 'hash', - 'QmXkiTdnfRJjiQREtF5dWf2X4V9awNHQSn9YGofwVY4qUU' - ) - expect(res[0]).to.have.property('path', 'fixtures/test.txt') - expect(res[0]).to.have.property( - 'hash', - 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD' - ) + + // Temporary: Need to see what is going on on windows expect(res).to.deep.equal([ { path: 'fixtures/test.txt', @@ -413,6 +404,18 @@ describe('daemons', () => { size: 73 } ]) + + expect(res.length).to.equal(2) + expect(added).to.have.property('path', 'fixtures') + expect(added).to.have.property( + 'hash', + 'QmXkiTdnfRJjiQREtF5dWf2X4V9awNHQSn9YGofwVY4qUU' + ) + expect(res[0]).to.have.property('path', 'fixtures/test.txt') + expect(res[0]).to.have.property( + 'hash', + 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD' + ) done() }) }) From 92841df17efa31ed9f77802a013794a643fec36b Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 15:40:12 +0200 Subject: [PATCH 12/18] adds info about packaging with asar and electron-asar example --- README.md | 15 +++++++++++ examples/electron-asar/.gitignore | 2 ++ examples/electron-asar/app.js | 33 ++++++++++++++++++++++++ examples/electron-asar/package.json | 16 ++++++++++++ examples/electron-asar/public/index.html | 21 +++++++++++++++ examples/electron-asar/readme.md | 6 +++++ 6 files changed, 93 insertions(+) create mode 100644 examples/electron-asar/.gitignore create mode 100644 examples/electron-asar/app.js create mode 100644 examples/electron-asar/package.json create mode 100644 examples/electron-asar/public/index.html create mode 100644 examples/electron-asar/readme.md diff --git a/README.md b/README.md index de87c919..6e972541 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,21 @@ If you need want to use an existing ipfs installation you can set `$IPFS_EXEC=/p For more details see https://ipfs.github.io/js-ipfsd-ctl/. +### Packaging + +`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary +has to be excluded from asar (Electron Archives), +[read more about unpack files from asar](https://electron.atom.io/docs/tutorial/application-packaging/#adding-unpacked-files-in-asar-archive). +`ipfsd-ctl` will try to detect if used from within an `app.asar` archive +and tries to resolve ipfs from `app.asar.unpacked`. The ipfs binary is part of +the `go-ipfs-dep` module. + +```bash +electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep +``` + +See [electron asar example](https://github.com/ipfs/js-ipfsd-ctl/tree/master/examples/electron-asar/) + ## Contribute Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfsd-ctl/issues)! diff --git a/examples/electron-asar/.gitignore b/examples/electron-asar/.gitignore new file mode 100644 index 00000000..6b1514c3 --- /dev/null +++ b/examples/electron-asar/.gitignore @@ -0,0 +1,2 @@ +node_modules +test-ipfs-app* diff --git a/examples/electron-asar/app.js b/examples/electron-asar/app.js new file mode 100644 index 00000000..d8f8c73b --- /dev/null +++ b/examples/electron-asar/app.js @@ -0,0 +1,33 @@ +'use strict' + +const { app, ipcMain, BrowserWindow } = require('electron') +const ipfsd = require('ipfsd-ctl') + +app.on('ready', () => { + const win = new BrowserWindow({ + title: 'loading' + }) + win.loadURL(`file://${app.getAppPath()}/public/index.html`) +}) + +ipcMain.on('start', ({ sender }) => { + console.log('starting disposable IPFS') + sender.send('message', 'starting disposable IPFS') + + ipfsd.disposableApi((err, ipfs) => { + if (err) { + sender.send('error', err) + throw err + } + console.log('get id') + sender.send('message', 'get id') + ipfs.id(function (err, id) { + if (err) { + sender.send('error', err) + throw err + } + console.log('got id', id) + sender.send('id', JSON.stringify(id)) + }) + }) +}) diff --git a/examples/electron-asar/package.json b/examples/electron-asar/package.json new file mode 100644 index 00000000..6321e85c --- /dev/null +++ b/examples/electron-asar/package.json @@ -0,0 +1,16 @@ +{ + "name": "test-ipfs-app", + "private": true, + "main": "./app.js", + "dependencies": { + "ipfsd-ctl": "thisconnect/js-ipfsd-ctl#asar-unpacked" + }, + "devDependencies": { + "electron": "^1.7.6", + "electron-packager": "^9.0.0" + }, + "scripts": { + "start": "electron .", + "package": "electron-packager ./ --overwrite --asar.unpackDir=node_modules/go-ipfs-dep" + } +} diff --git a/examples/electron-asar/public/index.html b/examples/electron-asar/public/index.html new file mode 100644 index 00000000..6a9f24f1 --- /dev/null +++ b/examples/electron-asar/public/index.html @@ -0,0 +1,21 @@ + +loading + + diff --git a/examples/electron-asar/readme.md b/examples/electron-asar/readme.md new file mode 100644 index 00000000..84bca385 --- /dev/null +++ b/examples/electron-asar/readme.md @@ -0,0 +1,6 @@ +# Packaging + +```bash +npm install +npm run package +``` From 5190a489a024bc8f68e2556ed9178b6d303f2588 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 15:45:49 +0200 Subject: [PATCH 13/18] disables eslint no-console warning for examples --- examples/disposableApi.js | 1 + examples/electron-asar/app.js | 1 + examples/id.js | 1 + examples/local.js | 1 + 4 files changed, 4 insertions(+) diff --git a/examples/disposableApi.js b/examples/disposableApi.js index c232a875..0889d698 100644 --- a/examples/disposableApi.js +++ b/examples/disposableApi.js @@ -1,3 +1,4 @@ +/* eslint no-console: 0 */ 'use strict' // Start a disposable node, and get access to the api diff --git a/examples/electron-asar/app.js b/examples/electron-asar/app.js index d8f8c73b..61fbb99c 100644 --- a/examples/electron-asar/app.js +++ b/examples/electron-asar/app.js @@ -1,3 +1,4 @@ +/* eslint no-console: 0 */ 'use strict' const { app, ipcMain, BrowserWindow } = require('electron') diff --git a/examples/id.js b/examples/id.js index cd079d8e..68c61b59 100644 --- a/examples/id.js +++ b/examples/id.js @@ -1,3 +1,4 @@ +/* eslint no-console: 0 */ 'use strict' var ipfsd = require('../') diff --git a/examples/local.js b/examples/local.js index 49621d4b..79cdfe97 100644 --- a/examples/local.js +++ b/examples/local.js @@ -1,3 +1,4 @@ +/* eslint no-console: 0 */ 'use strict' var ipfsd = require('../') From 32e8200a1a6395b49ff7c97bbefd850f2992ee5e Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 15:59:35 +0200 Subject: [PATCH 14/18] cleanup, to be ready for releasing --- examples/electron-asar/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/electron-asar/package.json b/examples/electron-asar/package.json index 6321e85c..5be4c215 100644 --- a/examples/electron-asar/package.json +++ b/examples/electron-asar/package.json @@ -3,7 +3,7 @@ "private": true, "main": "./app.js", "dependencies": { - "ipfsd-ctl": "thisconnect/js-ipfsd-ctl#asar-unpacked" + "ipfsd-ctl": "*" }, "devDependencies": { "electron": "^1.7.6", From f3e49d54ecb143d130812dfc07ebd0788ae5aa72 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 16:25:08 +0200 Subject: [PATCH 15/18] skips addFromFs on win32 --- test/index.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index 968c7791..272bfcc1 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -384,6 +384,15 @@ describe('daemons', () => { }) }) + // skip on windows for now + // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326970190 + // fails on windows see https://github.com/ipfs/js-ipfs-api/issues/408 + if (os.platform() === 'win32') { + it.skip('uses the correct ipfs-api', (done) => {}) + + return // does not continue this test on win + } + // NOTE: if you change ./fixtures, the hash will need to be changed it('uses the correct ipfs-api', (done) => { ipfs.util.addFromFs(path.join(__dirname, 'fixtures/'), { recursive: true }, (err, res) => { From 05108638947a5bf021be03bb1821440936748742 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 17:22:52 +0200 Subject: [PATCH 16/18] skips multiple start stop test on windows --- test/index.spec.js | 66 +++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index 272bfcc1..a51799a2 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -20,6 +20,8 @@ const os = require('os') const exec = require('../src/exec') const ipfsd = require('../src') +const isWindows = os.platform() === 'win32' + describe('ipfs executable path', () => { let Node @@ -387,9 +389,8 @@ describe('daemons', () => { // skip on windows for now // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326970190 // fails on windows see https://github.com/ipfs/js-ipfs-api/issues/408 - if (os.platform() === 'win32') { - it.skip('uses the correct ipfs-api', (done) => {}) - + if (isWindows) { + it.skip('uses the correct ipfs-api') return // does not continue this test on win } @@ -431,35 +432,40 @@ describe('daemons', () => { }) describe('startDaemon', () => { - it('start and stop', (done) => { - const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}` - - const check = (cb) => { - if (fs.existsSync(path.join(dir, 'repo.lock'))) { - cb(new Error('repo.lock not removed')) - } - if (fs.existsSync(path.join(dir, 'api'))) { - cb(new Error('api file not removed')) + // skip on windows + // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530 + if (isWindows) it.skip('start and stop') + else { + it('start and stop', (done) => { + const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}` + + const check = (cb) => { + if (fs.existsSync(path.join(dir, 'repo.lock'))) { + cb(new Error('repo.lock not removed')) + } + if (fs.existsSync(path.join(dir, 'api'))) { + cb(new Error('api file not removed')) + } + cb() } - cb() - } - async.waterfall([ - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.init((err) => cb(err, node)), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check, - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check, - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check - ], done) - }) + async.waterfall([ + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.init((err) => cb(err, node)), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check, + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check, + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check + ], done) + }) + } it('starts the daemon and returns valid API and gateway addresses', (done) => { let daemon From d74578bd37723b8344b201bee9ed16508607b036 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 17:34:55 +0200 Subject: [PATCH 17/18] skips only repo.lock assertion --- test/index.spec.js | 61 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index a51799a2..a457f35a 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -432,40 +432,37 @@ describe('daemons', () => { }) describe('startDaemon', () => { - // skip on windows - // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530 - if (isWindows) it.skip('start and stop') - else { - it('start and stop', (done) => { - const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}` - - const check = (cb) => { - if (fs.existsSync(path.join(dir, 'repo.lock'))) { - cb(new Error('repo.lock not removed')) - } - if (fs.existsSync(path.join(dir, 'api'))) { - cb(new Error('api file not removed')) - } - cb() + it('start and stop', (done) => { + const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}` + + const check = (cb) => { + // skip on windows + // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530 + if (!isWindows && fs.existsSync(path.join(dir, 'repo.lock'))) { + cb(new Error('repo.lock not removed')) } + if (fs.existsSync(path.join(dir, 'api'))) { + cb(new Error('api file not removed')) + } + cb() + } - async.waterfall([ - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.init((err) => cb(err, node)), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check, - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check, - (cb) => ipfsd.local(dir, cb), - (node, cb) => node.startDaemon((err) => cb(err, node)), - (node, cb) => node.stopDaemon(cb), - check - ], done) - }) - } + async.waterfall([ + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.init((err) => cb(err, node)), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check, + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check, + (cb) => ipfsd.local(dir, cb), + (node, cb) => node.startDaemon((err) => cb(err, node)), + (node, cb) => node.stopDaemon(cb), + check + ], done) + }) it('starts the daemon and returns valid API and gateway addresses', (done) => { let daemon From d1a7bdf068ca253f437a1990a0042b2c02504cf9 Mon Sep 17 00:00:00 2001 From: thisconnect Date: Mon, 4 Sep 2017 17:44:57 +0200 Subject: [PATCH 18/18] untests api file on windows --- test/index.spec.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index a457f35a..2bb5020d 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -438,11 +438,13 @@ describe('daemons', () => { const check = (cb) => { // skip on windows // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530 - if (!isWindows && fs.existsSync(path.join(dir, 'repo.lock'))) { - cb(new Error('repo.lock not removed')) - } - if (fs.existsSync(path.join(dir, 'api'))) { - cb(new Error('api file not removed')) + if (!isWindows) { + if (fs.existsSync(path.join(dir, 'repo.lock'))) { + cb(new Error('repo.lock not removed')) + } + if (fs.existsSync(path.join(dir, 'api'))) { + cb(new Error('api file not removed')) + } } cb() }