diff --git a/package-lock.json b/package-lock.json index 1c32fead..08e86108 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,8 @@ "devDependencies": { "@playwright/browser-chromium": "1.45.3", "@types/node": "22.0.0", - "@typescript-eslint/eslint-plugin": "7.17.0", - "@typescript-eslint/parser": "7.17.0", + "@typescript-eslint/eslint-plugin": "7.18.0", + "@typescript-eslint/parser": "7.18.0", "assert-modules-support-case-insensitive-fs": "1.0.1", "assert-package-lock-is-consistent": "1.0.0", "eslint": "8.57.0", @@ -32,7 +32,7 @@ "eslint-plugin-import": "2.29.1", "eslint-plugin-simple-import-sort": "12.1.1", "eslint-plugin-typescript-sort-keys": "3.2.0", - "husky": "9.1.3", + "husky": "9.1.4", "prettier": "3.3.3", "typescript": "5.5.4" }, @@ -229,16 +229,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.17.0.tgz", - "integrity": "sha512-pyiDhEuLM3PuANxH7uNYan1AaFs5XE0zw1hq69JBvGvE7gSuEoQl1ydtEe/XQeoC3GQxLXyOVa5kNOATgM638A==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz", + "integrity": "sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.17.0", - "@typescript-eslint/type-utils": "7.17.0", - "@typescript-eslint/utils": "7.17.0", - "@typescript-eslint/visitor-keys": "7.17.0", + "@typescript-eslint/scope-manager": "7.18.0", + "@typescript-eslint/type-utils": "7.18.0", + "@typescript-eslint/utils": "7.18.0", + "@typescript-eslint/visitor-keys": "7.18.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -262,15 +262,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.17.0.tgz", - "integrity": "sha512-puiYfGeg5Ydop8eusb/Hy1k7QmOU6X3nvsqCgzrB2K4qMavK//21+PzNE8qeECgNOIoertJPUC1SpegHDI515A==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz", + "integrity": "sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.17.0", - "@typescript-eslint/types": "7.17.0", - "@typescript-eslint/typescript-estree": "7.17.0", - "@typescript-eslint/visitor-keys": "7.17.0", + "@typescript-eslint/scope-manager": "7.18.0", + "@typescript-eslint/types": "7.18.0", + "@typescript-eslint/typescript-estree": "7.18.0", + "@typescript-eslint/visitor-keys": "7.18.0", "debug": "^4.3.4" }, "engines": { @@ -290,13 +290,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.17.0.tgz", - "integrity": "sha512-0P2jTTqyxWp9HiKLu/Vemr2Rg1Xb5B7uHItdVZ6iAenXmPo4SZ86yOPCJwMqpCyaMiEHTNqizHfsbmCFT1x9SA==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz", + "integrity": "sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.17.0", - "@typescript-eslint/visitor-keys": "7.17.0" + "@typescript-eslint/types": "7.18.0", + "@typescript-eslint/visitor-keys": "7.18.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -307,13 +307,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.17.0.tgz", - "integrity": "sha512-XD3aaBt+orgkM/7Cei0XNEm1vwUxQ958AOLALzPlbPqb8C1G8PZK85tND7Jpe69Wualri81PLU+Zc48GVKIMMA==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz", + "integrity": "sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.17.0", - "@typescript-eslint/utils": "7.17.0", + "@typescript-eslint/typescript-estree": "7.18.0", + "@typescript-eslint/utils": "7.18.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -334,9 +334,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.17.0.tgz", - "integrity": "sha512-a29Ir0EbyKTKHnZWbNsrc/gqfIBqYPwj3F2M+jWE/9bqfEHg0AMtXzkbUkOG6QgEScxh2+Pz9OXe11jHDnHR7A==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz", + "integrity": "sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -347,13 +347,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.17.0.tgz", - "integrity": "sha512-72I3TGq93t2GoSBWI093wmKo0n6/b7O4j9o8U+f65TVD0FS6bI2180X5eGEr8MA8PhKMvYe9myZJquUT2JkCZw==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz", + "integrity": "sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.17.0", - "@typescript-eslint/visitor-keys": "7.17.0", + "@typescript-eslint/types": "7.18.0", + "@typescript-eslint/visitor-keys": "7.18.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -399,15 +399,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.17.0.tgz", - "integrity": "sha512-r+JFlm5NdB+JXc7aWWZ3fKSm1gn0pkswEwIYsrGPdsT2GjsRATAKXiNtp3vgAAO1xZhX8alIOEQnNMl3kbTgJw==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.18.0.tgz", + "integrity": "sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.17.0", - "@typescript-eslint/types": "7.17.0", - "@typescript-eslint/typescript-estree": "7.17.0" + "@typescript-eslint/scope-manager": "7.18.0", + "@typescript-eslint/types": "7.18.0", + "@typescript-eslint/typescript-estree": "7.18.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -421,12 +421,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.17.0.tgz", - "integrity": "sha512-RVGC9UhPOCsfCdI9pU++K4nD7to+jTcMIbXTSOcrLqUEW6gF2pU1UUbYJKc9cvcRSK1UDeMJ7pdMxf4bhMpV/A==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz", + "integrity": "sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.17.0", + "@typescript-eslint/types": "7.18.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1902,9 +1902,9 @@ } }, "node_modules/husky": { - "version": "9.1.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.3.tgz", - "integrity": "sha512-ET3TQmQgdIu0pt+jKkpo5oGyg/4MQZpG6xcam5J5JyNJV+CBT23OBpCF15bKHKycRyMH9k6ONy8g2HdGIsSkMQ==", + "version": "9.1.4", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.4.tgz", + "integrity": "sha512-bho94YyReb4JV7LYWRWxZ/xr6TtOTt8cMfmQ39MQYJ7f/YE268s3GdghGwi+y4zAeqewE5zYLvuhV0M0ijsDEA==", "dev": true, "bin": { "husky": "bin.js" diff --git a/package.json b/package.json index ef62e706..e6901f20 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "devDependencies": { "@playwright/browser-chromium": "1.45.3", "@types/node": "22.0.0", - "@typescript-eslint/eslint-plugin": "7.17.0", - "@typescript-eslint/parser": "7.17.0", + "@typescript-eslint/eslint-plugin": "7.18.0", + "@typescript-eslint/parser": "7.18.0", "assert-modules-support-case-insensitive-fs": "1.0.1", "assert-package-lock-is-consistent": "1.0.0", "eslint": "8.57.0", @@ -43,7 +43,7 @@ "eslint-plugin-import": "2.29.1", "eslint-plugin-simple-import-sort": "12.1.1", "eslint-plugin-typescript-sort-keys": "3.2.0", - "husky": "9.1.3", + "husky": "9.1.4", "prettier": "3.3.3", "typescript": "5.5.4" }, diff --git a/src/constants/internal.ts b/src/constants/internal.ts index 7f0512de..8db0562f 100644 --- a/src/constants/internal.ts +++ b/src/constants/internal.ts @@ -33,7 +33,7 @@ export { } from './inspect'; export {LogEventStatus, LogEventType} from './log'; /** @internal */ -export {MESSAGE_BACKGROUND_COLOR_BY_STATUS, TESTCAFE_WARNINGS_KEY} from './log'; +export {MESSAGE_BACKGROUND_COLOR_BY_STATUS} from './log'; export {CREATE_PAGE_TOKEN} from './pages'; /** @internal */ export { diff --git a/src/constants/log.ts b/src/constants/log.ts index da497cde..b14884c5 100644 --- a/src/constants/log.ts +++ b/src/constants/log.ts @@ -38,9 +38,3 @@ export const MESSAGE_BACKGROUND_COLOR_BY_STATUS: Readonly< [TestRunStatus.Manual]: ConsoleBackgroundColor.YellowGreen, [TestRunStatus.Broken]: ConsoleBackgroundColor.Yellow, }; - -/** - * The symbolic key under which the global object can contain warnings from TestCafe. - * @internal - */ -export const TESTCAFE_WARNINGS_KEY = Symbol.for('testcafe-reporter-for-e2ed:testcafe-warnings'); diff --git a/src/types/retries.ts b/src/types/retries.ts index 0aae9032..c88fbe2f 100644 --- a/src/types/retries.ts +++ b/src/types/retries.ts @@ -23,7 +23,6 @@ export type RetriesState = Readonly<{ * @internal */ export type RunRetryOptions = Readonly<{ - concurrency: number; runLabel: RunLabel; successfulTestRunNamesHash: VisitedTestNamesHash; visitedTestNamesHash: VisitedTestNamesHash; diff --git a/src/types/runLabel.ts b/src/types/runLabel.ts index 1dad222f..2e1e8c8b 100644 --- a/src/types/runLabel.ts +++ b/src/types/runLabel.ts @@ -12,7 +12,6 @@ export type RunLabel = Brand; */ export type RunLabelObject = Readonly<{ concurrency: number; - disconnectedBrowsersCount: number; maxRetriesCount: number; retryIndex: number; }>; @@ -22,5 +21,5 @@ export type RunLabelObject = Readonly<{ * @internal */ export type RawRunLabelObject = { - [K in keyof RunLabelObject]: string; + [Key in keyof RunLabelObject]: string; }; diff --git a/src/utils/events/registerEndTestRunEvent.ts b/src/utils/events/registerEndTestRunEvent.ts index f0c15c20..5cf90c4d 100644 --- a/src/utils/events/registerEndTestRunEvent.ts +++ b/src/utils/events/registerEndTestRunEvent.ts @@ -92,7 +92,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent): const fullTestRun: FullTestRun = {mainParams, runHash, ...testRun}; - logEndTestRunEvent(fullTestRun); + await logEndTestRunEvent(fullTestRun); await writeTestRunToJsonFile(fullTestRun); await writeLogsToFile(); diff --git a/src/utils/fs/readEventsFromFiles.ts b/src/utils/fs/readEventsFromFiles.ts index 48c1412b..7a9a1f7d 100644 --- a/src/utils/fs/readEventsFromFiles.ts +++ b/src/utils/fs/readEventsFromFiles.ts @@ -41,7 +41,7 @@ export const readEventsFromFiles = async ( fileIndex < newEventFiles.length; fileIndex += AMOUNT_OF_PARALLEL_OPEN_FILES ) { - const readPromises: Promise[] = []; + const readPromises: Promise>[] = []; for ( let index = fileIndex; @@ -57,17 +57,25 @@ export const readEventsFromFiles = async ( }); const filePath = join(EVENTS_DIRECTORY_PATH, fileName); - const promise = readFile(filePath, READ_FILE_OPTIONS); + const promise = readFile(filePath, READ_FILE_OPTIONS).then((text) => ({fileName, text})); readPromises.push(promise); } - const files = await Promise.all(readPromises); + const filesWithNames = await Promise.all(readPromises); - for (const file of files) { - const fullTestRun = JSON.parse(file) as FullTestRun; + for (const {fileName, text} of filesWithNames) { + try { + const fullTestRun = JSON.parse(text) as FullTestRun; - fullTestRuns.push(fullTestRun); + fullTestRuns.push(fullTestRun); + } catch (error) { + generalLog('Caught an error on parsing JSON of test run', { + error, + fileName, + textLenght: text.length, + }); + } } } diff --git a/src/utils/generalLog/index.ts b/src/utils/generalLog/index.ts index 4d00cabd..1ed7520f 100644 --- a/src/utils/generalLog/index.ts +++ b/src/utils/generalLog/index.ts @@ -8,10 +8,6 @@ export {failMessage, okMessage} from './messages'; export {writeLogsToFile} from './logFile'; /** @internal */ export {logStartE2edError} from './logStartE2edError'; -/** @internal */ -export {readTestCafeWarnings} from './readTestCafeWarnings'; export {removeStyleFromString} from './removeStyleFromString'; /** @internal */ export {truncateArrayForLogs} from './truncateArrayForLogs'; -/** @internal */ -export {setSuccessfulTotalInPreviousRetries} from './successfulTestRunCount'; diff --git a/src/utils/generalLog/logEndTestRunEvent.ts b/src/utils/generalLog/logEndTestRunEvent.ts index b5f5e758..9785f871 100644 --- a/src/utils/generalLog/logEndTestRunEvent.ts +++ b/src/utils/generalLog/logEndTestRunEvent.ts @@ -14,11 +14,11 @@ import type {FullTestRun} from '../../types/internal'; * Logs an end of test run event. * @internal */ -export const logEndTestRunEvent = (fullTestRun: FullTestRun): void => { +export const logEndTestRunEvent = async (fullTestRun: FullTestRun): Promise => { const {filePath, mainParams, name, options, runError, runId, status} = fullTestRun; if (FAILED_TEST_RUN_STATUSES.includes(status) === false) { - addSuccessfulInCurrentRetry(); + await addSuccessfulInCurrentRetry(filePath); } const messageBackgroundColor = MESSAGE_BACKGROUND_COLOR_BY_STATUS[status]; @@ -26,7 +26,7 @@ export const logEndTestRunEvent = (fullTestRun: FullTestRun): void => { const messageText = `${messageSymbol} ${status} ${mainParams} ${name}`; const message = getMessageWithBackgroundColor(messageText, messageBackgroundColor); - const successful = getSuccessfulTestRunCount(); + const successful = await getSuccessfulTestRunCount(); generalLog(message, {filePath, options, runError, runId, successful}); }; diff --git a/src/utils/generalLog/readTestCafeWarnings.ts b/src/utils/generalLog/readTestCafeWarnings.ts deleted file mode 100644 index ea1a734e..00000000 --- a/src/utils/generalLog/readTestCafeWarnings.ts +++ /dev/null @@ -1,20 +0,0 @@ -import {TESTCAFE_WARNINGS_KEY} from '../../constants/internal'; - -import {generalLog} from './generalLog'; - -/** - * Reads warnings from TestCafe and logs it as usual logs with generalLog. - * @internal - */ -export const readTestCafeWarnings = (): void => { - const global = globalThis as {[TESTCAFE_WARNINGS_KEY]?: readonly string[] | undefined}; - const testCafeWarnings = global[TESTCAFE_WARNINGS_KEY]; - - if (testCafeWarnings) { - for (const warningMessage of testCafeWarnings) { - generalLog(`Warning from TestCafe: ${warningMessage}`); - } - - (testCafeWarnings as {length: number}).length = 0; - } -}; diff --git a/src/utils/generalLog/successfulTestRunCount.ts b/src/utils/generalLog/successfulTestRunCount.ts index 67b99730..5e911819 100644 --- a/src/utils/generalLog/successfulTestRunCount.ts +++ b/src/utils/generalLog/successfulTestRunCount.ts @@ -1,49 +1,39 @@ -import {assertValueIsTrue} from '../asserts'; +import {appendFile, readFile} from 'node:fs/promises'; +import {join} from 'node:path'; -/** - * The number of tests successful in the current retry. - */ -let successfulInCurrentRetry = 0; +import {READ_FILE_OPTIONS, TMP_DIRECTORY_PATH} from '../../constants/internal'; + +import type {FilePathFromRoot, TestFilePath} from '../../types/internal'; /** - * The total number of tests successful in all previous retries. + * Relative (from root) path to text file with list of not included in pack tests. + * For each not included in pack test in this file, a relative path + * to the file of this test is saved in a separate line. */ -let successfulTotalInPreviousRetries = 0; +const SUCCESSFUL_TESTS_PATH = join(TMP_DIRECTORY_PATH, 'successfulTests.txt') as FilePathFromRoot; /** * Adds one successful test run (in current retry). * @internal */ -export const addSuccessfulInCurrentRetry = (): void => { - successfulInCurrentRetry += 1; +export const addSuccessfulInCurrentRetry = async (filePath: TestFilePath): Promise => { + await appendFile(SUCCESSFUL_TESTS_PATH, `${filePath}\n`); }; /** * Get the number of tests successful for printing (total and in the current retry). * @internal */ -export const getSuccessfulTestRunCount = (): string => { - if (successfulTotalInPreviousRetries === 0) { - return String(successfulInCurrentRetry); - } +export const getSuccessfulTestRunCount = async (): Promise => { + let successfulTestsFile = ''; - const successfulTotal = successfulInCurrentRetry + successfulTotalInPreviousRetries; + try { + successfulTestsFile = await readFile(SUCCESSFUL_TESTS_PATH, READ_FILE_OPTIONS); + } catch {} - return `${successfulInCurrentRetry} in the current retry, ${successfulTotal} in total`; -}; + if (successfulTestsFile === '') { + return 0; + } -/** - * Set successful test runs total in previous retries - * @internal - */ -export const setSuccessfulTotalInPreviousRetries = ( - newSuccessfulTotalInPreviousRetries: number, -): void => { - assertValueIsTrue( - successfulTotalInPreviousRetries === 0, - 'successfulTotalInPreviousRetries is equal to 0', - {newSuccessfulTotalInPreviousRetries}, - ); - - successfulTotalInPreviousRetries = newSuccessfulTotalInPreviousRetries; + return successfulTestsFile.split('\n').filter(Boolean).length; }; diff --git a/src/utils/pack/runPackWithArgs.ts b/src/utils/pack/runPackWithArgs.ts index 527a54c8..733afdce 100644 --- a/src/utils/pack/runPackWithArgs.ts +++ b/src/utils/pack/runPackWithArgs.ts @@ -1,63 +1,24 @@ -import {spawn} from 'node:child_process'; - -import {CONFIG_PATH, e2edEnvironment, EndE2edReason} from '../../constants/internal'; +import {EndE2edReason} from '../../constants/internal'; import {getFullPackConfig} from '../config'; import {endE2ed} from '../end'; -import {setRunLabel} from '../environment'; -import {generalLog} from '../generalLog'; -import {startResourceUsageReading} from '../resourceUsage'; import {createRunLabel} from '../runLabel'; +import {runTests} from '../tests'; + +import type {VisitedTestNamesHash} from '../../types/internal'; /** * Runs e2ed pack of tests (or tasks) with command line arguments. * @internal */ export const runPackWithArgs = async (): Promise => { - const {concurrency, enableLiveMode, resourceUsageReadingInternal} = getFullPackConfig(); - const runLabel = createRunLabel({ - concurrency, - disconnectedBrowsersCount: 0, - maxRetriesCount: 1, - retryIndex: 1, - }); - - startResourceUsageReading(resourceUsageReadingInternal); - setRunLabel(runLabel); - - await new Promise((res) => { - const playwrightArgs = ['playwright', 'test', '--config', CONFIG_PATH]; - - // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions - if (e2edEnvironment.E2ED_DEBUG) { - e2edEnvironment.PWDEBUG = 'console'; - playwrightArgs.push('--debug'); - } - - const playwrightProcess = spawn('npx', playwrightArgs); - - playwrightProcess.stdout.on('data', (data) => { - const stringData = String(data).trim(); - - if (stringData !== '') { - if (stringData.startsWith('[e2ed]')) { - // eslint-disable-next-line no-console - console.log(stringData); - } else { - generalLog(stringData); - } - } - }); - playwrightProcess.stderr.on('data', (data) => generalLog(`Error: ${String(data)}`)); + const {concurrency} = getFullPackConfig(); + const runLabel = createRunLabel({concurrency, maxRetriesCount: 1, retryIndex: 1}); - playwrightProcess.on('close', () => { - res(); - }); - }); + const successfulTestRunNamesHash = Object.create(null) as VisitedTestNamesHash; + const visitedTestNamesHash = Object.create(null) as VisitedTestNamesHash; - if (enableLiveMode) { - process.argv.push('--live'); - } + await runTests({runLabel, successfulTestRunNamesHash, visitedTestNamesHash}); endE2ed(EndE2edReason.LocalRunEnded); }; diff --git a/src/utils/retry/processRetry.ts b/src/utils/retry/processRetry.ts index a298889b..3a77f6cc 100644 --- a/src/utils/retry/processRetry.ts +++ b/src/utils/retry/processRetry.ts @@ -21,12 +21,7 @@ export const processRetry = async (retriesState: RetriesState): Promise => successfulTestRunNamesHash, visitedTestNamesHash, } = retriesState; - const runLabel = createRunLabel({ - concurrency, - disconnectedBrowsersCount: 0, - maxRetriesCount, - retryIndex, - }); + const runLabel = createRunLabel({concurrency, maxRetriesCount, retryIndex}); const startLastRetryTimeInMs = Date.now() as UtcTimeInMs; const printedRetry = getPrintedRetry({maxRetriesCount, retryIndex}); @@ -40,7 +35,7 @@ export const processRetry = async (retriesState: RetriesState): Promise => try { await writeLogsToFile(); - await runRetry({concurrency, runLabel, successfulTestRunNamesHash, visitedTestNamesHash}); + await runRetry({runLabel, successfulTestRunNamesHash, visitedTestNamesHash}); setReadonlyProperty(retriesState, 'isLastRetrySuccessful', true); } catch (error) { diff --git a/src/utils/runLabel/createRunLabel.ts b/src/utils/runLabel/createRunLabel.ts index 3d32269a..b00909c3 100644 --- a/src/utils/runLabel/createRunLabel.ts +++ b/src/utils/runLabel/createRunLabel.ts @@ -6,12 +6,6 @@ import type {RunLabel, RunLabelObject} from '../../types/internal'; */ export const createRunLabel = ({ concurrency, - disconnectedBrowsersCount, maxRetriesCount, retryIndex, -}: RunLabelObject): RunLabel => { - const disconnectedBrowsersPart = - disconnectedBrowsersCount > 0 ? `-${disconnectedBrowsersCount}` : ''; - - return `r:${retryIndex}/${maxRetriesCount},c:${concurrency}${disconnectedBrowsersPart}` as RunLabel; -}; +}: RunLabelObject): RunLabel => `r:${retryIndex}/${maxRetriesCount},c:${concurrency}` as RunLabel; diff --git a/src/utils/runLabel/getRunLabelObject.ts b/src/utils/runLabel/getRunLabelObject.ts index 205c09c9..ee50a0fa 100644 --- a/src/utils/runLabel/getRunLabelObject.ts +++ b/src/utils/runLabel/getRunLabelObject.ts @@ -8,19 +8,13 @@ import type {RawRunLabelObject, RunLabel, RunLabelObject} from '../../types/inte */ export const getRunLabelObject = (runLabel: RunLabel): RunLabelObject => { const rawRunLabelObject = runLabel.match( - /r:(?\d+)\/(?\d+),c:(?\d+)(-(?\d+))?/, + /r:(?\d+)\/(?\d+),c:(?\d+)/, )?.groups as RawRunLabelObject | undefined; assertValueIsDefined(rawRunLabelObject, 'rawRunLabelObject is defined', {runLabel}); - const disconnectedBrowsersCount = - rawRunLabelObject.disconnectedBrowsersCount === undefined - ? 0 - : Number(rawRunLabelObject.disconnectedBrowsersCount); - return { concurrency: Number(rawRunLabelObject.concurrency), - disconnectedBrowsersCount, maxRetriesCount: Number(rawRunLabelObject.maxRetriesCount), retryIndex: Number(rawRunLabelObject.retryIndex), }; diff --git a/src/utils/tests/exitFromTestsSubprocess.ts b/src/utils/tests/exitFromTestsSubprocess.ts index da0cfb5d..2f275ef9 100644 --- a/src/utils/tests/exitFromTestsSubprocess.ts +++ b/src/utils/tests/exitFromTestsSubprocess.ts @@ -1,7 +1,7 @@ import {isLocalRun} from '../../configurator'; import {getRunLabel} from '../environment'; -import {generalLog, readTestCafeWarnings, writeLogsToFile} from '../generalLog'; +import {generalLog, writeLogsToFile} from '../generalLog'; let isExitAlreadyCalled = false; @@ -23,7 +23,7 @@ export const exitFromTestsSubprocess = async ({hasError, reason}: Options): Prom ); try { - await writeLogsToFile().finally(readTestCafeWarnings); + await writeLogsToFile(); } catch (error) { const runLabel = getRunLabel(); diff --git a/src/utils/tests/runTests.ts b/src/utils/tests/runTests.ts index 4207e6b0..d72ee2c8 100644 --- a/src/utils/tests/runTests.ts +++ b/src/utils/tests/runTests.ts @@ -5,33 +5,31 @@ import {CONFIG_PATH, e2edEnvironment} from '../../constants/internal'; import {getFullPackConfig} from '../config'; import {getRunLabel, setRunLabel} from '../environment'; import {E2edError} from '../error'; -import {generalLog, setSuccessfulTotalInPreviousRetries} from '../generalLog'; +import {generalLog} from '../generalLog'; import {setVisitedTestNamesHash} from '../globalState'; import {startResourceUsageReading} from '../resourceUsage'; import {beforeRunFirstTest} from './beforeRunFirstTest'; +import {stripExtraLogs} from './stripExtraLogs'; import type {RunRetryOptions} from '../../types/internal'; +const playwrightCliPath = require.resolve('@playwright/test').replace('index.js', 'cli.js'); + /** - * Runs tests (via TestCafe JavaScript API, for running one retry in docker). + * Runs tests via Playwright internal CLI module. * Rejects, if there are some failed tests. * @internal */ export const runTests = async ({ runLabel, - successfulTestRunNamesHash, visitedTestNamesHash, }: RunRetryOptions): Promise => { setRunLabel(runLabel); setVisitedTestNamesHash(visitedTestNamesHash); try { - const successfulTotalInPreviousRetries = Object.keys(successfulTestRunNamesHash).length; - - setSuccessfulTotalInPreviousRetries(successfulTotalInPreviousRetries); - - const {browserInitTimeout, resourceUsageReadingInternal} = getFullPackConfig(); + const {browserInitTimeout, enableLiveMode, resourceUsageReadingInternal} = getFullPackConfig(); startResourceUsageReading(resourceUsageReadingInternal); @@ -58,25 +56,32 @@ export const runTests = async ({ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions if (e2edEnvironment.E2ED_DEBUG) { // playwrightArgs.unshift('--node-options=--inspect-brk'); + e2edEnvironment.PWDEBUG = 'console'; playwrightArgs.push('--debug'); } + if (enableLiveMode) { + playwrightArgs.push('--ui'); + } + if (!beforeRunFirstTestWasCalled) { beforeRunFirstTestWasCalled = true; beforeRunFirstTest(); } - const playwrightProcess = fork( - '/node_modules/e2ed/node_modules/@playwright/test/cli.js', - playwrightArgs, - ); + const playwrightProcess = fork(playwrightCliPath, playwrightArgs); playwrightProcess.stdout?.on('data', (data) => { - const stringData = String(data).trim(); + const stringData = stripExtraLogs(String(data).trim()); if (stringData !== '') { - generalLog(stringData); + if (stringData.startsWith('[e2ed]')) { + // eslint-disable-next-line no-console + console.log(stringData); + } else { + generalLog(stringData); + } } }); playwrightProcess.stderr?.on('data', (data) => generalLog(`Error: ${String(data)}`)); diff --git a/src/utils/tests/stripExtraLogs.ts b/src/utils/tests/stripExtraLogs.ts new file mode 100644 index 00000000..f41129da --- /dev/null +++ b/src/utils/tests/stripExtraLogs.ts @@ -0,0 +1,22 @@ +/** + * Strip extra Playwright logs. + * @internal + */ +export const stripExtraLogs = (text: string): string => { + const lines = text.split('\n'); + + for (let index = 0; index < lines.length; index += 1) { + const line = lines[index]; + + if (line?.includes('../node_modules/e2ed/test.js:')) { + const startIndex = line.indexOf('›'); + const endIndex = line.lastIndexOf('›'); + + if (startIndex >= 0) { + lines[index] = line.slice(0, startIndex) + line.slice(endIndex + 1); + } + } + } + + return lines.join('\n'); +};