From 3dd960c41fcb365a9b4309e660f290ea8ee830ac Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 12:08:12 +0400 Subject: [PATCH 01/16] feat: add possibility to pass additional data to the reporter plugin --- src/api/test-controller/index.js | 5 ++ src/reporter/index.ts | 27 +++++++ src/reporter/interfaces.ts | 1 + src/reporter/plugin-host.ts | 4 + src/reporter/plugin-methods.ts | 1 + src/reporter/report-data-log.ts | 37 +++++++++ src/runner/test-run-controller.ts | 1 + src/test-run/commands/actions.d.ts | 5 ++ src/test-run/commands/actions.js | 13 +++ src/test-run/commands/type.js | 1 + src/test-run/index.ts | 12 ++- test/functional/fixtures/reporter/test.js | 80 +++++++++++++++++++ .../testcafe-fixtures/report-data-test.js | 17 ++++ ts-defs-src/test-api/test-controller.d.ts | 7 ++ 14 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 src/reporter/report-data-log.ts create mode 100644 test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js diff --git a/src/api/test-controller/index.js b/src/api/test-controller/index.js index 82c815d2737..a6a8e74029f 100644 --- a/src/api/test-controller/index.js +++ b/src/api/test-controller/index.js @@ -57,6 +57,7 @@ import { SkipJsErrorsCommand, AddRequestHooksCommand, RemoveRequestHooksCommand, + ReportCommand, } from '../../test-run/commands/actions'; import { @@ -629,6 +630,10 @@ export default class TestController { return this.enqueueCommand(RemoveRequestHooksCommand, { hooks }); } + [delegatedAPI(ReportCommand.methodName)] (...args) { + return this.enqueueCommand(ReportCommand, { args }); + } + static enableDebugForNonDebugCommands () { inDebug = true; } diff --git a/src/reporter/index.ts b/src/reporter/index.ts index 3be3f774d10..97c9705fb16 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -34,6 +34,7 @@ import MessageBus from '../utils/message-bus'; import BrowserConnection from '../browser/connection'; import { Dictionary } from '../configuration/interfaces'; import debug from 'debug'; +import { ReportDataLogItem } from './report-data-log'; interface PendingPromise { resolve: Function | null; @@ -69,6 +70,7 @@ interface TestInfo { pendingTestRunDonePromise: PendingPromise; pendingTestRunStartPromise: PendingPromise; browsers: BrowserRunInfo[]; + reportData: ReportDataLogItem[]; } interface FixtureInfo { @@ -86,6 +88,7 @@ interface BrowserRunInfo extends Browser { interface TestRunInfo { errs: TestRunErrorFormattableAdapter[]; warnings: string[]; + reportData: ReportDataLogItem[]; durationMs: number; unstable: boolean; screenshotPath: string; @@ -123,6 +126,11 @@ interface ReportWarningEventArguments { actionId?: string; } +interface ReportDataEventArgs { + data: any; + testRun: TestRun +} + const debugLog = debug('testcafe:reporter'); export default class Reporter { @@ -194,6 +202,8 @@ export default class Reporter { messageBus.on('warning-add', async e => await this._onWarningAddHandler(e)); + messageBus.on('report-data', async e => await this._onReportDataHandler(e)); + messageBus.once('start', async (task: Task) => await this._onceTaskStartHandler(task)); messageBus.on('test-run-start', async testRun => await this._onTaskTestRunStartHandler(testRun)); @@ -299,6 +309,7 @@ export default class Reporter { pendingTestRunDonePromise: Reporter._createPendingPromise(), pendingTestRunStartPromise: Reporter._createPendingPromise(), browsers: [], + reportData: [], }; } @@ -312,6 +323,7 @@ export default class Reporter { return { errs: sortBy(reportItem.errs, ['userAgent', 'code']), warnings: reportItem.warnings, + reportData: reportItem.reportData, durationMs: +new Date() - (reportItem.startTime as number), //eslint-disable-line @typescript-eslint/no-extra-parens unstable: reportItem.unstable, screenshotPath: reportItem.screenshotPath as string, @@ -548,6 +560,7 @@ export default class Reporter { reportItem.unstable = reportItem.unstable || testRun.unstable; reportItem.errs = reportItem.errs.concat(testRun.errs); reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; + reportItem.reportData = testRun.reportDataLog.data; if (testRun.quarantine) { reportItem.quarantine = reportItem.quarantine || {}; @@ -635,4 +648,18 @@ export default class Reporter { (this.taskInfo.pendingTaskDonePromise.resolve as Function)(); } + + private async _onReportDataHandler ({ testRun, data }: ReportDataEventArgs): Promise { + if (!this.taskInfo) + return; + + await this.dispatchToPlugin({ + method: ReporterPluginMethod.reportData as string, + initialObject: this.taskInfo.task, + args: [{ + testRun, + data, + }], + }); + } } diff --git a/src/reporter/interfaces.ts b/src/reporter/interfaces.ts index b2576650f53..14857855c2e 100644 --- a/src/reporter/interfaces.ts +++ b/src/reporter/interfaces.ts @@ -10,6 +10,7 @@ export interface ReporterPlugin { reportTestDone(): void; reportTaskDone(): void; reportWarnings?(): void; + reportData? (): void } export interface ReporterSource { diff --git a/src/reporter/plugin-host.ts b/src/reporter/plugin-host.ts index 208899b11ee..f86381a8fca 100644 --- a/src/reporter/plugin-host.ts +++ b/src/reporter/plugin-host.ts @@ -194,4 +194,8 @@ export default class ReporterPluginHost { // NOTE: It's an optional method public async reportWarnings (/* warnings */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function } + + // NOTE: It's an optional method + public async reportData (/* testRun, data */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function + } } diff --git a/src/reporter/plugin-methods.ts b/src/reporter/plugin-methods.ts index 5ba76b8da5f..46e0f103712 100644 --- a/src/reporter/plugin-methods.ts +++ b/src/reporter/plugin-methods.ts @@ -11,6 +11,7 @@ const ReporterPluginMethod: EnumFromPropertiesOf = { reportTestDone: 'reportTestDone', reportTaskDone: 'reportTaskDone', reportWarnings: 'reportWarnings', + reportData: 'reportData', }; export default ReporterPluginMethod; diff --git a/src/reporter/report-data-log.ts b/src/reporter/report-data-log.ts new file mode 100644 index 00000000000..9a052a1c2ff --- /dev/null +++ b/src/reporter/report-data-log.ts @@ -0,0 +1,37 @@ +import MessageBus from '../utils/message-bus'; +import TestRun from '../test-run'; + +export interface ReportDataLogItem { + data: any; + testRun: TestRun; +} + +type ReportDataLogCallback = (data: any) => Promise; + +export default class ReportDataLog { + private readonly _data: any[]; + public callback?: ReportDataLogCallback; + + public constructor (callback?: ReportDataLogCallback) { + this._data = []; + this.callback = callback; + } + + public get data (): any[] { + return this._data; + } + + public async addData (data: any[]): Promise { + if (this.callback) + await this.callback(data); + + this._data.push(...data); + } + + public static createAddDataCallback (messageBus?: MessageBus | object, testRun?: TestRun): ReportDataLogCallback { + return async (data: any) => { + if (messageBus && messageBus instanceof MessageBus) + await messageBus.emit('report-data', { data, testRun }); + }; + } +} diff --git a/src/runner/test-run-controller.ts b/src/runner/test-run-controller.ts index 08e5d89ebfa..f2b674aef7c 100644 --- a/src/runner/test-run-controller.ts +++ b/src/runner/test-run-controller.ts @@ -214,6 +214,7 @@ export default class TestRunController extends AsyncEventEmitter { private _assignTestRunEvents (testRun: TestRun | LegacyTestRun, connection: BrowserConnection): void { testRun.on('action-start', async (args: ActionEventArg) => this._emitActionStart(Object.assign(args, { testRun }))); testRun.on('action-done', async (args: ActionEventArg) => this._emitActionDone(Object.assign(args, { testRun }))); + testRun.on('report-data', async (data: any) => this._messageBus.emit('report-data', { testRun, data })); testRun.once('start', async () => this._emitTestRunStart()); testRun.once('ready', async () => { diff --git a/src/test-run/commands/actions.d.ts b/src/test-run/commands/actions.d.ts index 513f3a2fbcc..d641adbc788 100644 --- a/src/test-run/commands/actions.d.ts +++ b/src/test-run/commands/actions.d.ts @@ -285,3 +285,8 @@ export class RunCustomActionCommand extends ActionCommandBase { public args: any; } +export class ReportDataCommand extends ActionCommandBase { + public constructor (obj: object, testRun: TestRun, validateProperties: boolean); + public args: any[]; +} + diff --git a/src/test-run/commands/actions.js b/src/test-run/commands/actions.js index b0820eec638..60b67d86e55 100644 --- a/src/test-run/commands/actions.js +++ b/src/test-run/commands/actions.js @@ -813,3 +813,16 @@ export class RemoveRequestHooksCommand extends ActionCommandBase { } } +export class ReportCommand extends ActionCommandBase { + static methodName = camelCase(TYPE.report); + + constructor (obj, testRun, validateProperties) { + super(obj, testRun, TYPE.report, validateProperties); + } + + getAssignableProperties () { + return [ + { name: 'args', required: true }, + ]; + } +} diff --git a/src/test-run/commands/type.js b/src/test-run/commands/type.js index 8a63204aef2..8b9cdc13813 100644 --- a/src/test-run/commands/type.js +++ b/src/test-run/commands/type.js @@ -72,4 +72,5 @@ export default { addRequestHooks: 'add-request-hooks', removeRequestHooks: 'remove-request-hooks', runCustomAction: 'run-custom-action', + report: 'report', }; diff --git a/src/test-run/index.ts b/src/test-run/index.ts index 5d267501541..de96ca8cfb2 100644 --- a/src/test-run/index.ts +++ b/src/test-run/index.ts @@ -143,6 +143,7 @@ import { import ProxylessRequestPipeline from '../proxyless/request-pipeline'; import Proxyless from '../proxyless'; +import ReportDataLog from '../reporter/report-data-log'; const lazyRequire = require('import-lazy')(require); const ClientFunctionBuilder = lazyRequire('../client-functions/client-function-builder'); @@ -227,6 +228,7 @@ interface OpenedWindowInformation { export default class TestRun extends AsyncEventEmitter { private [testRunMarker]: boolean; public readonly warningLog: WarningLog; + public readonly reportDataLog: ReportDataLog; private readonly opts: Dictionary; public readonly test: Test; public readonly browserConnection: BrowserConnection; @@ -290,6 +292,7 @@ export default class TestRun extends AsyncEventEmitter { this[testRunMarker] = true; this._messageBus = messageBus; this.warningLog = new WarningLog(globalWarningLog, WarningLog.createAddWarningCallback(messageBus, this)); + this.reportDataLog = new ReportDataLog(ReportDataLog.createAddDataCallback(messageBus, this)); this.opts = opts; this.test = test; this.browserConnection = browserConnection; @@ -307,8 +310,8 @@ export default class TestRun extends AsyncEventEmitter { this.pageLoadTimeout = this._getPageLoadTimeout(test, opts); this.testExecutionTimeout = this._getTestExecutionTimeout(opts); - this.disablePageReloads = test.disablePageReloads || opts.disablePageReloads as boolean && test.disablePageReloads !== false; - this.disablePageCaching = test.disablePageCaching || opts.disablePageCaching as boolean; + this.disablePageReloads = test.disablePageReloads || opts.disablePageReloads as boolean && test.disablePageReloads !== false; + this.disablePageCaching = test.disablePageCaching || opts.disablePageCaching as boolean; this.disableMultipleWindows = opts.disableMultipleWindows as boolean; @@ -350,7 +353,7 @@ export default class TestRun extends AsyncEventEmitter { this.debugLog = new TestRunDebugLog(this.browserConnection.userAgent); - this.quarantine = null; + this.quarantine = null; this.debugLogger = this.opts.debugLogger; @@ -1308,6 +1311,9 @@ export default class TestRun extends AsyncEventEmitter { return await wrappedFn(this, args); } + if (command.type === COMMAND_TYPE.report) + return await this.reportDataLog.addData(command.args as any[]); + if (command.type === COMMAND_TYPE.assertion) return this._executeAssertion(command as AssertionCommand, callsite as CallsiteRecord); diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 0acd462229e..7f8a1af4dac 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -888,6 +888,86 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }); }); + describe('Report Data', () => { + let dataResult = null; + let reporter = null; + + const createReportDataReporter = () => { + dataResult = { + reportDataInfos: {}, + testDoneList: {}, + }; + + return createReporter({ + reportData: ({ data, testRun }) => { + const testName = testRun.test.name; + + if (!dataResult.reportDataInfos[testName]) + dataResult.reportDataInfos[testName] = []; + + dataResult.reportDataInfos[testName].push(...data); + }, + reportTestDone: (name, { reportData }) => { + dataResult.testDoneList[name] = reportData; + }, + }); + }; + + const expectedReports = { + 'Run t.report action twice': ['Report 1', 'Report 2'], + 'Run t.report action with multiple args': ['Report 1', 'Report2', { 'reportResult': 'test' }, 'Report 3', 'Report 4'], + 'Run t.report action with object val': ['Report 1', { 'reportResult': 'test' }], + }; + + + beforeEach(() => { + reporter = createReportDataReporter(); + }); + + it('Should raise reportData twice', async () => { + const testName = 'Run t.report action twice'; + + await runTests('testcafe-fixtures/report-data-test.js', testName, { + reporter, + }); + + expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); + expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); + }); + + it('Should raise reportData with object value', async () => { + const testName = 'Run t.report action with object val'; + + await runTests('testcafe-fixtures/report-data-test.js', testName, { + reporter, + }); + + expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); + expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); + }); + + it('Should raise reportData with multiple args', async () => { + const testName = 'Run t.report action with multiple args'; + + await runTests('testcafe-fixtures/report-data-test.js', testName, { + reporter, + }); + + expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); + expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); + }); + + it('Should collect info from different tests', async () => { + await runTests('testcafe-fixtures/report-data-test.js', null, { + reporter, + }); + + expect(dataResult.testDoneList).eql(expectedReports); + expect(dataResult.reportDataInfos).eql(expectedReports); + }); + + }); + describe('Warnings', () => { let warningResult = {}; let reporter = null; diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js new file mode 100644 index 00000000000..05b029f934e --- /dev/null +++ b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js @@ -0,0 +1,17 @@ +fixture`Report Data API` + .page('../pages/index.html'); + +test('Run t.report action twice', async t => { + await t.report('Report 1'); + await t.report('Report 2'); +}); + +test('Run t.report action with object val', async t => { + await t.report('Report 1'); + await t.report({ 'reportResult': 'test' }); +}); + +test('Run t.report action with multiple args', async t => { + await t.report('Report 1', 'Report2', { 'reportResult': 'test' }); + await t.report('Report 3', 'Report 4'); +}); diff --git a/ts-defs-src/test-api/test-controller.d.ts b/ts-defs-src/test-api/test-controller.d.ts index 8532492c7ac..34ab7300699 100644 --- a/ts-defs-src/test-api/test-controller.d.ts +++ b/ts-defs-src/test-api/test-controller.d.ts @@ -548,6 +548,13 @@ interface TestController { * @param options - Error skipping conditions: a Boolean flag, an Object with options, or a callback function that defines custom error skipping logic. */ skipJsErrors (options?: boolean | SkipJsErrorsOptionsObject | SkipJsErrorsCallback | SkipJsErrorsCallbackWithOptionsObject): TestControllerPromise; + + /** + * Pass additional data to the reporter. + * + * @param args - Any user data. + */ + report (...args: any[]): TestControllerPromise; } interface TestControllerPromise extends TestController, Promise { From 55bdff76f85b664d5c741e1a3efb16a405fc2841 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 12:13:33 +0400 Subject: [PATCH 02/16] add array arg --- test/functional/fixtures/reporter/test.js | 2 +- .../fixtures/reporter/testcafe-fixtures/report-data-test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 7f8a1af4dac..7d17e7fc5b2 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -914,7 +914,7 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }; const expectedReports = { - 'Run t.report action twice': ['Report 1', 'Report 2'], + 'Run t.report action twice': [['Report 1', 'Report 2'], 'Report 3'], 'Run t.report action with multiple args': ['Report 1', 'Report2', { 'reportResult': 'test' }, 'Report 3', 'Report 4'], 'Run t.report action with object val': ['Report 1', { 'reportResult': 'test' }], }; diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js index 05b029f934e..9f348e41f89 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js @@ -2,8 +2,8 @@ fixture`Report Data API` .page('../pages/index.html'); test('Run t.report action twice', async t => { - await t.report('Report 1'); - await t.report('Report 2'); + await t.report(['Report 1', 'Report 2']); + await t.report('Report 3'); }); test('Run t.report action with object val', async t => { From 692cf225660da8dc6adeb37a1ac8569bd2b1283e Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 13:53:35 +0400 Subject: [PATCH 03/16] fix tests --- src/reporter/index.ts | 2 +- .../command-constructors.ts | 2 ++ src/test-run/commands/actions.d.ts | 2 +- .../index.js | 26 +++++++++++++----- test/server/reporter-test.js | 27 ++++++++++++++++++- test/server/test-controller-events-test.js | 1 + 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index 97c9705fb16..b74fda6c053 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -560,7 +560,7 @@ export default class Reporter { reportItem.unstable = reportItem.unstable || testRun.unstable; reportItem.errs = reportItem.errs.concat(testRun.errs); reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; - reportItem.reportData = testRun.reportDataLog.data; + reportItem.reportData = testRun.reportDataLog ? testRun.reportDataLog.data : []; if (testRun.quarantine) { reportItem.quarantine = reportItem.quarantine || {}; diff --git a/src/services/serialization/replicator/transforms/command-base-trasform/command-constructors.ts b/src/services/serialization/replicator/transforms/command-base-trasform/command-constructors.ts index 9f98ec8c081..f437a8e5ca4 100644 --- a/src/services/serialization/replicator/transforms/command-base-trasform/command-constructors.ts +++ b/src/services/serialization/replicator/transforms/command-base-trasform/command-constructors.ts @@ -49,6 +49,7 @@ import { SkipJsErrorsCommand, AddRequestHooksCommand, RemoveRequestHooksCommand, + ReportCommand, } from '../../../../../test-run/commands/actions'; import { AssertionCommand } from '../../../../../test-run/commands/assertion'; @@ -115,6 +116,7 @@ const COMMAND_CONSTRUCTORS = new Map([ [CommandType.skipJsErrors, SkipJsErrorsCommand], [CommandType.addRequestHooks, AddRequestHooksCommand], [CommandType.removeRequestHooks, RemoveRequestHooksCommand], + [CommandType.report, ReportCommand], ]); export default COMMAND_CONSTRUCTORS; diff --git a/src/test-run/commands/actions.d.ts b/src/test-run/commands/actions.d.ts index d641adbc788..b9dd7c8ee85 100644 --- a/src/test-run/commands/actions.d.ts +++ b/src/test-run/commands/actions.d.ts @@ -285,7 +285,7 @@ export class RunCustomActionCommand extends ActionCommandBase { public args: any; } -export class ReportDataCommand extends ActionCommandBase { +export class ReportCommand extends ActionCommandBase { public constructor (obj: object, testRun: TestRun, validateProperties: boolean); public args: any[]; } diff --git a/test/server/data/test-controller-reporter-expected/index.js b/test/server/data/test-controller-reporter-expected/index.js index e7572519be4..4c4710fd8a1 100644 --- a/test/server/data/test-controller-reporter-expected/index.js +++ b/test/server/data/test-controller-reporter-expected/index.js @@ -877,16 +877,28 @@ module.exports = { browser: { alias: 'test-browser', headless: false }, }, { - testRunId: "test-run-id", - name: "skipJsErrors", + testRunId: 'test-run-id', + name: 'skipJsErrors', command: { - actionId: "SkipJsErrorsCommand", + actionId: 'SkipJsErrorsCommand', options: true, - type: "skip-js-errors", + type: 'skip-js-errors', + }, + test: { id: 'test-id', name: 'test-name', phase: 'initial' }, + fixture: { id: 'fixture-id', name: 'fixture-name' }, + browser: { alias: 'test-browser', headless: false }, + }, + { + testRunId: 'test-run-id', + name: 'report', + command: { + actionId: 'ReportCommand', + args: [], + type: 'report', }, - test: { id: "test-id", name: "test-name", phase: "initial" }, - fixture: { id: "fixture-id", name: "fixture-name" }, - browser: { alias: "test-browser", headless: false }, + test: { id: 'test-id', name: 'test-name', phase: 'initial' }, + fixture: { id: 'fixture-id', name: 'fixture-name' }, + browser: { alias: 'test-browser', headless: false }, }, ], } diff --git a/test/server/reporter-test.js b/test/server/reporter-test.js index 4210a667437..08947136447 100644 --- a/test/server/reporter-test.js +++ b/test/server/reporter-test.js @@ -189,6 +189,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, quarantine: { attempts: [ { testRunId: 'firstRunId', errors: ['1', '2'] }, @@ -205,6 +206,7 @@ describe('Reporter', () => { unstable: false, browserConnection: browserConnectionMocks[0], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], errs: [ @@ -221,6 +223,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, @@ -232,6 +235,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, @@ -243,6 +247,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, @@ -254,6 +259,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, @@ -265,6 +271,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, @@ -276,6 +283,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[0], errs: [], warningLog: { messages: ['warning2'] }, + reportDataLog: { data: [] }, browser: browserMocks[0], }, ]; @@ -289,6 +297,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, quarantine: { attempts: [ { testRunId: 'firstRunId', errors: ['1', '2'] }, @@ -306,6 +315,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [{ text: 'err1' }], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -317,6 +327,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -328,6 +339,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -339,6 +351,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -350,6 +363,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [{ text: 'err1' }], warningLog: { messages: ['warning1'] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -361,6 +375,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: [] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, @@ -372,6 +387,7 @@ describe('Reporter', () => { browserConnection: browserConnectionMocks[1], errs: [], warningLog: { messages: ['warning2', 'warning3'] }, + reportDataLog: { data: [] }, browser: browserMocks[1], }, ]; @@ -498,7 +514,7 @@ describe('Reporter', () => { createReporter(messageBus); - expect(messageBus.listenerCount()).eql(8); + expect(messageBus.listenerCount()).eql(9); expect(messageBus.listenerCount('warning-add')).eql(1); expect(messageBus.listenerCount('start')).eql(1); expect(messageBus.listenerCount('test-run-start')).eql(1); @@ -507,6 +523,7 @@ describe('Reporter', () => { expect(messageBus.listenerCount('test-action-done')).eql(1); expect(messageBus.listenerCount('done')).eql(1); expect(messageBus.listenerCount('unhandled-rejection')).eql(1); + expect(messageBus.listenerCount('report-data')).eql(1); }); it('Should analyze task progress and call appropriate plugin methods', function () { @@ -767,6 +784,7 @@ describe('Reporter', () => { run: 'run-001', }, }, + reportData: [], }, { run: 'run-001', @@ -860,6 +878,7 @@ describe('Reporter', () => { run: 'run-001', }, }, + reportData: [], }, { run: 'run-001', @@ -925,6 +944,7 @@ describe('Reporter', () => { run: 'run-001', }, }, + reportData: [], }, { run: 'run-001', @@ -1000,6 +1020,7 @@ describe('Reporter', () => { run: 'run-002', }, }, + reportData: [], }, { run: 'run-001', @@ -1065,6 +1086,7 @@ describe('Reporter', () => { run: 'run-002', }, }, + reportData: [], }, { run: 'run-001', @@ -1142,6 +1164,7 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, + reportData: [], }, { run: 'run-001', @@ -1205,6 +1228,7 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, + reportData: [], }, { run: 'run-001', @@ -1268,6 +1292,7 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, + reportData: [], }, { run: 'run-001', diff --git a/test/server/test-controller-events-test.js b/test/server/test-controller-events-test.js index 247ba133173..14180873e37 100644 --- a/test/server/test-controller-events-test.js +++ b/test/server/test-controller-events-test.js @@ -141,6 +141,7 @@ const actions = { setCookies: [{ cookieName: 'cookieValue' }, 'https://domain.com'], deleteCookies: [['cookieName1', 'cookieName2'], 'https://domain.com'], skipJsErrors: [true], + report: [], }; let testController = null; From dfe3c9c89e4251e1dc792d0dc5609203bc3cb4e1 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 14:25:55 +0400 Subject: [PATCH 04/16] refactor --- src/reporter/report-data-log.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/reporter/report-data-log.ts b/src/reporter/report-data-log.ts index 9a052a1c2ff..2a0b798c70c 100644 --- a/src/reporter/report-data-log.ts +++ b/src/reporter/report-data-log.ts @@ -13,8 +13,8 @@ export default class ReportDataLog { public callback?: ReportDataLogCallback; public constructor (callback?: ReportDataLogCallback) { - this._data = []; - this.callback = callback; + this._data = []; + this.callback = callback; } public get data (): any[] { @@ -28,10 +28,9 @@ export default class ReportDataLog { this._data.push(...data); } - public static createAddDataCallback (messageBus?: MessageBus | object, testRun?: TestRun): ReportDataLogCallback { - return async (data: any) => { - if (messageBus && messageBus instanceof MessageBus) - await messageBus.emit('report-data', { data, testRun }); + public static createAddDataCallback (messageBus: MessageBus, testRun: TestRun): ReportDataLogCallback { + return async (data: any[]) => { + await messageBus.emit('report-data', { data, testRun }); }; } } From f18476ef2297da576051999b487b9f9df998b564 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 14:35:46 +0400 Subject: [PATCH 05/16] refactor 2 --- src/reporter/report-data-log.ts | 5 +++-- .../fixtures/reporter/testcafe-fixtures/report-data-test.js | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/reporter/report-data-log.ts b/src/reporter/report-data-log.ts index 2a0b798c70c..5558a2573cd 100644 --- a/src/reporter/report-data-log.ts +++ b/src/reporter/report-data-log.ts @@ -28,9 +28,10 @@ export default class ReportDataLog { this._data.push(...data); } - public static createAddDataCallback (messageBus: MessageBus, testRun: TestRun): ReportDataLogCallback { + public static createAddDataCallback (messageBus: MessageBus | undefined, testRun: TestRun): ReportDataLogCallback { return async (data: any[]) => { - await messageBus.emit('report-data', { data, testRun }); + if (messageBus) + await messageBus.emit('report-data', { data, testRun }); }; } } diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js index 9f348e41f89..01abb51a15c 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js @@ -7,8 +7,7 @@ test('Run t.report action twice', async t => { }); test('Run t.report action with object val', async t => { - await t.report('Report 1'); - await t.report({ 'reportResult': 'test' }); + await t.report('Report 1').report({ 'reportResult': 'test' }); }); test('Run t.report action with multiple args', async t => { From 3614c3356534fcca65a15ab9e3737485dab782a0 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 15:09:23 +0400 Subject: [PATCH 06/16] refactor 3 --- src/reporter/plugin-host.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/plugin-host.ts b/src/reporter/plugin-host.ts index f86381a8fca..538801966ef 100644 --- a/src/reporter/plugin-host.ts +++ b/src/reporter/plugin-host.ts @@ -196,6 +196,6 @@ export default class ReporterPluginHost { } // NOTE: It's an optional method - public async reportData (/* testRun, data */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function + public async reportData (/* { testRun, data } */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function } } From 82a8bd9e3960cb2bc08e4065bc8126884dfebd9f Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 16:17:59 +0400 Subject: [PATCH 07/16] refactor 3 --- src/reporter/index.ts | 14 +++++--------- src/reporter/report-data-log.ts | 7 +------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index b74fda6c053..5705b21a335 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -34,7 +34,6 @@ import MessageBus from '../utils/message-bus'; import BrowserConnection from '../browser/connection'; import { Dictionary } from '../configuration/interfaces'; import debug from 'debug'; -import { ReportDataLogItem } from './report-data-log'; interface PendingPromise { resolve: Function | null; @@ -70,7 +69,6 @@ interface TestInfo { pendingTestRunDonePromise: PendingPromise; pendingTestRunStartPromise: PendingPromise; browsers: BrowserRunInfo[]; - reportData: ReportDataLogItem[]; } interface FixtureInfo { @@ -88,7 +86,7 @@ interface BrowserRunInfo extends Browser { interface TestRunInfo { errs: TestRunErrorFormattableAdapter[]; warnings: string[]; - reportData: ReportDataLogItem[]; + reportData: any[]; durationMs: number; unstable: boolean; screenshotPath: string; @@ -127,7 +125,7 @@ interface ReportWarningEventArguments { } interface ReportDataEventArgs { - data: any; + data: any[]; testRun: TestRun } @@ -309,7 +307,6 @@ export default class Reporter { pendingTestRunDonePromise: Reporter._createPendingPromise(), pendingTestRunStartPromise: Reporter._createPendingPromise(), browsers: [], - reportData: [], }; } @@ -319,11 +316,11 @@ export default class Reporter { return task.tests.map(test => Reporter._createTestItem(test, runsPerTest)); } - private static _createTestRunInfo (reportItem: TestInfo): TestRunInfo { + private static _createTestRunInfo (reportItem: TestInfo, testRun: TestRun): TestRunInfo { return { errs: sortBy(reportItem.errs, ['userAgent', 'code']), warnings: reportItem.warnings, - reportData: reportItem.reportData, + reportData: testRun.reportDataLog ? testRun.reportDataLog.data : [], durationMs: +new Date() - (reportItem.startTime as number), //eslint-disable-line @typescript-eslint/no-extra-parens unstable: reportItem.unstable, screenshotPath: reportItem.screenshotPath as string, @@ -415,7 +412,7 @@ export default class Reporter { } if (!testItem.testRunInfo) { - testItem.testRunInfo = Reporter._createTestRunInfo(testItem); + testItem.testRunInfo = Reporter._createTestRunInfo(testItem, testRun); if (testItem.test.skip) taskInfo.skipped++; @@ -560,7 +557,6 @@ export default class Reporter { reportItem.unstable = reportItem.unstable || testRun.unstable; reportItem.errs = reportItem.errs.concat(testRun.errs); reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; - reportItem.reportData = testRun.reportDataLog ? testRun.reportDataLog.data : []; if (testRun.quarantine) { reportItem.quarantine = reportItem.quarantine || {}; diff --git a/src/reporter/report-data-log.ts b/src/reporter/report-data-log.ts index 5558a2573cd..8c317e3d3a8 100644 --- a/src/reporter/report-data-log.ts +++ b/src/reporter/report-data-log.ts @@ -1,12 +1,7 @@ import MessageBus from '../utils/message-bus'; import TestRun from '../test-run'; -export interface ReportDataLogItem { - data: any; - testRun: TestRun; -} - -type ReportDataLogCallback = (data: any) => Promise; +type ReportDataLogCallback = (data: any[]) => Promise; export default class ReportDataLog { private readonly _data: any[]; From 8461517115dd646c967bfdf232ce7c0e060a3a70 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 16:41:52 +0400 Subject: [PATCH 08/16] fix test --- .../functional/fixtures/reporter/testcafe-fixtures/index-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js index 4096e47b8b0..3e30a8a3e27 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js @@ -25,6 +25,7 @@ async function errorCheck (t) { test('Simple test', async t => { await t.wait(1); + await t.report(); }); test('Simple command test', async t => { From 54e7ab64b81064e6c21ef683fb77f24ba91985c9 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 17:42:58 +0400 Subject: [PATCH 09/16] refactor 4 --- src/reporter/index.ts | 6 +++--- test/functional/fixtures/reporter/test.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index 5705b21a335..9152ae56ff6 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -652,10 +652,10 @@ export default class Reporter { await this.dispatchToPlugin({ method: ReporterPluginMethod.reportData as string, initialObject: this.taskInfo.task, - args: [{ + args: [ testRun, - data, - }], + ...data, + ], }); } } diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 7d17e7fc5b2..71efa8eef68 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -888,7 +888,7 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }); }); - describe('Report Data', () => { + describe.only('Report Data', () => { let dataResult = null; let reporter = null; @@ -899,7 +899,7 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }; return createReporter({ - reportData: ({ data, testRun }) => { + reportData: (testRun, ...data) => { const testName = testRun.test.name; if (!dataResult.reportDataInfos[testName]) From 568891a5b5cfa1eb350673aeecd0e0650a2ac83e Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 17:44:01 +0400 Subject: [PATCH 10/16] fix lint --- test/functional/fixtures/reporter/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 71efa8eef68..0bb6e9069ce 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -888,7 +888,7 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }); }); - describe.only('Report Data', () => { + describe('Report Data', () => { let dataResult = null; let reporter = null; From a2b74cb3d4d46a3a8425e81d4a26a2688c6c62e2 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 15 Mar 2023 17:47:32 +0400 Subject: [PATCH 11/16] refactor 6 --- src/reporter/plugin-host.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/plugin-host.ts b/src/reporter/plugin-host.ts index 538801966ef..353afb2c253 100644 --- a/src/reporter/plugin-host.ts +++ b/src/reporter/plugin-host.ts @@ -196,6 +196,6 @@ export default class ReporterPluginHost { } // NOTE: It's an optional method - public async reportData (/* { testRun, data } */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function + public async reportData (/* testRun, ...data */): Promise { // eslint-disable-line @typescript-eslint/no-empty-function } } From 9032a004fe5f5e4849c12d26089481500740b079 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Fri, 17 Mar 2023 15:54:41 +0400 Subject: [PATCH 12/16] refactor 7 --- src/reporter/index.ts | 50 +++++++++--- src/runner/test-run-controller.ts | 1 - test/functional/fixtures/reporter/test.js | 79 +++++++------------ .../testcafe-fixtures/report-data-test.js | 14 +--- 4 files changed, 71 insertions(+), 73 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index 9152ae56ff6..a12ddc74cb7 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -52,6 +52,7 @@ interface TaskInfo { } interface TestInfo { + reportData: Dictionary; fixture: Fixture; test: Test; testRunIds: string[]; @@ -86,7 +87,7 @@ interface BrowserRunInfo extends Browser { interface TestRunInfo { errs: TestRunErrorFormattableAdapter[]; warnings: string[]; - reportData: any[]; + reportData: Dictionary; durationMs: number; unstable: boolean; screenshotPath: string; @@ -307,6 +308,7 @@ export default class Reporter { pendingTestRunDonePromise: Reporter._createPendingPromise(), pendingTestRunStartPromise: Reporter._createPendingPromise(), browsers: [], + reportData: {}, }; } @@ -316,11 +318,11 @@ export default class Reporter { return task.tests.map(test => Reporter._createTestItem(test, runsPerTest)); } - private static _createTestRunInfo (reportItem: TestInfo, testRun: TestRun): TestRunInfo { + private static _createTestRunInfo (reportItem: TestInfo): TestRunInfo { return { errs: sortBy(reportItem.errs, ['userAgent', 'code']), warnings: reportItem.warnings, - reportData: testRun.reportDataLog ? testRun.reportDataLog.data : [], + reportData: reportItem.reportData, durationMs: +new Date() - (reportItem.startTime as number), //eslint-disable-line @typescript-eslint/no-extra-parens unstable: reportItem.unstable, screenshotPath: reportItem.screenshotPath as string, @@ -412,7 +414,7 @@ export default class Reporter { } if (!testItem.testRunInfo) { - testItem.testRunInfo = Reporter._createTestRunInfo(testItem, testRun); + testItem.testRunInfo = Reporter._createTestRunInfo(testItem); if (testItem.test.skip) taskInfo.skipped++; @@ -553,10 +555,12 @@ export default class Reporter { reportItem.browsers.push(browser); - reportItem.pendingRuns = isTestRunStoppedTaskExecution ? 0 : reportItem.pendingRuns - 1; - reportItem.unstable = reportItem.unstable || testRun.unstable; - reportItem.errs = reportItem.errs.concat(testRun.errs); - reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; + reportItem.pendingRuns = isTestRunStoppedTaskExecution ? 0 : reportItem.pendingRuns - 1; + reportItem.unstable = reportItem.unstable || testRun.unstable; + reportItem.errs = reportItem.errs.concat(testRun.errs); + reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; + reportItem.reportData = reportItem.reportData || {}; + reportItem.reportData[testRun.id] = testRun.reportDataLog.data; if (testRun.quarantine) { reportItem.quarantine = reportItem.quarantine || {}; @@ -645,15 +649,43 @@ export default class Reporter { (this.taskInfo.pendingTaskDonePromise.resolve as Function)(); } + private _prepareReportDataEventArgs (testRun: TestRun): any { + const { test, reportDataLog, browser, id } = testRun; + const fixture = test.fixture; + + const testInfo = { + name: test.name, + id: test.id, + meta: test.meta, + }; + + const fixtureInfo = { + name: fixture?.name, + id: fixture?.id, + meta: fixture?.meta, + path: fixture?.path, + }; + + return { + reportData: reportDataLog.data, + test: testInfo, + fixture: fixtureInfo, + testRunId: id, + browser, + }; + } + private async _onReportDataHandler ({ testRun, data }: ReportDataEventArgs): Promise { if (!this.taskInfo) return; + const testRunInfo = this._prepareReportDataEventArgs(testRun); + await this.dispatchToPlugin({ method: ReporterPluginMethod.reportData as string, initialObject: this.taskInfo.task, args: [ - testRun, + testRunInfo, ...data, ], }); diff --git a/src/runner/test-run-controller.ts b/src/runner/test-run-controller.ts index f2b674aef7c..08e5d89ebfa 100644 --- a/src/runner/test-run-controller.ts +++ b/src/runner/test-run-controller.ts @@ -214,7 +214,6 @@ export default class TestRunController extends AsyncEventEmitter { private _assignTestRunEvents (testRun: TestRun | LegacyTestRun, connection: BrowserConnection): void { testRun.on('action-start', async (args: ActionEventArg) => this._emitActionStart(Object.assign(args, { testRun }))); testRun.on('action-done', async (args: ActionEventArg) => this._emitActionDone(Object.assign(args, { testRun }))); - testRun.on('report-data', async (data: any) => this._messageBus.emit('report-data', { testRun, data })); testRun.once('start', async () => this._emitTestRunStart()); testRun.once('ready', async () => { diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 0bb6e9069ce..356835eb973 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -889,83 +889,58 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; }); describe('Report Data', () => { - let dataResult = null; - let reporter = null; + let reportDataInfos = {}; + let testDoneInfos = {}; + let reporter = null; const createReportDataReporter = () => { - dataResult = { - reportDataInfos: {}, - testDoneList: {}, - }; - return createReporter({ - reportData: (testRun, ...data) => { - const testName = testRun.test.name; + reportData: ({ browser }, ...data) => { + const alias = browser.alias; - if (!dataResult.reportDataInfos[testName]) - dataResult.reportDataInfos[testName] = []; + if (!reportDataInfos[alias]) + reportDataInfos[alias] = []; - dataResult.reportDataInfos[testName].push(...data); + reportDataInfos[alias].push(data); }, - reportTestDone: (name, { reportData }) => { - dataResult.testDoneList[name] = reportData; + reportTestDone: (name, { reportData, browsers }) => { + browsers.forEach(({ testRunId, alias }) => { + testDoneInfos[alias] = reportData[testRunId]; + }); }, }); }; - const expectedReports = { - 'Run t.report action twice': [['Report 1', 'Report 2'], 'Report 3'], - 'Run t.report action with multiple args': ['Report 1', 'Report2', { 'reportResult': 'test' }, 'Report 3', 'Report 4'], - 'Run t.report action with object val': ['Report 1', { 'reportResult': 'test' }], - }; - - beforeEach(() => { - reporter = createReportDataReporter(); - }); + reportDataInfos = {}; + testDoneInfos = {}; - it('Should raise reportData twice', async () => { - const testName = 'Run t.report action twice'; - - await runTests('testcafe-fixtures/report-data-test.js', testName, { - reporter, - }); - - expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); - expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); + reporter = createReportDataReporter(); }); - it('Should raise reportData with object value', async () => { - const testName = 'Run t.report action with object val'; + it('Should raise reportData twice with different argument count and types', async () => { + const expectedReportData = [1, true, 'string', { 'reportResult': 'test' }]; - await runTests('testcafe-fixtures/report-data-test.js', testName, { + await runTests('testcafe-fixtures/report-data-test.js', 'Run t.report action with object val', { reporter, }); - expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); - expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); - }); + const reportDataBrowserInfos = Object.entries(reportDataInfos); + const testDoneBrowserInfos = Object.entries(testDoneInfos); - it('Should raise reportData with multiple args', async () => { - const testName = 'Run t.report action with multiple args'; + expect(reportDataBrowserInfos.length).eql(config.browsers.length); + expect(testDoneBrowserInfos.length).eql(config.browsers.length); - await runTests('testcafe-fixtures/report-data-test.js', testName, { - reporter, + reportDataBrowserInfos.forEach(([alias, reportData]) => { + expect(reportData.flat()).eql(testDoneInfos[alias]); }); - expect(dataResult.testDoneList).eql({ [testName]: expectedReports[testName] }); - expect(dataResult.reportDataInfos).eql({ [testName]: expectedReports[testName] }); - }); + testDoneBrowserInfos.forEach(([, reportData]) => { + const [, ...rest] = reportData; - it('Should collect info from different tests', async () => { - await runTests('testcafe-fixtures/report-data-test.js', null, { - reporter, + expect(rest).eql(expectedReportData); }); - - expect(dataResult.testDoneList).eql(expectedReports); - expect(dataResult.reportDataInfos).eql(expectedReports); }); - }); describe('Warnings', () => { diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js index 01abb51a15c..b728c09504d 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js @@ -1,16 +1,8 @@ fixture`Report Data API` .page('../pages/index.html'); -test('Run t.report action twice', async t => { - await t.report(['Report 1', 'Report 2']); - await t.report('Report 3'); -}); - test('Run t.report action with object val', async t => { - await t.report('Report 1').report({ 'reportResult': 'test' }); -}); - -test('Run t.report action with multiple args', async t => { - await t.report('Report 1', 'Report2', { 'reportResult': 'test' }); - await t.report('Report 3', 'Report 4'); + await t + .report(t.browser.alias) + .report(1, true, 'string', { 'reportResult': 'test' }); }); From ee7a8ad2b946cec92a1e64e2337672b089f219b0 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Fri, 17 Mar 2023 16:11:18 +0400 Subject: [PATCH 13/16] refactor 7 --- src/reporter/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index a12ddc74cb7..f4731c0e59c 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -650,8 +650,8 @@ export default class Reporter { } private _prepareReportDataEventArgs (testRun: TestRun): any { - const { test, reportDataLog, browser, id } = testRun; - const fixture = test.fixture; + const { test, browser, id } = testRun; + const fixture = test.fixture; const testInfo = { name: test.name, @@ -667,10 +667,9 @@ export default class Reporter { }; return { - reportData: reportDataLog.data, - test: testInfo, - fixture: fixtureInfo, - testRunId: id, + test: testInfo, + fixture: fixtureInfo, + testRunId: id, browser, }; } From d3cdb5af08c465e5837d0aff60fbe06df24c04f5 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Mon, 20 Mar 2023 12:45:05 +0400 Subject: [PATCH 14/16] fix tests --- src/reporter/index.ts | 2 +- test/server/reporter-test.js | 42 ++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/reporter/index.ts b/src/reporter/index.ts index f4731c0e59c..83b79e03758 100644 --- a/src/reporter/index.ts +++ b/src/reporter/index.ts @@ -560,7 +560,7 @@ export default class Reporter { reportItem.errs = reportItem.errs.concat(testRun.errs); reportItem.warnings = testRun.warningLog ? union(reportItem.warnings, testRun.warningLog.messages) : []; reportItem.reportData = reportItem.reportData || {}; - reportItem.reportData[testRun.id] = testRun.reportDataLog.data; + reportItem.reportData[testRun.id] = testRun.reportDataLog ? testRun.reportDataLog.data : []; if (testRun.quarantine) { reportItem.quarantine = reportItem.quarantine || {}; diff --git a/test/server/reporter-test.js b/test/server/reporter-test.js index 08947136447..05c5fc785b5 100644 --- a/test/server/reporter-test.js +++ b/test/server/reporter-test.js @@ -784,7 +784,10 @@ describe('Reporter', () => { run: 'run-001', }, }, - reportData: [], + reportData: { + 'f1t1': [], + 'f1t1ff': [], + }, }, { run: 'run-001', @@ -878,7 +881,10 @@ describe('Reporter', () => { run: 'run-001', }, }, - reportData: [], + reportData: { + f1t2: [], + f1t2ff: [], + }, }, { run: 'run-001', @@ -944,7 +950,10 @@ describe('Reporter', () => { run: 'run-001', }, }, - reportData: [], + reportData: { + f1t3: [], + f1t3ff: [], + }, }, { run: 'run-001', @@ -1020,7 +1029,10 @@ describe('Reporter', () => { run: 'run-002', }, }, - reportData: [], + reportData: { + f2t1: [], + f2t1ff: [], + }, }, { run: 'run-001', @@ -1086,7 +1098,10 @@ describe('Reporter', () => { run: 'run-002', }, }, - reportData: [], + reportData: { + f2t2: [], + f2t2ff: [], + }, }, { run: 'run-001', @@ -1164,7 +1179,10 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, - reportData: [], + reportData: { + f3t1: [], + f3t1ff: [], + }, }, { run: 'run-001', @@ -1228,7 +1246,10 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, - reportData: [], + reportData: { + f3t2: [], + f3t2ff: [], + }, }, { run: 'run-001', @@ -1292,7 +1313,10 @@ describe('Reporter', () => { path: './file2.js', meta: null, }, - reportData: [], + reportData: { + f3t3: [], + f3t3ff: [], + }, }, { run: 'run-001', @@ -1396,7 +1420,7 @@ describe('Reporter', () => { [ { testRunId: 'f1t2-id1', videoPath: 'f1t2-path1' }, { testRunId: 'f1t2-id2', videoPath: 'f1t2-path2' }, - ]] + ]], ); }); }); From a3145392beefc50a98fc2cdf3129ad806e7adc80 Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 22 Mar 2023 15:35:48 +0400 Subject: [PATCH 15/16] fix tests 2 --- test/functional/fixtures/reporter/test.js | 4 ++-- .../fixtures/reporter/testcafe-fixtures/index-test.js | 1 - .../fixtures/reporter/testcafe-fixtures/report-data-test.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/functional/fixtures/reporter/test.js b/test/functional/fixtures/reporter/test.js index 356835eb973..517f505f4e9 100644 --- a/test/functional/fixtures/reporter/test.js +++ b/test/functional/fixtures/reporter/test.js @@ -918,10 +918,10 @@ const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG; reporter = createReportDataReporter(); }); - it('Should raise reportData twice with different argument count and types', async () => { + it('Should raise "reportData" event', async () => { const expectedReportData = [1, true, 'string', { 'reportResult': 'test' }]; - await runTests('testcafe-fixtures/report-data-test.js', 'Run t.report action with object val', { + await runTests('testcafe-fixtures/report-data-test.js', 'Run t.report action', { reporter, }); diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js index 3e30a8a3e27..4096e47b8b0 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js @@ -25,7 +25,6 @@ async function errorCheck (t) { test('Simple test', async t => { await t.wait(1); - await t.report(); }); test('Simple command test', async t => { diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js index b728c09504d..8bbded0e186 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/report-data-test.js @@ -1,7 +1,7 @@ fixture`Report Data API` .page('../pages/index.html'); -test('Run t.report action with object val', async t => { +test('Run t.report action', async t => { await t .report(t.browser.alias) .report(1, true, 'string', { 'reportResult': 'test' }); From c76365c37781cf40ff019ef3fb8a905bd7810e5b Mon Sep 17 00:00:00 2001 From: artem-babich Date: Wed, 22 Mar 2023 16:33:21 +0400 Subject: [PATCH 16/16] fix tests 3 --- .../functional/fixtures/reporter/testcafe-fixtures/index-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js index 4096e47b8b0..3e30a8a3e27 100644 --- a/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js +++ b/test/functional/fixtures/reporter/testcafe-fixtures/index-test.js @@ -25,6 +25,7 @@ async function errorCheck (t) { test('Simple test', async t => { await t.wait(1); + await t.report(); }); test('Simple command test', async t => {