Skip to content

Commit

Permalink
FI-1038 feat: remove extra logs from mockApiRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 27, 2023
1 parent ec8d568 commit d50abb3
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 50 deletions.
22 changes: 11 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@

fix: remove unnecessary backticks around the error message

- [Torchinskiy Merge pull request #44 from joomcode/FI-494](https://github.com/joomcode/e2ed/commit/eba8a49e65fc100ca3dc4e1c492c6c86968fb689) ([Nikita](https://github.com/Nikita))
- [Merge pull request #44 from joomcode/FI-494](https://github.com/joomcode/e2ed/commit/eba8a49e65fc100ca3dc4e1c492c6c86968fb689) ([nnn3d](https://github.com/nnn3d))

FI-494: add selectors with custom methods

- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/c69b98dc548a66c043ca99f52e1e8b8ddf89100a) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/349c95d7800810ab03b7f2cab4a058e6e988833c) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/ef71561bedc4a27428b27bfbecc84fcc106c69e3) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [FI-494: fix prettier](https://github.com/joomcode/e2ed/commit/daa939c3088ef1e41390e79ec2d5293fbe2a578f) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [Torchinskiy Merge branch 'main' into FI-494](https://github.com/joomcode/e2ed/commit/ab4f9114b4e3694c363e53f5a2567fed8c77bf4a) ([Nikita](https://github.com/Nikita))
- [FI-494: remove default selector exports](https://github.com/joomcode/e2ed/commit/b03ad55d24c53d58fc217efc70b74ec876a4c2a2) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [FI-494: add selectors with custom methods](https://github.com/joomcode/e2ed/commit/3e577d3b7dd113eaba2a135b1bd362e9eeca8d90) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/c69b98dc548a66c043ca99f52e1e8b8ddf89100a) ([nnn3d](https://github.com/nnn3d))
- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/349c95d7800810ab03b7f2cab4a058e6e988833c) ([nnn3d](https://github.com/nnn3d))
- [FI-494: review fixes](https://github.com/joomcode/e2ed/commit/ef71561bedc4a27428b27bfbecc84fcc106c69e3) ([nnn3d](https://github.com/nnn3d))
- [FI-494: fix prettier](https://github.com/joomcode/e2ed/commit/daa939c3088ef1e41390e79ec2d5293fbe2a578f) ([nnn3d](https://github.com/nnn3d))
- [Merge branch 'main' into FI-494](https://github.com/joomcode/e2ed/commit/ab4f9114b4e3694c363e53f5a2567fed8c77bf4a) ([nnn3d](https://github.com/nnn3d))
- [FI-494: remove default selector exports](https://github.com/joomcode/e2ed/commit/b03ad55d24c53d58fc217efc70b74ec876a4c2a2) ([nnn3d](https://github.com/nnn3d))
- [FI-494: add selectors with custom methods](https://github.com/joomcode/e2ed/commit/3e577d3b7dd113eaba2a135b1bd362e9eeca8d90) ([nnn3d](https://github.com/nnn3d))

## [v0.15.10](https://github.com/joomcode/e2ed/tree/v0.15.10) (2023-11-15)

Expand Down Expand Up @@ -153,12 +153,12 @@

fix: change `tsconfig.json` options to more explicit ones (`"module": "CommonJS"`)

- [Torchinskiy Merge pull request #38 from joomcode/FI-901](https://github.com/joomcode/e2ed/commit/b401f8323cdb0d19ffeb380e75ccdd83fac13e0f) ([Nikita](https://github.com/Nikita))
- [Merge pull request #38 from joomcode/FI-901](https://github.com/joomcode/e2ed/commit/b401f8323cdb0d19ffeb380e75ccdd83fac13e0f) ([nnn3d](https://github.com/nnn3d))

fix(report): link color styles for dark theme

- [Torchinskiy fix(report): color contrast and var name](https://github.com/joomcode/e2ed/commit/7d09f1c37edd9f7dd6e8ad064f2863f519c544b4) ([Nikita](https://github.com/Nikita))
- [fix(report): link color styles for dark theme](https://github.com/joomcode/e2ed/commit/7cf3da6c6db555969f8d3b7098c96a92f952df76) ([Nikita_Torchinskiy](https://github.com/Nikita_Torchinskiy))
- [fix(report): color contrast and var name](https://github.com/joomcode/e2ed/commit/7d09f1c37edd9f7dd6e8ad064f2863f519c544b4) ([nnn3d](https://github.com/nnn3d))
- [fix(report): link color styles for dark theme](https://github.com/joomcode/e2ed/commit/7cf3da6c6db555969f8d3b7098c96a92f952df76) ([nnn3d](https://github.com/nnn3d))

## [v0.15.4](https://github.com/joomcode/e2ed/tree/v0.15.4) (2023-10-11)

Expand Down
26 changes: 17 additions & 9 deletions autotests/pageObjects/pages/E2edReportExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {locatorIdSelector} from 'autotests/selectors';
import {Page} from 'e2ed';
import {setReadonlyProperty} from 'e2ed/utils';

import type {Cookie} from 'e2ed/types';
import type {Cookie, Selector} from 'e2ed/types';

type CustomPageParams = {pageCookies?: readonly Cookie[]} | undefined;

Expand All @@ -19,29 +19,37 @@ export class E2edReportExample extends Page<CustomPageParams> {

override readonly pageStabilizationInterval = 600;

override init(): void {
override init(this: E2edReportExample): void {
const {pageCookies = []} = this.pageParams ?? {};

setReadonlyProperty(this as E2edReportExample, 'pageCookies', pageCookies);
setReadonlyProperty(this, 'pageCookies', pageCookies);
}

getRoute(): E2edReportExampleRoute {
return new E2edReportExampleRoute();
}

/** Navigation bar with test retries */
readonly navigationRetries = locatorIdSelector('app-navigation-retries');
readonly navigationRetries: Selector = locatorIdSelector('app-navigation-retries');

/** Button tabs in navigation bar with test retries */
readonly navigationRetriesButton = this.navigationRetries.findByLocatorId(
readonly navigationRetriesButton: Selector = this.navigationRetries.findByLocatorId(
'app-navigation-retries-button',
);

/** Selected button tab in navigation bar with test retries */
readonly navigationRetriesButtonSelected = this.navigationRetriesButton.filterByLocatorParameter(
'selected',
'true',
);
readonly navigationRetriesButtonSelected: Selector =
this.navigationRetriesButton.filterByLocatorParameter('selected', 'true');

/**
* List of test runs of retry.
*/
readonly testRunsList: Selector = locatorIdSelector('app-column1');

/**
* Test run button.
*/
readonly testRunButton: Selector = this.testRunsList.findByLocatorId('app-retries-retry-button');

/**
* Set page cookies to context before navigate.
Expand Down
9 changes: 8 additions & 1 deletion autotests/tests/e2edReportExample/customSelectorMethods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {it} from 'autotests';
import {E2edReportExample} from 'autotests/pageObjects/pages';
import {expect} from 'e2ed';
import {navigateToPage} from 'e2ed/actions';
import {click, navigateToPage} from 'e2ed/actions';

it('custom selector methods', {meta: {testId: '15'}}, async () => {
const reportPage = await navigateToPage(E2edReportExample);
Expand Down Expand Up @@ -33,4 +33,11 @@ it('custom selector methods', {meta: {testId: '15'}}, async () => {
).eql(
'[data-testid="app-navigation-retries"].findByLocatorId(app-navigation-retries-button).filterByLocatorParameter(selected, true)',
);

await click(reportPage.navigationRetriesButton);

await expect(
reportPage.testRunButton.nth(2).getLocatorParameter('status'),
'nested selectors also get custom methods',
).eql('passed');
});
24 changes: 24 additions & 0 deletions autotests/tests/internalTypeTests/selectors.skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ createSelectorByCss('id').findByLocatorId('id').find('body').findByLocatorId('id
// ok
locatorIdSelector('id').findByLocatorId('id').find('body').findByLocatorId('id');

// @ts-expect-error: wrong number of arguments
locatorIdSelector();

// @ts-expect-error: wrong type of arguments
locatorIdSelector(3);

// ok
htmlElementSelector.filterByLocatorId('id');
// ok
Expand Down Expand Up @@ -53,6 +59,24 @@ htmlElementSelector.nextSiblingByLocatorParameter('prop', 'value');
// ok
htmlElementSelector.prevSiblingByLocatorParameter('prop', 'value');

// ok
void htmlElementSelector.getLocatorId();

// @ts-expect-error: wrong number of arguments

Check failure on line 65 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / build-docker

Unused '@ts-expect-error' directive.

Check failure on line 65 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / lint

Unused '@ts-expect-error' directive.

Check failure on line 65 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / lint

Unused '@ts-expect-error' directive.

Check failure on line 65 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / test-local

Unused '@ts-expect-error' directive.
void htmlElementSelector.getLocatorId('foo');

// ok
void htmlElementSelector.hasLocatorId();

// @ts-expect-error: wrong number of arguments

Check failure on line 71 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / build-docker

Unused '@ts-expect-error' directive.

Check failure on line 71 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / lint

Unused '@ts-expect-error' directive.

Check failure on line 71 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / lint

Unused '@ts-expect-error' directive.

Check failure on line 71 in autotests/tests/internalTypeTests/selectors.skip.ts

View workflow job for this annotation

GitHub Actions / test-local

Unused '@ts-expect-error' directive.
void htmlElementSelector.hasLocatorId('foo');

// @ts-expect-error: wrong number of arguments
void htmlElementSelector.hasLocatorParameter();

// @ts-expect-error: wrong number of arguments
void htmlElementSelector.getLocatorParameter();

// ok
void htmlElementSelector.getLocatorParameter('prop');
// ok
Expand Down
2 changes: 1 addition & 1 deletion src/actions/typeText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const typeText = async (
LogEventType.InternalAction,
);

await testController.typeText(selector as TestCafeSelector, text, options);
await testController.typeText(selector as unknown as TestCafeSelector, text, options);

await waitForInterfaceStabilization(stabilizationInterval);
};
9 changes: 6 additions & 3 deletions src/selectors/createCustomMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DESCRIPTION_KEY} from '../constants/internal';
import {getDescriptionFromSelector} from '../utils/locators';

import type {GetLocatorAttributeNameFn, SelectorCustomMethods} from '../types/internal';
import type {GetLocatorAttributeNameFn, Selector, SelectorCustomMethods} from '../types/internal';

/**
* Creates native `e2ed` methods of selector.
Expand Down Expand Up @@ -60,6 +60,9 @@ export const createCustomMethods = (
getLocatorId() {
return this.getAttribute(locatorIdAttributeName);
},
hasLocatorId() {
return this.hasAttribute(locatorIdAttributeName);
},
getLocatorParameter(parameter) {
return this.getAttribute(getLocatorAttributeName(parameter));
},
Expand All @@ -68,7 +71,7 @@ export const createCustomMethods = (
},

getDescription(): string | undefined {
return (this as {[DESCRIPTION_KEY]?: string})[DESCRIPTION_KEY];
return getDescriptionFromSelector(this as unknown as Selector);
},
};
/* eslint-enable sort-keys */
Expand Down
19 changes: 10 additions & 9 deletions src/selectors/createSelectorCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
Fn,
Selector as SelectorType,
SelectorCustomMethods,
TestCafeSelector,
Values,
} from '../types/internal';

Expand All @@ -24,10 +25,10 @@ const createGet = (
: undefined;

let result = (
customMethod ? customMethod.bind(target) : Reflect.get(target, property, receiver)
) as Values<SelectorType> & {
[DESCRIPTION_KEY]?: string;
};
customMethod
? customMethod.bind(target as unknown as TestCafeSelector)
: Reflect.get(target, property, receiver)
) as Values<SelectorType> & {[DESCRIPTION_KEY]?: string};

if (typeof property === 'symbol') {
return result;
Expand All @@ -51,9 +52,9 @@ const createGet = (
return callResult;
}

const callLocator = `${result[DESCRIPTION_KEY]}(${args.join(', ')})`;
const callDescription = `${result[DESCRIPTION_KEY]}(${args.join(', ')})`;

(callResult as typeof result)[DESCRIPTION_KEY] = callLocator;
(callResult as typeof result)[DESCRIPTION_KEY] = callDescription;

// callResult is Selector
if (Object.prototype.hasOwnProperty.call(callResult, 'getBoundingClientRectProperty')) {
Expand All @@ -64,9 +65,9 @@ const createGet = (
} as typeof result;
}

const locator = target[DESCRIPTION_KEY] || '';
const description = target[DESCRIPTION_KEY] || '';

result[DESCRIPTION_KEY] = `${locator}.${property}`;
result[DESCRIPTION_KEY] = `${description}.${property}`;

return result;
};
Expand All @@ -81,7 +82,7 @@ const createGet = (
export const createSelectorCreator = (customMethods: SelectorCustomMethods): CreateSelector => {
const createSelector: CreateSelector = (...args) => {
const locator = args[0];
const selector = Selector(...args) as SelectorType;
const selector = Selector(...args) as unknown as SelectorType;

if (typeof locator === 'string') {
setReadonlyProperty(selector, DESCRIPTION_KEY, locator);
Expand Down
5 changes: 3 additions & 2 deletions src/types/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export type LocatorIdSelector = (this: void, id: string) => Selector;
/**
* Selector type (which replaces the DOM element wrapper).
*/
export type Selector = ((this: void, ...args: unknown[]) => Inner.SelectorPromise) &
ReplaceObjectSelectors<Inner.SelectorAPI> &
export type Selector = ReplaceObjectSelectors<Inner.SelectorAPI> &
ReplaceObjectSelectors<SelectorCustomMethods> &
Readonly<{[DESCRIPTION_KEY]?: string}>;

Expand Down Expand Up @@ -124,6 +123,8 @@ export type SelectorCustomMethods = Readonly<{

/** Returns the value of the locator id. */
getLocatorId(this: Inner.Selector): Promise<string | null>;
/** true if the element has the locator id. */
hasLocatorId(this: Inner.Selector): Promise<boolean>;
/** Returns the value of the locator parameter. */
getLocatorParameter(this: Inner.Selector, parameter: string): Promise<string | null>;
/** true if the element has the locator parameter. */
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ export {setReadonlyProperty} from './setReadonlyProperty';
export {getPackageInfo} from './startInfo';
export {wrapInTestRunTracker} from './testRun';
export {isArray} from './typeGuards';
export {valueToString} from './valueToString';
export {getStringTrimmedToMaxLength, valueToString} from './valueToString';
export {isSelectorEntirelyInViewport, isSelectorInViewport} from './viewport';
9 changes: 1 addition & 8 deletions src/utils/mockApiRoute/getSetResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ export const getSetResponse =

log(
`A mock was applied to the API route "${route.constructor.name}"`,
{
apiMockFunction,
mainRequestOptions,
request,
response,
responseOptions,
route,
},
{apiMockFunction, request, response, route},
LogEventType.InternalCore,
);
};
2 changes: 1 addition & 1 deletion src/utils/report/render/renderRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const renderRetry = ({retry, ...rest}: Props): SafeHtml => {
return createSafeHtmlWithoutSanitize`
<article class="retry" id="retry${retry.retryIndex}" ${
retry.hidden ? 'hidden' : ''
} {${renderAttributes(locator({index: String(retry.retryIndex)}))}}>
} ${renderAttributes(locator({index: String(retry.retryIndex)}))}>
${renderRetryHeader({...retry, ...locator.header()})}
${buttons.join('')}
</article>`;
Expand Down
10 changes: 6 additions & 4 deletions src/utils/valueToString/getStringTrimmedToMaxLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import {MAX_STRING_LENGTH_IN_PRINTED_VALUE} from '../../constants/internal';

/**
* Get string trimmed to max string length in printed value.
* @internal
*/
export const getStringTrimmedToMaxLength = (text: string): string => {
if (text.length <= MAX_STRING_LENGTH_IN_PRINTED_VALUE) {
export const getStringTrimmedToMaxLength = (
text: string,
maxStringLength = MAX_STRING_LENGTH_IN_PRINTED_VALUE,
): string => {
if (text.length <= maxStringLength) {
return text;
}

const halfOfLength = Math.floor(MAX_STRING_LENGTH_IN_PRINTED_VALUE / 2);
const halfOfLength = Math.floor(maxStringLength / 2);
const numberOfCuttedSymbols = text.length - 2 * halfOfLength;

return `${text.slice(0, halfOfLength)}...(${numberOfCuttedSymbols} symbols)...${text.slice(
Expand Down
1 change: 1 addition & 0 deletions src/utils/valueToString/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {getStringTrimmedToMaxLength} from './getStringTrimmedToMaxLength';
export {valueToString} from './valueToString';
/** @internal */
export {wrapStringForLogs} from './wrapStringForLogs';

0 comments on commit d50abb3

Please sign in to comment.