Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec reporter throws JS error when using t.report and having a reporter onBeforeWrite hook set #8147

Closed
di5ko opened this issue Feb 22, 2024 · 3 comments
Assignees
Labels
HAS WORKAROUND STATE: Issue accepted An issue has been reproduced. TYPE: bug The described behavior is considered as wrong (bug).

Comments

@di5ko
Copy link

di5ko commented Feb 22, 2024

What is your Scenario?

  • Run any test
  • Set a onBeforeWrite hook in .testcaferc.js which modifies spec reporter output
  • At the end of the test, do a t.report({})

What is the Current behavior?

Get JS error:

ERROR The "reportTestDone" method of the "spec" reporter produced an uncaught error. Error details:
TypeError: Cannot read properties of undefined (reading 'durationMs')

What is the Expected behavior?

Do not get a JS error.

What is the public URL of the test page? (attach your complete example)

Find a POC here: https://github.com/di5ko/testcafe-reporter-issue-poc

What is your TestCafe test code?

See Github repo shared above.

Your complete configuration file

See Github repo shared above.

Your complete test report

~/git/testcafe-reporter-issue-poc  $ npm run test-chromium

> [email protected] test-chromium
> node src/run-tests.js chromium:headless

 Running tests in:
 - Chrome 124.0.6316.0 / Monterey 12

 Reporter issue POC
 ✓ Show JS error when attempting to run test (0s)


 1 passed (1s)
[RUN-TESTS] An error occurred:  ReporterPluginError: The "reportTestDone" method of the "spec" reporter produced an uncaught error. Error details:
TypeError: Cannot read properties of undefined (reading 'durationMs')
    at Object.onBeforeWriteHook [as onBeforeWrite] (/Users/di5ko/git/testcafe-reporter-issue-poc/.testcaferc.js:4:66)
    at ReporterPluginHost.write (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/plugin-host.ts:153:25)
    at ReporterPluginHost._renderReportData (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe-reporter-spec/lib/index.js:84:35)
    at ReporterPluginHost.reportTestDone (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe-reporter-spec/lib/index.js:71:12)
    at Reporter.dispatchToPlugin (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:205:38)
    at Reporter._shiftTestQueue (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:408:24)
    at Reporter._resolveTestItem (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:472:20)
    at Reporter._onTaskTestRunDoneHandler (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:627:24)
    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:237:68
    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/emittery/index.js:69:13
    at new ReporterPluginError (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/errors/runtime/index.js:173:9)
    at Reporter.dispatchToPlugin (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:208:35)
    at Reporter._shiftTestQueue (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:408:24)
    at Reporter._resolveTestItem (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:472:20)
    at Reporter._onTaskTestRunDoneHandler (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:627:24)
    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:237:68
    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/emittery/index.js:69:13
    at Array.map (<anonymous>)
    at MessageBus.emit (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/emittery/index.js:67:23)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'E1058',
  data: [
    'reportTestDone',
    'spec',
    "TypeError: Cannot read properties of undefined (reading 'durationMs')\n" +
      '    at Object.onBeforeWriteHook [as onBeforeWrite] (/Users/di5ko/git/testcafe-reporter-issue-poc/.testcaferc.js:4:66)\n' +
      '    at ReporterPluginHost.write (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/plugin-host.ts:153:25)\n' +
      '    at ReporterPluginHost._renderReportData (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe-reporter-spec/lib/index.js:84:35)\n' +
      '    at ReporterPluginHost.reportTestDone (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe-reporter-spec/lib/index.js:71:12)\n' +
      '    at Reporter.dispatchToPlugin (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:205:38)\n' +
      '    at Reporter._shiftTestQueue (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:408:24)\n' +
      '    at Reporter._resolveTestItem (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:472:20)\n' +
      '    at Reporter._onTaskTestRunDoneHandler (/Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:627:24)\n' +
      '    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/testcafe/src/reporter/index.ts:237:68\n' +
      '    at /Users/di5ko/git/testcafe-reporter-issue-poc/node_modules/emittery/index.js:69:13'
  ]
}

Screenshots

No response

Steps to Reproduce

Run npm run test in repo shared above.

TestCafe version

3.5.0

Node.js version

v20.10.0

Command-line arguments

npm run test

Browser name(s) and version(s)

Chrome, Chromium, FF

Platform(s) and version(s)

MacOS Monterey 12

Other

No response

@di5ko di5ko added the TYPE: bug The described behavior is considered as wrong (bug). label Feb 22, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 22, 2024
@Bayheck
Copy link
Collaborator

Bayheck commented Feb 27, 2024

Hello, thank you for the example. I managed to reproduce the issue.

For some reason, the onBeforeWriteHook method is called twice. The second time it is called, the writeInfo object returns almost empty. As a result, an error occurs: https://github.com/di5ko/testcafe-reporter-issue-poc/blob/9ff2af8f54b5e527ca17b7718169db3afd943dc7/.testcaferc.js#L4C9-L4C78.

As a workaround, add the following line after the third line in your .testcaferc.js:

if (!testRunInfo) return;

@Bayheck Bayheck added STATE: Issue accepted An issue has been reproduced. and removed STATE: Need response An issue that requires a response or attention from the team. labels Feb 27, 2024
Copy link

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

@PavelMor25 PavelMor25 self-assigned this Mar 12, 2024
@PavelMor25
Copy link
Collaborator

PavelMor25 commented Mar 12, 2024

Hello @di5ko,

We have re-investigated the issue and believe that it is expected behavior. The default spec reporter displays custom data (passed through the report method) after test completion, once for each browser that runs the test. Due to this, the string Report data is outputted before it with empty data initiated by the reportTestDone event. As a result, this error occurs.

@need-response-app need-response-app bot added STATE: Need response An issue that requires a response or attention from the team. and removed STATE: Need response An issue that requires a response or attention from the team. labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HAS WORKAROUND STATE: Issue accepted An issue has been reproduced. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

3 participants