From b74369687a126062fcef68b57a7098f1cb78434f Mon Sep 17 00:00:00 2001 From: RandomSeeded Date: Wed, 11 Apr 2018 16:32:45 -0700 Subject: [PATCH] fix(check): fix check via API not passing results to the callback Signed-off-by: RandomSeeded --- lib/commands/on-complete.js | 5 +++-- test/on_complete_test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/on_complete_test.js diff --git a/lib/commands/on-complete.js b/lib/commands/on-complete.js index a78d921d..a0d0ad8d 100644 --- a/lib/commands/on-complete.js +++ b/lib/commands/on-complete.js @@ -1,9 +1,10 @@ var assert = require('assert'); var log = require('db-migrate-shared').log; -module.exports = function (migrator, internals, callback, originalErr) { +module.exports = function (migrator, internals, callback, originalErr, results) { if (typeof callback !== 'function') { originalErr = originalErr || callback; + results = results || originalErr; } migrator.driver.close(function (err) { @@ -22,7 +23,7 @@ module.exports = function (migrator, internals, callback, originalErr) { } if (typeof callback === 'function') { - callback(); + callback(null, results); } }); }; diff --git a/test/on_complete_test.js b/test/on_complete_test.js new file mode 100644 index 00000000..38f64b56 --- /dev/null +++ b/test/on_complete_test.js @@ -0,0 +1,27 @@ +var Code = require('code'); +var Lab = require('lab'); +var lab = (exports.lab = Lab.script()); +var onComplete = require('../lib/commands/on-complete'); + +lab.experiment('on-complete', function () { + lab.test('should invoke the callback with the results', function (done) { + var migratorMock = { + driver: { + close: function (cb) { + cb(); + } + } + }; + var internalsMock = { + argv: { } + }; + + var resultsPassedToCallback = 'callback should be invoked with results'; + var testCallback = function (err, res) { + Code.expect(err).to.equal(null); + Code.expect(res).to.equal(resultsPassedToCallback); + done(); + }; + onComplete(migratorMock, internalsMock, testCallback, null, resultsPassedToCallback); + }); +});