diff --git a/lib/api/client-commands/debug.js b/lib/api/client-commands/debug.js index 52a02c13fb..76e1477b56 100644 --- a/lib/api/client-commands/debug.js +++ b/lib/api/client-commands/debug.js @@ -1,6 +1,7 @@ const util = require('util'); const EventEmitter = require('events'); const NightwatchRepl = require('../../testsuite/repl'); +const Debuggability = require('../../utils/debuggability.js'); /** * This command halts the test execution and provides users with a REPL interface where they can type @@ -47,9 +48,18 @@ Debug.prototype.command = function(config, cb) { browser: this.api, app: this.api }; + // Before starting REPL server, Set debugMode to true + Debuggability.debugMode = true; + // Set isES6AsyncTestcase to true in debugmode + const isES6AsyncTestcase = this.client.isES6AsyncTestcase; + this.client.isES6AsyncTestcase = true; repl.startServer(context); repl.onExit(() => { + // On exit, Set debugMode to false + Debuggability.debugMode = false; + this.client.isES6AsyncTestcase = isES6AsyncTestcase; + // if we have a callback, call it right before the complete event if (cb) { cb.call(this.client.api); diff --git a/lib/testsuite/repl.js b/lib/testsuite/repl.js index 906d53fe8b..3acc45f4fd 100644 --- a/lib/testsuite/repl.js +++ b/lib/testsuite/repl.js @@ -47,11 +47,6 @@ module.exports = class NightwatchRepl { return; } - // Make any modifications to the command before sending it over to vm. - if (cmd.includes('assert')) { - cmd = cmd.replaceAll('assert', 'verify'); - } - try { const result = vm.runInContext(cmd, this._context); this._handleResult(result, callback); @@ -101,6 +96,11 @@ module.exports = class NightwatchRepl { // already been logged by Nightwatch. // TODO: Should we close the REPL server here? + // Assertions errors would have already been logged + if (err.name !== 'NightwatchAssertError') { + Logger.error(err); + } + if (timeoutCalled) { return; } diff --git a/lib/utils/debuggability.js b/lib/utils/debuggability.js index 7aac25382c..437f3455cf 100644 --- a/lib/utils/debuggability.js +++ b/lib/utils/debuggability.js @@ -6,7 +6,7 @@ class Debuggability { static set stepOverAndPause(value) { this._stepOverAndPause = value; } - + static reset() { this._stepOverAndPause = false; } diff --git a/test/src/core/testTreeNode.js b/test/src/core/testTreeNode.js index 957d3cf13b..eaa3fa52a9 100644 --- a/test/src/core/testTreeNode.js +++ b/test/src/core/testTreeNode.js @@ -1,6 +1,7 @@ const assert = require('assert'); const EventEmitter = require('events'); const TreeNode = require('../../../lib/core/treenode'); +const common = require('../../common.js'); describe('test Queue', function () { it('Test commands treeNode - clear error events in handleCommandResult', function () { @@ -45,4 +46,21 @@ describe('test Queue', function () { assert.equal(mockCommandLoader.listenerCount('error'), 0); assert.equal(mockCommandLoader.listenerCount('complete'), 0); }); + + it('test handleError - set abortOnFailure to false in debug mode', function () { + const treeNode = new TreeNode({ + name: '__root__', + parent: null + }); + const Debuggability = common.require('utils/debuggability'); + + Debuggability.debugMode = true; + let error = new Error('Error while executing command in debug mode'); + error.abortOnFailure = true; + + error = treeNode.handleError(error); + assert.strictEqual(error.abortOnFailure, false); + + Debuggability.debugMode = false; + }); });