karma-runner / karma-browserstack-launcher

A Karma plugin. Launch any browser on BrowserStack!
MIT License
150 stars 82 forks source link

BrowserStack: Karma tests hang after finish with Angular 14 #195

Open suryart opened 2 years ago

suryart commented 2 years ago

Description

For Angular 14, when running the unit tests with Karma the process hangs after all tests finish successfully. As I can see the test getting completed on BrowserStack. Here is a session public link.

Here is an example repository created by @daniel-sc where issue can be reproduced.

Details for setting up and running the tests are in the example repository(link above).

Here is the link to log file.

What is happening?

When running the npm run test-ci the process is stuck after 28 07 2022 18:24:35.692:DEBUG [launcher]: FINISHED -> FINISHED log line.

What is expected?

When the tests are finished the process should exit.

ravasconcelos commented 2 years ago

Hi,

I am experiencing exactly the same issue in my project after upgrading it to Angular 14. It was working fine on Angular 12.

@suryart , if you find any work around, can you please share it?

daniel-sc commented 2 years ago

A (hacky) workaround is to run the following before executing the tests:

sed -i -z "s/ removeAllListeners()\n/ removeAllListeners();process.nextTick(() => process.exit(code || 0));\n/g" node_modules/karma/lib/server.js

Hope this helps others that get stuck..

ravasconcelos commented 2 years ago

Thank you for sharing the hack @daniel-sc it worked for me with a minor adjustment!

Blackbaud-SteveBrush commented 2 years ago

So is this a fix that needs to happen in karma-browserstack-launcher or karma, or...?

simon-chen-1 commented 1 year ago

@daniel-sc Running that before executing the tests worked perfectly! But I'm curious if there's an alternative solution/fix in place that would resolve this issue without having to run that script you shared?

daniel-sc commented 1 year ago

I'm not aware of any real solution to this issue. It seems that nobody at Browserstack really cares about this.. 🤷‍♀️

MessiasLima commented 1 year ago

A (hacky) workaround is to run the following before executing the tests:

sed -i -z "s/ removeAllListeners()\n/ removeAllListeners();process.nextTick(() => process.exit(code || 0));\n/g" node_modules/karma/lib/server.js

Hope this helps others that get stuck..

Thank you @daniel-sc I'm trying to use patch-package to apply your solution. So, should the code looks like this?

Screenshot 2023-02-20 at 21 01 45