Skip to content

Commit

Permalink
Add the debugOnFail option (closes DevExpress#1608) (DevExpress#1776)
Browse files Browse the repository at this point in the history
* Add the debugOnFail option (closes DevExpress#1608)

* "Resume" -> "Finish"

* Update description

* Add a test

* Don't import testcafeReporterSpecPlugin
  • Loading branch information
AlexanderMoskovkin authored Sep 18, 2017
1 parent e407169 commit 9c04cd7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/cli/argument-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class CLIArgumentParser {
.option('-F, --fixture-grep <pattern>', 'run only fixtures matching the specified pattern')
.option('-a, --app <command>', 'launch the tested app using the specified command before running tests')
.option('-c, --concurrency <number>', 'run tests concurrently')
.option('--debug-on-fail', 'pause the test if it fails')
.option('--app-init-delay <ms>', 'specify how much time it takes for the tested app to initialize')
.option('--selector-timeout <ms>', 'set the amount of time within which selectors make attempts to obtain a node to be returned')
.option('--assertion-timeout <ms>', 'set the amount of time within which assertion should pass')
Expand Down
6 changes: 3 additions & 3 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ export default class Driver {
});
}

_onSetBreakpointCommand () {
this.statusBar.showDebuggingStatus()
_onSetBreakpointCommand (isTestError) {
this.statusBar.showDebuggingStatus(isTestError)
.then(stopAfterNextAction => this._onReady(new DriverStatus({
isCommandResult: true,
result: stopAfterNextAction
Expand Down Expand Up @@ -463,7 +463,7 @@ export default class Driver {
this._onTestDone(new DriverStatus({ isCommandResult: true }));

else if (command.type === COMMAND_TYPE.setBreakpoint)
this._onSetBreakpointCommand();
this._onSetBreakpointCommand(command.isTestError);

else if (command.type === COMMAND_TYPE.prepareBrowserManipulation)
this._onPrepareBrowserManipulationCommand();
Expand Down
30 changes: 24 additions & 6 deletions src/client/ui/status-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const LOADING_PAGE_TEXT = 'Loading Web Page...';
const WAITING_FOR_ELEMENT_TEXT = 'Waiting for an element to appear...';
const WAITING_FOR_ASSERTION_EXECUTION_TEXT = 'Waiting for an assertion execution...';
const DEBUGGING_TEXT = 'Debugging test...';
const TEST_FAILED_TEXT = 'Test failed';
const MIDDLE_WINDOW_WIDTH = 720;
const SMALL_WINDOW_WIDTH = 380;
const SMALL_WINDOW_WIDTH_IN_DEBUGGING = 540;
Expand All @@ -61,6 +62,7 @@ export default class StatusBar {
this.icon = null;
this.fixtureContainer = null;
this.resumeButton = null;
this.finishButton = null;
this.stepButton = null;
this.statusDiv = null;
this.buttons = null;
Expand Down Expand Up @@ -123,6 +125,10 @@ export default class StatusBar {

this.resumeButton = this._createButton('Resume', RESUME_BUTTON_CLASS);
this.stepButton = this._createButton('Step', STEP_CLASS);
this.finishButton = this._createButton('Finish', RESUME_BUTTON_CLASS);

this.buttons.appendChild(this.resumeButton);
this.buttons.appendChild(this.stepButton);
}

_createButton (text, className) {
Expand All @@ -143,7 +149,6 @@ export default class StatusBar {

button.appendChild(icon);
button.appendChild(span);
this.buttons.appendChild(button);

return button;
}
Expand Down Expand Up @@ -366,11 +371,22 @@ export default class StatusBar {
});
}

_showDebuggingStatus () {
_showDebuggingStatus (isTestError) {
return new Promise(resolve => {
this.debugging = true;

this.statusDiv.textContent = DEBUGGING_TEXT;
if (isTestError) {
this.buttons.removeChild(this.stepButton);
this.buttons.removeChild(this.resumeButton);
this.buttons.appendChild(this.finishButton);

this.statusDiv.textContent = TEST_FAILED_TEXT;
shadowUI.removeClass(this.statusBar, WAITING_SUCCESS_CLASS);
shadowUI.addClass(this.statusBar, WAITING_FAILED_CLASS);
}
else
this.statusDiv.textContent = DEBUGGING_TEXT;

this.buttons.style.display = 'inline-block';

this._recalculateSizes();
Expand All @@ -380,8 +396,9 @@ export default class StatusBar {
var downHandler = e => {
var isResumeButton = domUtils.containsElement(this.resumeButton, e.target);
var isStepButton = domUtils.containsElement(this.stepButton, e.target);
var isFinishButton = domUtils.containsElement(this.finishButton, e.target);

if (isResumeButton || isStepButton) {
if (isResumeButton || isStepButton || isFinishButton) {
eventUtils.preventDefault(e);
this._resetState();
listeners.removeInternalEventListener(window, [eventName], downHandler);
Expand Down Expand Up @@ -437,11 +454,12 @@ export default class StatusBar {
this._resetState();
}

showDebuggingStatus () {
showDebuggingStatus (isTestError) {
this._stopAnimation();

styleUtils.set(this.statusBar, 'opacity', 1);

return this._showDebuggingStatus();
return this._showDebuggingStatus(isTestError);
}

showWaitingElementStatus (timeout) {
Expand Down
6 changes: 3 additions & 3 deletions src/notifications/debug-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
this.debugLogging = false;
},

showBreakpoint (testRunId, userAgent, callsite) {
showBreakpoint (testRunId, userAgent, callsite, testError) {
if (!this.streamsOverridden)
this._overrideStreams();

Expand All @@ -71,8 +71,8 @@ export default {
var frame = `\n` +
`----\n` +
`${userAgent}\n` +
chalk.yellow('DEBUGGER PAUSE:') + `\n` +
`${callsiteStr}\n` +
chalk.yellow(testError ? 'DEBUGGER PAUSE ON FAILED TEST:' : 'DEBUGGER PAUSE:') + `\n` +
`${testError ? testError : callsiteStr}\n` +
`----\n`;

var message = { testRunId, frame };
Expand Down
3 changes: 2 additions & 1 deletion src/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ export default class Runner extends EventEmitter {
return this;
}

run ({ skipJsErrors, quarantineMode, debugMode, selectorTimeout, assertionTimeout, pageLoadTimeout, speed = 1 } = {}) {
run ({ skipJsErrors, quarantineMode, debugMode, selectorTimeout, assertionTimeout, pageLoadTimeout, speed = 1, debugOnFail } = {}) {
this.opts.skipJsErrors = !!skipJsErrors;
this.opts.quarantineMode = !!quarantineMode;
this.opts.debugMode = !!debugMode;
this.opts.debugOnFail = !!debugOnFail;
this.opts.selectorTimeout = selectorTimeout === void 0 ? DEFAULT_SELECTOR_TIMEOUT : selectorTimeout;
this.opts.assertionTimeout = assertionTimeout === void 0 ? DEFAULT_ASSERTION_TIMEOUT : assertionTimeout;
this.opts.pageLoadTimeout = pageLoadTimeout === void 0 ? DEFAULT_PAGE_LOAD_TIMEOUT : pageLoadTimeout;
Expand Down
5 changes: 3 additions & 2 deletions src/test-run/commands/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export class HideAssertionRetriesStatusCommand {
}

export class SetBreakpointCommand {
constructor () {
this.type = TYPE.setBreakpoint;
constructor (isTestError) {
this.type = TYPE.setBreakpoint;
this.isTestError = isTestError;
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import testRunTracker from '../api/test-run-tracker';
import ROLE_PHASE from '../role/phase';
import TestRunBookmark from './bookmark';
import ClientFunctionBuilder from '../client-functions/client-function-builder';
import ReporterPluginHost from '../reporter/plugin-host';


import { TakeScreenshotOnFailCommand } from './commands/browser-manipulation';
Expand Down Expand Up @@ -91,7 +92,9 @@ export default class TestRun extends Session {
this.resolveWaitForFileDownloadingPromise = null;

this.debugging = this.opts.debugMode;
this.debugOnFail = this.opts.debugOnFail;
this.disableDebugBreakpoints = false;
this.debugReporterPluginHost = new ReporterPluginHost({ noColors: false });

this.browserManipulationQueue = new BrowserManipulationQueue(browserConnection, screenshotCapturer, warningLog);

Expand Down Expand Up @@ -208,6 +211,9 @@ export default class TestRun extends Session {
await this._runAfterHook();
}

if (this.errs.length && this.debugOnFail)
await this._enqueueSetBreakpointCommand(null, this.debugReporterPluginHost.formatError(this.errs[0]));

await this.executeCommand(new TestDoneCommand());
this._addPendingPageErrorIfAny();

Expand Down Expand Up @@ -263,10 +269,10 @@ export default class TestRun extends Session {
return this.executeCommand(new PrepareBrowserManipulationCommand(command.type), callsite);
}

async _enqueueSetBreakpointCommand (callsite) {
debugLogger.showBreakpoint(this.id, this.browserConnection.userAgent, callsite);
async _enqueueSetBreakpointCommand (callsite, error) {
debugLogger.showBreakpoint(this.id, this.browserConnection.userAgent, callsite, error);

this.debugging = await this._enqueueCommand(new SetBreakpointCommand(), callsite);
this.debugging = await this._enqueueCommand(new SetBreakpointCommand(!!error), callsite);
}

_removeAllNonServiceTasks () {
Expand Down
3 changes: 2 additions & 1 deletion test/server/cli-argument-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('CLI argument parser', function () {
});

it('Should parse command line arguments', function () {
return parse('-r list -S -q -e --hostname myhost --proxy localhost:1234 --qr-code --app run-app --speed 0.5 ie test/server/data/file-list/file-1.js')
return parse('-r list -S -q -e --hostname myhost --proxy localhost:1234 --qr-code --app run-app --speed 0.5 --debug-on-fail ie test/server/data/file-list/file-1.js')
.then(function (parser) {
expect(parser.browsers).eql(['ie']);
expect(parser.src).eql([path.resolve(process.cwd(), 'test/server/data/file-list/file-1.js')]);
Expand All @@ -346,6 +346,7 @@ describe('CLI argument parser', function () {
expect(parser.opts.speed).eql(0.5);
expect(parser.opts.qrCode).to.be.ok;
expect(parser.opts.proxy).to.be.ok;
expect(parser.opts.debugOnFail).to.be.ok;
});
});
});
Expand Down

0 comments on commit 9c04cd7

Please sign in to comment.