From 7e174fd0cd18ff0025c95e82e3e07d3acb8dc639 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 25 Aug 2015 13:15:30 -0400 Subject: [PATCH] Handle exit codes from npm install with the create command. --- lib/scaffold/create.js | 7 ++++-- test/scaffold/create.integration.js | 36 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/scaffold/create.js b/lib/scaffold/create.js index d2d14594..22dcd954 100644 --- a/lib/scaffold/create.js +++ b/lib/scaffold/create.js @@ -150,8 +150,11 @@ function create(options, done) { }); npm.on('close', function (code) { - //todo: handle code - next(); + if (code !== 0) { + return next(new Error('There was an error installing dependencies.')); + } else { + return next(); + } }); } else { diff --git a/test/scaffold/create.integration.js b/test/scaffold/create.integration.js index 827662eb..8930d207 100644 --- a/test/scaffold/create.integration.js +++ b/test/scaffold/create.integration.js @@ -13,7 +13,7 @@ var create = proxyquire('../../lib/scaffold/create', { on: sinon.stub() }, on: function(event, cb) { - cb(); + cb(0); } }) } @@ -134,10 +134,6 @@ describe('#create', function() { throw err; } - if (err) { - throw err; - } - var packagePath = testDir + '/mynode3/package.json'; should.equal(fs.existsSync(packagePath), false); @@ -145,4 +141,34 @@ describe('#create', function() { }); + it('will receieve an error from npm', function() { + var createtest = proxyquire('../../lib/scaffold/create', { + 'child_process': { + spawn: sinon.stub().returns({ + stdout: { + on: sinon.stub() + }, + stderr: { + on: sinon.stub() + }, + on: function(event, cb) { + cb(1); + } + }) + } + }); + + createtest({ + cwd: testDir, + dirname: 'mynode4', + name: 'My Node 4', + isGlobal: false, + datadir: '../.bitcoin' + }, function(err) { + should.exist(err); + err.message.should.equal('There was an error installing dependencies.'); + }); + + }); + });