Skip to content

Commit

Permalink
fix #3469 REPL interface exits on error (#3489)
Browse files Browse the repository at this point in the history
  • Loading branch information
prudhvi22 authored and beatfactor committed Mar 23, 2023
1 parent 9280062 commit b2f31a6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/api/client-commands/debug.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions lib/testsuite/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/debuggability.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Debuggability {
static set stepOverAndPause(value) {
this._stepOverAndPause = value;
}

static reset() {
this._stepOverAndPause = false;
}
Expand Down
18 changes: 18 additions & 0 deletions test/src/core/testTreeNode.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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;
});
});

0 comments on commit b2f31a6

Please sign in to comment.