Skip to content

Commit

Permalink
Fixed #2190 - test error/failure stack traces showing incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Sep 19, 2019
1 parent b7f6a6c commit 0beacad
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 36 deletions.
6 changes: 4 additions & 2 deletions lib/api-loader/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class ApiLoader {
addCommandDefinition(commandName, commandFn, parent) {
let loader = new CommandLoader(this.nightwatchInstance);
loader.commandName = commandName;
loader.commandFn = commandFn;
loader.commandFn = function({args, stackTrace}) {
return commandFn.apply(this, args);
};
loader.define(parent);
}

Expand Down Expand Up @@ -264,7 +266,7 @@ class ApiLoader {
commandFn,
context: this.api,
args: [],
stackTrace: assertFn.stackTrace,
stackTrace: CommandLoader.getOriginalStackTrace(assertFn),
namespace
});

Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/assertion-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AssertionLoader extends BaseCommandLoader {
this.validateModuleDefinition();
this.abortOnFailure = abortOnFailure;

this.commandFn = function commandFn(...args) {
this.commandFn = function commandFn({args, stackTrace}) {
return this.resolveElementSelector(args)
.then(elementResult => {
if (elementResult) {
Expand All @@ -132,7 +132,7 @@ class AssertionLoader extends BaseCommandLoader {
});

return AssertionLoader.runAssertion(instance, {
stackTrace: commandFn.stackTrace,
stackTrace,
rescheduleInterval: Utils.isNumber(instance.rescheduleInterval) ? instance.rescheduleInterval : this.rescheduleInterval,
timeout: Utils.isNumber(instance.retryAssertionTimeout) ? instance.retryAssertionTimeout : this.timeout,
abortOnFailure,
Expand Down
8 changes: 4 additions & 4 deletions lib/api-loader/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class CommandLoader extends BaseCommandLoader {

createWrapper() {
if (this.module) {
this.commandFn = function commandFn(...args) {
this.commandFn = function commandFn({args, stackTrace}) {
const instance = CommandLoader.createInstance(this.nightwatchInstance, this.module, {
stackTrace: commandFn.stackTrace,
stackTrace,
args,
commandName: this.commandName
});
Expand Down Expand Up @@ -152,7 +152,7 @@ class CommandLoader extends BaseCommandLoader {
const commandFn = this.commandFn.bind(this);

const args = [function queuedCommandFn(...args) {
const originalStackTrace = CommandLoader.getOriginalStackTrace(queuedCommandFn);
const stackTrace = CommandLoader.getOriginalStackTrace(queuedCommandFn);
const deferred = Utils.createPromise();

// if this command was called from another async (custom) command
Expand All @@ -166,7 +166,7 @@ class CommandLoader extends BaseCommandLoader {
commandFn,
context: this,
args,
originalStackTrace,
stackTrace,
namespace,
deferred,
isES6Async
Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/element-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class ElementCommandLoader extends CommandLoader {
}

createWrapper() {
this.commandFn = function commandFn(...args) {
this.commandFn = function commandFn({args, stackTrace}) {
const instance = ElementCommandLoader.createInstance(this.module, {
args,
commandName: this.commandName,
nightwatchInstance: this.nightwatchInstance
});

instance.stackTrace = commandFn.stackTrace;
instance.stackTrace = stackTrace;

return instance.command();
};
Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/expect/_expect-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ExpectLoader extends BaseCommandLoader {
}

static createCommandWrapper(commandWrapper, expectInstance, promiseRejectedMsg = 'Element was not found.') {
return function commandFn(...args) {
this.stackTrace = commandFn.stackTrace;
return function commandFn({args, stackTrace}) {
this.stackTrace = stackTrace;
commandWrapper.call(expectInstance, args);

this.promise.catch(err => {
Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/expect/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class ExpectCookieLoader extends ExpectLoader {
}

createWrapper() {
return function commandFn(...args) {
this.stackTrace = commandFn.stackTrace;
return function commandFn({args, stackTrace}) {
this.stackTrace = stackTrace;
this.__args = args;
this.createEmmitter(...args);
this.executeProtocolAction();
Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/expect/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class ExpectTitleLoader extends ExpectLoader {
}

createWrapper() {
return function commandFn(...args) {
this.stackTrace = commandFn.stackTrace;
return function commandFn({args, stackTrace}) {
this.stackTrace = stackTrace;
this.__args = args;
this.createEmmitter(...args);
this.executeProtocolAction();
Expand Down
4 changes: 2 additions & 2 deletions lib/api-loader/expect/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ExpectUrlLoader extends ExpectLoader {
}

createWrapper() {
return function commandFn(...args) {
this.stackTrace = commandFn.stackTrace;
return function commandFn({args, stackTrace}) {
this.stackTrace = stackTrace;
this.createEmmitter(...args);
this.executeProtocolAction(args);

Expand Down
11 changes: 2 additions & 9 deletions lib/core/treenode.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,8 @@ class TreeNode {
return Promise.resolve();
}

if (commandFn.prototype) {
commandFn.prototype.constructor.stackTrace = this.stackTrace;
}

this.__instance = commandFn.apply(this.context, this.args);

if (!commandFn.prototype) {
this.__instance.stackTrace = this.stackTrace;
}
const {args, stackTrace} = this;
this.__instance = commandFn.call(this.context, {args, stackTrace});

return (this.instance instanceof Promise) ? this.instance : this.handleCommandResult();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/element/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ElementCommand extends EventEmitter {
this.abortOnFailure = this.api.globals.abortOnAssertionFailure;
this.throwOnMultipleElementsReturned = this.api.globals.throwOnMultipleElementsReturned;
this.elementId = null;
this.args = args || this.commandArgs || [];
this.args = Array.isArray(args) && args.slice(0) || this.commandArgs || [];

this.setMilliseconds();
this.setRescheduleInterval();
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mocks/assertionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AssertionLoaderMock {
let loader = new AssertionLoaderMock(module, commandName, settings, mockReporter);

loader.setAddToQueueFn(function({commandName, commandFn, context, args, stackTrace}) {
commandFn.apply(context, args);
commandFn.call(context, {args, stackTrace});
});

return loader;
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mocks/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MockSession extends Session {
get commandQueue() {
return {
add({commandName, commandFn, context, args, stackTrace}) {
commandFn(...args);
commandFn({args, stackTrace});
},

empty() {
Expand Down
4 changes: 2 additions & 2 deletions test/src/api-loader/testAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('test Assertions', function() {
value : 'expected text result'
});
}).setAddToQueueFn(function({commandName, commandFn, context, args, namespace, stackTrace}) {
commandFn.apply(context, args);
commandFn.call(context, {args, stackTrace});
}).loadAssertion(function(passed, value, calleeFn, message) {
assert.equal(passed, true);
assert.equal(this.assertion.expected, 'text result');
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('test Assertions', function() {
});
}).setAddToQueueFn(function({commandName, commandFn, context, args, namespace, stackTrace}) {
commandFn.stackTrace = stackTrace;
commandFn.apply(context, args);
commandFn.call(context, {args, stackTrace});
}).loadAssertion(function(passed, value, calleeFn, message) {
assert.equal(passed, false);
assert.equal(value, 'not_expected');
Expand Down
4 changes: 2 additions & 2 deletions test/src/api-loader/testNightwatchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('test Nightwatch Api', function() {
session: {
commandQueue: {
add({commandName, commandFn, context, args, stackTrace}) {
let instance = commandFn.apply(context, args);
let instance = commandFn.call(context, {args, stackTrace});
if (commandName === 'customPerform') {
instance.on('complete', () => {
assert.strictEqual(paramFnCalled, true);
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('test Nightwatch Api', function() {
commandQueue: {
add({commandName, commandFn, context, args, stackTrace}) {
commandQueue.push(commandName);
let instance = commandFn.apply(context, args);
let instance = commandFn.call(context, {args, stackTrace});

if (commandName === 'customCommand') {
assert.equal(instance.toString(), 'CommandInstance [name=customCommand]');
Expand Down
4 changes: 2 additions & 2 deletions test/src/wd-manager/testSelenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ describe('Webdriver Manager', function () {
// Simulate an error thrown
assert.ok(false, 'Selenium Server should have failed to start.');
}).catch(err => {
assert.strictEqual(wdServer.settings.webdriver.max_status_poll_tries, 5);
assert.strictEqual(wdServer.settings.webdriver.status_poll_interval, 100);
assert.strictEqual(wdServer.settings.webdriver.max_status_poll_tries, 15);
assert.strictEqual(wdServer.settings.webdriver.status_poll_interval, 200);
assert.strictEqual(wdServer.settings.webdriver.check_process_delay, 1000);
assert.strictEqual(wdServer.settings.webdriver.process_create_timeout, 2000);
assert.ok(err.message.includes('Selenium Server process exited with code: 1'));
Expand Down

0 comments on commit 0beacad

Please sign in to comment.