Skip to content

Commit 4d814b1

Browse files
committed
feat: clean up and cosolidate tests
1 parent b003584 commit 4d814b1

File tree

6 files changed

+503
-485
lines changed

6 files changed

+503
-485
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"lint": "aegir lint",
88
"coverage": "aegir coverage",
9-
"test": "aegir test --target node",
9+
"test": "aegir test -t node --timeout 50000",
1010
"docs": "aegir docs",
1111
"release": "aegir release -t node",
1212
"release-minor": "aegir release --type minor -t node",
@@ -58,7 +58,8 @@
5858
"once": "^1.4.0",
5959
"rimraf": "^2.6.2",
6060
"shutdown": "^0.3.0",
61-
"subcomandante": "^1.0.5"
61+
"subcomandante": "^1.0.5",
62+
"truthy": "0.0.1"
6263
},
6364
"devDependencies": {
6465
"aegir": "^12.1.3",

src/daemon.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const path = require('path')
1010
const join = path.join
1111
const once = require('once')
1212
const os = require('os')
13+
const truthy = require('truthy')
14+
1315
const isWindows = os.platform() === 'win32'
1416

1517
const exec = require('./exec')
@@ -91,7 +93,7 @@ class Node {
9193
*/
9294
constructor (path, opts, disposable) {
9395
const rootPath = process.env.testpath ? process.env.testpath : __dirname
94-
const isJS = process.env.IPFS_JS && process.env.IPFS_JS === 'true' // TODO: handle proper truthy/falsy
96+
const isJS = truthy(process.env.IPFS_JS)
9597

9698
this.opts = opts || { isJs: isJS || false }
9799
process.env.IPFS_JS = this.opts.isJs

test/daemon.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const daemon = require('./spawning-daemons.js')
5+
6+
describe('ipfsd-ctl', () => {
7+
describe('Go daemon', () => {
8+
daemon(false)()
9+
})
10+
11+
describe('Js daemon', () => {
12+
daemon(true)()
13+
})
14+
})

test/npm-installs.spec.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ describe('ipfs executable path', () => {
1717
const tmp = os.tmpdir()
1818
const appName = isWindows ? 'ipfs.exe' : 'ipfs'
1919

20+
const oldPath = process.env.testpath
21+
before(() => { process.env.testpath = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/lib') }) // fake __dirname
22+
after(() => { process.env.testpath = oldPath })
23+
2024
it('has the correct path when installed with npm3', (done) => {
21-
process.env.testpath = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/lib') // fake __dirname
2225
let npm3Path = path.join(tmp, 'ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs')
2326

2427
mkdirp(npm3Path, (err) => {
@@ -36,8 +39,6 @@ describe('ipfs executable path', () => {
3639
})
3740

3841
it('has the correct path when installed with npm2', (done) => {
39-
process.env.testpath = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/lib') // fake __dirname
40-
4142
let npm2Path = path.join(tmp, 'ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs')
4243

4344
mkdirp(npm2Path, (err) => {
@@ -50,9 +51,7 @@ describe('ipfs executable path', () => {
5051
const node = new Daemon()
5152

5253
expect(node.exec)
53-
.to.eql(
54-
path.join(tmp, `ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/${appName}`)
55-
)
54+
.to.eql(path.join(tmp, `ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/${appName}`))
5655
rimraf(path.join(tmp, 'ipfsd-ctl-test'), done)
5756
})
5857
})

0 commit comments

Comments
 (0)