Skip to content

Chrome/karma is started before the webpack dev server is ready to serve #22495

Closed
@arobinson

Description

@arobinson

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

No, AFAIK, this has always been present

Description

A clear and concise description of the problem...

There is this issue in Karma: karma-runner/karma#3745

What happens is that Angular CLI is starting karma and the webpack dev server at the same time. On large Angular projects, like ours, Angular + webpack is very slow (1-2 minutes to start ng serve for example, separate issue we really need to address somehow).

What seems to occur is that chrome (or ChromeHeadless) gives up trying to load the page (it would see the problem that the server is not responding). Karma then kills the browser and restarts it (triggering issue karma-runner/karma#3745). Eventually the webpack dev server starts responding, and the tests run. Once the tests complete, the coverage report (and potentially other reporters) fail to write their reports.

While there is a bug in Karma that needs to be fixed, it does not seem to make sense to start the test framework until the webpack dev server is ready to serve the application. When it is ready, we see the Browser application bundle generation complete printed to the terminal.

Ideally karma would be started after a 200 HTTP response could be obtained from the webpack dev server

🔬 Minimal Reproduction

Only thing that is required is to run ng test on an Angular project. The problem to reproduce is that the application has to have enough code to cause webpack dev server to be too slow to start before chrome gives up loading the page.

🔥 Exception or Error





🌍 Your Environment




Angular CLI: 13.1.2
Node: 14.17.1
Package Manager: npm 6.14.13
OS: darwin x64

Angular: 13.1.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.2
@angular-devkit/build-angular   13.1.2
@angular-devkit/core            13.1.2
@angular-devkit/schematics      13.1.2
@angular/cli                    13.1.2
@ngtools/webpack                13.1.2
@schematics/angular             13.1.2
ng-packagr                      13.1.2
rxjs                            6.6.7
typescript                      4.5.4
webpack                         5.65.0

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions