From d5bc0ca5506733cbf11058466316c762e1580a82 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 14 Jun 2017 14:00:18 -0700 Subject: [PATCH 1/2] Remove process.exit when simctl prerequisite is not present. The init() function will return a shell return code. In the CLI context, when the return code is non-zero, it will then call process.exit with that return code. Since the behaviour has changed, the version is bumped a major so that dependents don't pick this up automatically and encounter unexpected results. --- package.json | 2 +- src/cli.js | 5 ++++- src/commands.js | 2 +- src/lib.js | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8e8f9f8..f28bc00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ios-sim", - "version": "5.1.0", + "version": "6.0.0", "preferGlobal": "true", "description": "launch iOS apps into the iOS Simulator from the command line (Xcode 7.0+)", "main": "ios-sim.js", diff --git a/src/cli.js b/src/cli.js index f648dc6..206ce2f 100644 --- a/src/cli.js +++ b/src/cli.js @@ -37,7 +37,10 @@ var nopt; function init() { try { nopt = require('nopt'); - command_lib.init(); + var code = command_lib.init(); + if (code !== 0) { + process.exit(code); + } } catch (e) { console.error( 'Please run npm install from this directory:\n\t' + diff --git a/src/commands.js b/src/commands.js index 4c21991..4869ed2 100644 --- a/src/commands.js +++ b/src/commands.js @@ -31,7 +31,7 @@ var path = require('path'), var command_lib = { init: function() { - lib.init(); + return lib.init(); }, //jscs:disable disallowUnusedParams diff --git a/src/lib.js b/src/lib.js index b86665a..1063851 100644 --- a/src/lib.js +++ b/src/lib.js @@ -274,12 +274,13 @@ var lib = { var output = simctl.check_prerequisites(); if (output.code !== 0) { console.error(output.output); - process.exit(2); } if (!bplist) { bplist = require('bplist-parser'); } + + return output.code; }, //jscs:disable disallowUnusedParams From ebaea0b6f6a87cc54ffe355aa40dd73e0a8eb90b Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 14 Jun 2017 15:25:30 -0700 Subject: [PATCH 2/2] Added lib.init unit test --- spec/lib.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/lib.spec.js b/spec/lib.spec.js index 3b4ba2f..7fa0e88 100644 --- a/spec/lib.spec.js +++ b/spec/lib.spec.js @@ -51,6 +51,8 @@ describe('lib end-to-end', function() { }); }) - // it('', function(done) { - // }); + it('init should not process.exit when called as a lib', function() { + var code = lib.init(); + expect(!isNaN(code)).toBe(true); + }); }); \ No newline at end of file