"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dedent_1 = __importDefault(require("dedent"));
const lodash_1 = require("lodash");
const type_1 = __importDefault(require("./type"));
const assertion_diffs_1 = __importDefault(require("./assertion-diffs"));
function escapeNewLines(str) {
return (0, lodash_1.escape)(str).replace(/(\r\n|\n|\r)/gm, '\\n');
}
function getAssertionMsgPrefix(err) {
return err.message ? `"${(0, lodash_1.escape)(err.message)}" assertion` : 'Assertion';
}
function getDiffHeader(err) {
if (err.isArrays)
return `Arrays differ at index ${err.key}
:`;
if (err.isObjects)
return `Objects differ at the ${(0, lodash_1.escape)(err.key)}
field:`;
if (err.isStrings)
return `Strings differ at index ${err.key}
:`;
return '';
}
function markup(err, msgMarkup, opts = {}) {
msgMarkup = (0, dedent_1.default)(`
null
, not undefined
, not false
, not NaN
and not ''
Actual: ${escapeNewLines(err.actual)}
`),
[type_1.default.notOkAssertion]: err => markup(err, `
${getAssertionMsgPrefix(err)} failed at step "${(0, lodash_1.escape)(err.stepName)}":
Expected: null
, undefined
, false
, NaN
or ''
Actual: ${escapeNewLines(err.actual)}
`),
[type_1.default.eqAssertion]: (err, maxStringLength) => {
var diff = (0, assertion_diffs_1.default)(err, maxStringLength);
var diffMarkerStr = diff.marker ? ` ${diff.marker}` : '';
return markup(err, `
${getAssertionMsgPrefix(err)} failed at step "${(0, lodash_1.escape)(err.stepName)}":
${getDiffHeader(err)}
Expected: ${escapeNewLines(diff.expected)}
Actual: ${escapeNewLines(diff.actual)}
${diffMarkerStr}
`);
},
[type_1.default.notEqAssertion]: err => markup(err, `
${getAssertionMsgPrefix(err)} failed at step "${(0, lodash_1.escape)(err.stepName)}":
Expected: not ${escapeNewLines(err.actual)}
Actual: ${escapeNewLines(err.actual)}
`),
[type_1.default.iframeLoadingTimeout]: err => markup(err, `
IFrame loading timed out.
`),
[type_1.default.inIFrameTargetLoadingTimeout]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
IFrame target loading timed out.
`),
[type_1.default.uncaughtJSError]: err => {
if (err.pageDestUrl) {
return markup(err, `
Uncaught JavaScript error ${(0, lodash_1.escape)(err.scriptErr)}
on page ${err.pageDestUrl}
`);
}
return markup(err, `
Uncaught JavaScript error ${(0, lodash_1.escape)(err.scriptErr)}
on page.
`);
},
[type_1.default.uncaughtJSErrorInTestCodeStep]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
Uncaught JavaScript error in test code - ${(0, lodash_1.escape)(err.scriptErr)}
.
`),
[type_1.default.storeDomNodeOrJqueryObject]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
It is not allowed to share the DOM element, jQuery object or a function between test steps via "this" object.
`),
[type_1.default.emptyFirstArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
A target element of the ${err.action}
action has not been found in the DOM tree.
If this element should be created after animation or a time-consuming operation is finished, use the waitFor
action (available for use in code) to pause test execution until this element appears.
`),
[type_1.default.invisibleActionElement]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
A target element ${(0, lodash_1.escape)(err.element)}
of the ${err.action}
action is not visible.
If this element should appear when you are hovering over another element, make sure that you properly recorded the hover
action.
`),
[type_1.default.incorrectDraggingSecondArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
drag
action drop target is incorrect.
`),
[type_1.default.incorrectPressActionArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
press
action parameter contains incorrect key code.
`),
[type_1.default.emptyTypeActionArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The type action's parameter text is empty.
`),
[type_1.default.unexpectedDialog]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
Unexpected system ${err.dialog}
dialog ${(0, lodash_1.escape)(err.message)}
appeared.
`),
[type_1.default.expectedDialogDoesntAppear]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The expected system ${err.dialog}
dialog did not appear.
`),
[type_1.default.incorrectSelectActionArguments]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
select
action's parameters contain an incorrect value.
`),
[type_1.default.incorrectWaitActionMillisecondsArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
wait
action's "milliseconds" parameter should be a positive number.
`),
[type_1.default.incorrectWaitForActionEventArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
waitFor
action's first parameter should be a function, a CSS selector or an array of CSS selectors.
`),
[type_1.default.incorrectWaitForActionTimeoutArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
waitFor
action's "timeout" parameter should be a positive number.
`),
[type_1.default.waitForActionTimeoutExceeded]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
waitFor
action's timeout exceeded.
`),
[type_1.default.incorrectGlobalWaitForActionEventArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
__waitFor
action's first parameter should be a function.
`),
[type_1.default.incorrectGlobalWaitForActionTimeoutArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
__waitFor
action's "timeout" parameter should be a positive number.
`),
[type_1.default.globalWaitForActionTimeoutExceeded]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
__waitFor
action's timeout exceeded.
`),
[type_1.default.emptyIFrameArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The selector within the inIFrame
function returns an empty value.
`),
[type_1.default.iframeArgumentIsNotIFrame]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The selector within the inIFrame
function doesn’t return an iframe element.
`),
[type_1.default.multipleIFrameArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The selector within the inIFrame
function returns more than one iframe element.
`),
[type_1.default.incorrectIFrameArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
The inIFrame
function contains an invalid argument.
`),
[type_1.default.uploadCanNotFindFileToUpload]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
Cannot find the following file(s) to upload:
${err.filePaths.map(path => `${(0, lodash_1.escape)(path)}
`).join(',\n')}
`),
[type_1.default.uploadElementIsNotFileInput]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
upload
action argument does not contain a file input element.
`),
[type_1.default.uploadInvalidFilePathArgument]: err => markup(err, `
Error at step "${(0, lodash_1.escape)(err.stepName)}":
upload
action's "path" parameter should be a string or an array of strings.
`),
[type_1.default.pageNotLoaded]: err => markup(err, `
${err.message}
`)
};