Skip to content

Commit

Permalink
Graceful handling of missing newman.run parameters, akin to usage of …
Browse files Browse the repository at this point in the history
…CLI.

- work gracefully if no options parameter is sent
- throw error even if there is no callback sent to receive it
  • Loading branch information
shamasis committed Jan 10, 2024
1 parent 2c2121c commit 5580d6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ module.exports = function (options, callback) {
(callback = options),
(options = {})
);
!_.isFunction(callback) && (callback = _.noop);

// if a callback is not provided, then attach a callback that throws error
!_.isFunction(callback) && (callback = function (err) {
if (err) { throw err; } // this throw will likely not work with 'catch' as this will be thrown async
// the idea bove is to at least have the error message displayed up on the stack in case there is an error
// and not be gobbled up and cause confusion for unsuspecting time users.
});

// sanitise object here to avoid repeated property access of undefined error down the line
!_.isObject(options) && (options = {});

var emitter = new EventEmitter(), // @todo: create a new inherited constructor
runner = new runtime.Runner(),
Expand Down
11 changes: 11 additions & 0 deletions test/unit/newman-programmatic-use.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const expect = require('chai').expect,
newman = require('../../');

describe('Newman programmatic usage', function () {
it('should run without any meaningful parameter and pass error in callback', function (done) {
newman.run({}, function (err) {
expect(err).to.be.an('error');
done();
});
});
});

0 comments on commit 5580d6e

Please sign in to comment.