karma-runner / karma-runner/karma
onBrowserStart is not executed if the browser is restarted
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
This issue was originally filed as https://github.com/karma-runner/karma/issues/945
The problem is surfacing as a coverage failure and was filed as https://github.com/karma-runner/karma-coverage/issues/434
The issue is that if the browser does not initially respond, the `onBrowserStart` function of the karma reporters is not fired.
This happens with high frequency with larger Angular projects. I believe the issue there is that the `ng serve` portion of `ng test` takes a while (the time it takes for the webpack dev server to start is quite long with large Angular projects). Karma considers this as chrome not responding. I think what is happening under the covers is that Chrome gives up trying to load the page and times out while trying to load a resource from the webpack dev server. Since chrome failed to load the page, karma then thinks that chrome is not responding.
This is seen in our CI builds when we don't get a coverage report:
```
START:
12 01 2022 20:32:01.145:INFO [karma-server]: Karma v6.3.9 server started at http://localhost:9876/
12 01 2022 20:32:01.145:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
12 01 2022 20:32:01.152:INFO [launcher]: Starting browser Chrome
12 01 2022 20:34:01.547:WARN [launcher]: Chrome has not captured in 120000 ms, killing.
12 01 2022 20:34:04.784:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL.
12 01 2022 20:34:13.076:INFO [launcher]: Trying to start Chrome again (1/2).
✔ Browser application bundle generation complete.
```
The `Browser application bundle generation complete.` signifies when the webpack dev server finally started doing its job, so chrome has already died and been restarted.
The issue seemed to be documented well by this person's comment:
https://github.com/karma-runner/karma-coverage/issues/434#issuecomment-812183323
Contributor guide
Research direction
Start by tracing the browser launcher restart path and the reporters' onBrowserStart callback described in the issue. Reproduce a delayed Chrome capture while the webpack dev server starts, then verify that onBrowserStart is fired after the browser is restarted and that the coverage report is produced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, javascript, webpack
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100