Skip to content

Commit

Permalink
FI-1434 fix: logs of actual values in expect's assert functions
Browse files Browse the repository at this point in the history
chore: updat Playwright to 1.49.0
chore: update devDependencies (`husky`, etc)
  • Loading branch information
uid11 committed Nov 19, 2024
1 parent f7da93c commit 457e51a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 65 deletions.
60 changes: 31 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"url": "git+https://github.com/joomcode/e2ed.git"
},
"dependencies": {
"@playwright/test": "1.48.2",
"@playwright/test": "1.49.0",
"create-locator": "0.0.25",
"get-modules-graph": "0.0.9",
"globby": "11.1.0"
},
"devDependencies": {
"@playwright/browser-chromium": "1.48.2",
"@types/node": "22.8.7",
"@playwright/browser-chromium": "1.49.0",
"@types/node": "22.9.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
Expand All @@ -43,7 +43,7 @@
"eslint-plugin-import": "2.31.0",
"eslint-plugin-simple-import-sort": "12.1.1",
"eslint-plugin-typescript-sort-keys": "3.3.0",
"husky": "9.1.6",
"husky": "9.1.7",
"prettier": "3.3.3",
"typescript": "5.6.3"
},
Expand Down
12 changes: 8 additions & 4 deletions src/utils/expect/applyAdditionalMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const applyAdditionalMatcher = (
args: unknown[],
selectorPropertyRetryData: SelectorPropertyRetryData | undefined,
// eslint-disable-next-line @typescript-eslint/max-params
): Promise<unknown> => {
): Promise<Expect> => {
if (selectorPropertyRetryData === undefined) {
return matcher.apply(ctx, args);
return matcher.apply(ctx, args).then(() => ctx);
}

const {assertionTimeout} = getFullPackConfig();

let context: Expect;

return expect(() => {
const {args: selectorArgs, property, selector} = selectorPropertyRetryData;

Expand All @@ -34,9 +36,11 @@ export const applyAdditionalMatcher = (
);

return actualValue.then((value) => {
const context: Expect = {actualValue: value, description: ctx.description};
context = {actualValue: value, description: ctx.description};

return matcher.apply(context, args);
});
}).toPass({timeout: assertionTimeout});
})
.toPass({timeout: assertionTimeout})
.then(() => context);
};
49 changes: 21 additions & 28 deletions src/utils/expect/createExpectMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {AssertionFunction, ExpectMethod} from './types';
import {expect} from '@playwright/test';

const additionalAssertionTimeoutInMs = 1_000;
let assertionTimeout: number | undefined;

/**
* Creates method of `Expect` class.
Expand All @@ -32,7 +31,7 @@ export const createExpectMethod = (
): ExpectMethod =>
// eslint-disable-next-line no-restricted-syntax
function method(...args: Parameters<ExpectMethod>) {
assertionTimeout ??= getFullPackConfig().assertionTimeout;
const {assertionTimeout} = getFullPackConfig();

const timeout = assertionTimeout + additionalAssertionTimeoutInMs;
const message = getAssertionMessage === undefined ? key : getAssertionMessage(...args);
Expand All @@ -42,15 +41,11 @@ export const createExpectMethod = (
`"${key}" assertion promise rejected after ${timeoutWithUnits} timeout`,
);

const runAssertion = (value: unknown): Promise<unknown> => {
const runAssertion = (value: unknown): Promise<Expect> => {
const additionalMatcher = additionalMatchers[key as keyof typeof additionalMatchers];
const ctx: Expect = {actualValue: value, description: this.description};

if (additionalMatcher !== undefined) {
const ctx: Expect = {
actualValue: value,
description: this.description,
};

const selectorPropertyRetryData = (
this.actualValue as {[RETRY_KEY]?: SelectorPropertyRetryData}
)?.[RETRY_KEY];
Expand All @@ -70,35 +65,33 @@ export const createExpectMethod = (
const assertion = expect(value) as unknown as Record<string, Fn<unknown[], Promise<unknown>>>;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return addTimeoutToPromise(assertion[key]!(...args), timeout, error);
return addTimeoutToPromise(assertion[key]!(...args), timeout, error).then(() => ctx);
};

const assertionPromise = RESOLVED_PROMISE.then(() => {
if (isThenable(this.actualValue)) {
return addTimeoutToPromise(this.actualValue as Promise<unknown>, timeout, error).then(
runAssertion,
);
}

return runAssertion(this.actualValue);
}).then(
() => undefined,
(assertionError: Error) => assertionError,
);

return assertionPromise.then((maybeError) => {
const assertionPromise: Promise<Readonly<{maybeError?: Error; value?: unknown}>> =
RESOLVED_PROMISE.then(() => {
if (isThenable(this.actualValue)) {
return addTimeoutToPromise(this.actualValue as Promise<unknown>, timeout, error).then(
runAssertion,
);
}

return runAssertion(this.actualValue);
}).then(
({actualValue}) => ({value: actualValue}),
(maybeError: Error) => ({maybeError}),
);

return assertionPromise.then(({maybeError, value}) => {
const logMessage = `Assert: ${this.description}`;
const logPayload = {
assertionArguments: args,
description:
this.actualValue != null
? getDescriptionFromSelector(this.actualValue as Selector)
: undefined,
description: value != null ? getDescriptionFromSelector(value as Selector) : undefined,
error: maybeError,
logEventStatus: maybeError ? LogEventStatus.Failed : LogEventStatus.Passed,
};

return addTimeoutToPromise(Promise.resolve(this.actualValue), timeout, error)
return addTimeoutToPromise(Promise.resolve(value), timeout, error)
.then(
(actualValue) =>
log(
Expand Down

0 comments on commit 457e51a

Please sign in to comment.