From 457e51a83b2bcd3493b994a01ddd37561a2c1e22 Mon Sep 17 00:00:00 2001 From: uid11 Date: Tue, 19 Nov 2024 06:37:11 +0300 Subject: [PATCH] FI-1434 fix: logs of actual values in `expect`'s assert functions chore: updat Playwright to 1.49.0 chore: update devDependencies (`husky`, etc) --- package-lock.json | 60 +++++++++++----------- package.json | 8 +-- src/utils/expect/applyAdditionalMatcher.ts | 12 +++-- src/utils/expect/createExpectMethod.ts | 49 ++++++++---------- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index 340ee5e4..57612bce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,18 +9,19 @@ "version": "0.18.16", "license": "MIT", "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" }, "bin": { "e2ed": "bin/runE2edInLocalEnvironment.js", - "e2ed-init": "bin/init.js" + "e2ed-init": "bin/init.js", + "e2ed-install-browsers": "bin/installBrowsers.sh" }, "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", @@ -31,7 +32,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" }, @@ -179,26 +180,26 @@ } }, "node_modules/@playwright/browser-chromium": { - "version": "1.48.2", - "resolved": "https://registry.npmjs.org/@playwright/browser-chromium/-/browser-chromium-1.48.2.tgz", - "integrity": "sha512-TvYJ5PFaDPYNlKpvPSftBbPTnu75VdRKjoMjmkd7/P79rFIBD+v6K4wU8XR6PlAqqFdPcfLL5XXZnRwTRixbDQ==", + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/@playwright/browser-chromium/-/browser-chromium-1.49.0.tgz", + "integrity": "sha512-SnDBEmw0h4XpbHcWR8T0LgLj1Cqn8Cvql+Nahot2zBud945z+MYXH3WVPvMI5U37WsWAgw9Cj7pZ6oL7haKrhg==", "dev": true, "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.48.2" + "playwright-core": "1.49.0" }, "engines": { "node": ">=18" } }, "node_modules/@playwright/test": { - "version": "1.48.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.48.2.tgz", - "integrity": "sha512-54w1xCWfXuax7dz4W2M9uw0gDyh+ti/0K/MxcCUxChFh37kkdxPdfZDw5QBbuPUJHr1CiHJ1hXgSs+GgeQc5Zw==", + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.0.tgz", + "integrity": "sha512-DMulbwQURa8rNIQrf94+jPJQ4FmOVdpE5ZppRNvWVjvhC+6sOeo28r8MgIpQRYouXRtt/FCCXU7zn20jnHR4Qw==", "license": "Apache-2.0", "dependencies": { - "playwright": "1.48.2" + "playwright": "1.49.0" }, "bin": { "playwright": "cli.js" @@ -227,9 +228,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.8.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.7.tgz", - "integrity": "sha512-LidcG+2UeYIWcMuMUpBKOnryBWG/rnmOHQR5apjn8myTQcx3rinFRn7DcIFhMnS0PPFSC6OafdIKEad0lj6U0Q==", + "version": "22.9.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", + "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", "dev": true, "license": "MIT", "dependencies": { @@ -750,10 +751,11 @@ "license": "MIT" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -2065,9 +2067,9 @@ } }, "node_modules/husky": { - "version": "9.1.6", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.6.tgz", - "integrity": "sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==", + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", "dev": true, "license": "MIT", "bin": { @@ -2729,12 +2731,12 @@ } }, "node_modules/playwright": { - "version": "1.48.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.48.2.tgz", - "integrity": "sha512-NjYvYgp4BPmiwfe31j4gHLa3J7bD2WiBz8Lk2RoSsmX38SVIARZ18VYjxLjAcDsAhA+F4iSEXTSGgjua0rrlgQ==", + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.0.tgz", + "integrity": "sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==", "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.48.2" + "playwright-core": "1.49.0" }, "bin": { "playwright": "cli.js" @@ -2747,9 +2749,9 @@ } }, "node_modules/playwright-core": { - "version": "1.48.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.48.2.tgz", - "integrity": "sha512-sjjw+qrLFlriJo64du+EK0kJgZzoQPsabGF4lBvsid+3CNIZIYLgnMj9V6JY5VhM2Peh20DJWIVpVljLLnlawA==", + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.0.tgz", + "integrity": "sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==", "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" diff --git a/package.json b/package.json index 950ac51f..b1544c40 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/src/utils/expect/applyAdditionalMatcher.ts b/src/utils/expect/applyAdditionalMatcher.ts index cb8ef6ae..fdd256ad 100644 --- a/src/utils/expect/applyAdditionalMatcher.ts +++ b/src/utils/expect/applyAdditionalMatcher.ts @@ -16,13 +16,15 @@ export const applyAdditionalMatcher = ( args: unknown[], selectorPropertyRetryData: SelectorPropertyRetryData | undefined, // eslint-disable-next-line @typescript-eslint/max-params -): Promise => { +): Promise => { 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; @@ -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); }; diff --git a/src/utils/expect/createExpectMethod.ts b/src/utils/expect/createExpectMethod.ts index bd3f75b1..b0a8b132 100644 --- a/src/utils/expect/createExpectMethod.ts +++ b/src/utils/expect/createExpectMethod.ts @@ -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. @@ -32,7 +31,7 @@ export const createExpectMethod = ( ): ExpectMethod => // eslint-disable-next-line no-restricted-syntax function method(...args: Parameters) { - assertionTimeout ??= getFullPackConfig().assertionTimeout; + const {assertionTimeout} = getFullPackConfig(); const timeout = assertionTimeout + additionalAssertionTimeoutInMs; const message = getAssertionMessage === undefined ? key : getAssertionMessage(...args); @@ -42,15 +41,11 @@ export const createExpectMethod = ( `"${key}" assertion promise rejected after ${timeoutWithUnits} timeout`, ); - const runAssertion = (value: unknown): Promise => { + const runAssertion = (value: unknown): Promise => { 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]; @@ -70,35 +65,33 @@ export const createExpectMethod = ( const assertion = expect(value) as unknown as Record>>; // 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, timeout, error).then( - runAssertion, - ); - } - - return runAssertion(this.actualValue); - }).then( - () => undefined, - (assertionError: Error) => assertionError, - ); - - return assertionPromise.then((maybeError) => { + const assertionPromise: Promise> = + RESOLVED_PROMISE.then(() => { + if (isThenable(this.actualValue)) { + return addTimeoutToPromise(this.actualValue as Promise, 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(