1

Started to get Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client in random places using TestCafe.

I have a local node module that is a wrapper on createTestCafe() api. Module is called testcafe-runner and is installed like this "testcafe-runner": "file:local_modules/testcafe-runner".

I started to get the error with the following exception:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:485:11)
    at RequestPipelineContext.redirect (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe-hammerhead\lib\request-pipeline\context.js:278:9)
    at TestRun.handlePageError (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe\src\test-run\index.js:287:13)
    at SessionController.handlePageError (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe\src\test-run\session-controller.js:43:36)
    at error (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe-hammerhead\lib\request-pipeline\utils.js:81:48)
    at DestinationRequest.<anonymous> (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe-hammerhead\lib\request-pipeline\utils.js:62:9)
    at DestinationRequest.emit (events.js:209:13)
    at DestinationRequest.EventEmitter.emit (domain.js:476:20)
    at DestinationRequest._onError (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe-hammerhead\lib\request-pipeline\destination-request\index.js:171:17)
    at ClientRequest.<anonymous> (C:\MyTests\local_modules\testcafe-runner\node_modules\testcafe-hammerhead\lib\request-pipeline\destination-request\index.js:93:40) {
  domainThrown: true
}
npm ERR! code ELIFECYCLE
npm ERR! errno 7

All test javascript files are located in C:\MyTests folder.

Version of testcafe 1.8.4 installed on both local_module and project

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • The information you provided is insufficient to determine the cause of the issue. Please share the module you mentioned and a sample test case that we can run on our side to diagnose this behavior. Or, better yet, submit a bug report at [https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md](https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md) and fill-in all the information to reproduce the issue. Thank you. – Alex Skorkin May 05 '20 at 12:29
  • Thanks for your answer and yes, I can imagine that it might be insuffucient. We have very complex test suites driven by json files and our system under test is on test env. with integration with telephony systems etc. so it would be impossible to run the test even if I provide the full source code. However problem is solved now by downgrading version of testcafe in all modules to explicit "1.8.1" which comes with testcafe-hammerhead 16.0.2. I suspect, however I might be wrong, that the issue might have been introduced between 16.0.2 and 16.2.3 of testcafe-hammerhead. – Szymon Semrau May 06 '20 at 13:32
  • 1
    I think that downgrading TestCafe is only a temporary solution. It's better to find the cause of the real issue. There were a lot of changes in `testcafe-hammerhead ` between versions `16.0.2` and `16.2.3`, so it's impossible to detect the problem without a project. We understand that it's very difficult to provide a full project integrated with other services, however, we would really appreciate it if you can extract the problematic part and share it with us. – Alex Kamaev May 07 '20 at 09:18

1 Answers1

0

I am getting the exact error.

testcafe - 1.8.4
OS - Mac Catalina
browser - chrome 81 
Node - 12.16.3

This is happening while clicking on a logout button.
There is 302 redirection happening and ultimately user is redirected back to login page.

The test cafe browser url is shown as at failure http://localhost:1337/03WvIUCEQ/about:error

Dinesh Kumar
  • 1,694
  • 15
  • 22