Skip to content

Commit

Permalink
Add global validation for actions options(closes DevExpress#7293) (De…
Browse files Browse the repository at this point in the history
…vExpress#7281)

* Add global validation for actions options

* Add Studio service field

* fix Studio service field

* Change reporter props filtering mechanism

* display only public properties in assignable object, fix raw tests

* display property path in type validation error

* fix functional tests

* fix functional tests 2

* define actionId prop before validation

* fix IE test, refactor

* fix CommandBase type definition

* replace includes with indexOf method

* refactor

* fix: testcafe studio passes invalid properties to the raw tests

* change note

* refactor raw test compiler

* add note

* fix remove selector if it is null

* reset raw tests, refactor compiler

* refactor compiler 2

* remove studio related properties during command creation to prevent error when createCommandFromObject called outside of compiler

* fix: remove callsite service property

* skip iframe firefox-osx test

* fix getAssignableProperties method name
  • Loading branch information
Artem-Babich committed Oct 4, 2022
1 parent ba2d7c4 commit 968ae65
Show file tree
Hide file tree
Showing 39 changed files with 1,369 additions and 1,259 deletions.
2 changes: 1 addition & 1 deletion src/api/skip-js-errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function createSkipJsErrorsObjectFunction (deps: SkipJsErrorsOptionsObject): Exe

const func = new Function('err', SKIP_JS_ERRORS_OBJECT_FUNCTION) as SkipJsErrorsCallback;

const callbackWrapper = wrapSkipJsErrorsCallback(func, { deps }) as SkipJsErrorsCallbackWithOptionsObject;
const callbackWrapper = wrapSkipJsErrorsCallback(func, { deps });

return createSkipJsErrorsCallbackFunction(callbackWrapper);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/driver/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class DriverStatus extends Assignable {
this._assignFrom(obj, true);
}

_getAssignableProperties () {
getAssignableProperties () {
return [
{ name: 'isCommandResult' },
{ name: 'executionError' },
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compilers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Compiler as LegacyTestFileCompiler } from 'testcafe-legacy-api';
import EsNextTestFileCompiler from './test-file/formats/es-next/compiler';
import TypeScriptTestFileCompiler from './test-file/formats/typescript/compiler';
import CoffeeScriptTestFileCompiler from './test-file/formats/coffeescript/compiler';
import RawTestFileCompiler from './test-file/formats/raw';
import RawTestFileCompiler from './test-file/formats/raw/compiler';
import DevToolsTestFileCompiler from './test-file/formats/dev-tools/compiler';
import CustomizableCompilers from '../configuration/customizable-compilers';

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/test-file/formats/dev-tools/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RawTestFileCompiler from '../raw';
import RawTestFileCompiler from '../raw/compiler';
import Test from '../../../../api/structure/test';
import { CommandTransformerFactory } from './commands/factory';
import { SwitchToIframeCommandTransformer } from './commands/switch-to-iframe';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TestFileCompilerBase from '../base';
import { GeneralError } from '../../../errors/runtime';
import { RUNTIME_ERRORS } from '../../../errors/types';
import TestFile from '../../../api/structure/test-file';
import Fixture from '../../../api/structure/fixture';
import Test from '../../../api/structure/test';
import createCommandFromObject from '../../../test-run/commands/from-object';
import { RawCommandCallsiteRecord } from '../../../utils/raw-command-callsite-record';
import TestFileCompilerBase from '../../base';
import { GeneralError } from '../../../../errors/runtime';
import { RUNTIME_ERRORS } from '../../../../errors/types';
import TestFile from '../../../../api/structure/test-file';
import Fixture from '../../../../api/structure/fixture';
import Test from '../../../../api/structure/test';
import createCommandFromObject from '../../../../test-run/commands/from-object';
import { RawCommandCallsiteRecord } from '../../../../utils/raw-command-callsite-record';

export default class RawTestFileCompiler extends TestFileCompilerBase {

Expand Down
8 changes: 8 additions & 0 deletions src/errors/test-run/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
replaceLeadingSpacesWithNbsp,
formatExpressionMessage,
} from './utils';
import { getConcatenatedValuesString } from '../../utils/string';

const EXTERNAL_LINKS = {
createNewIssue: 'https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md',
Expand Down Expand Up @@ -451,4 +452,11 @@ export default {
[TEST_RUN_ERRORS.actionFunctionOptionError]: err => `
The value of the "${err.optionName}" option belongs to an unsupported data type (${err.actualValue}). The "${err.optionName}" option only accepts function types values.
`,

[TEST_RUN_ERRORS.actionInvalidObjectPropertyError]: err => `
The "${err.objectName}" object does not support the "${err.propertyName}" property.
To proceed, remove invalid options from your code or check your test for spelling errors.
The "${err.objectName}" object supports the following options:
${getConcatenatedValuesString(err.availableProperties, ',\n')}.
`,
};
1 change: 1 addition & 0 deletions src/errors/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const TEST_RUN_ERRORS = {
actionStringOrRegexOptionError: 'E97',
actionSkipJsErrorsArgumentError: 'E98',
actionFunctionOptionError: 'E99',
actionInvalidObjectPropertyError: 'E100',
};

export const RUNTIME_ERRORS = {
Expand Down
16 changes: 2 additions & 14 deletions src/reporter/command/command-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import {
} from '../../test-run/commands/options';

import { CommandBase } from '../../test-run/commands/base';
import CommandType from '../../test-run/commands/type';
import { AssertionCommand } from '../../test-run/commands/assertion';


const CONFIDENTIAL_INFO_PLACEHOLDER = '********';

Expand Down Expand Up @@ -128,20 +125,11 @@ export class CommandFormatter {
return command.url;
}

private _filterNotReportedProperties (properties: string[], commandType: string): string[] {
if (commandType !== CommandType.assertion)
return properties;

return properties.filter(prop => !AssertionCommand.NOT_REPORTED_PROPERTIES.includes(prop));
}

private _assignProperties (command: CommandBase, formattedCommand: FormattedCommand): void {
if (!this._command._getAssignableProperties)
if (!this._command.getReportedProperties)
return;

let sourceProperties = this._command._getAssignableProperties().map(prop => prop.name);

sourceProperties = this._filterNotReportedProperties(sourceProperties, this._command.type);
const sourceProperties = this._command.getReportedProperties();

sourceProperties.forEach((key: string) => {
const property = this._command[key];
Expand Down
10 changes: 10 additions & 0 deletions src/shared/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ export class ActionFunctionOptionError extends ActionOptionErrorBase {
}
}

export class ActionInvalidObjectPropertyError extends TestRunErrorBase {
constructor (objectName, propertyName, availableProperties) {
super(TEST_RUN_ERRORS.actionInvalidObjectPropertyError);

this.objectName = objectName;
this.propertyName = propertyName;
this.availableProperties = availableProperties;
}
}

// Action execution errors
//--------------------------------------------------------------------
export class ActionElementNotFoundError extends SelectorErrorBase {
Expand Down

0 comments on commit 968ae65

Please sign in to comment.