`urlRoot` in `karma.conf.js` can't be set to anything other than the default `/`

Open
#22,132 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, javascript, typescript
Domain
testing

Research direction

Start with karma.conf.js and the ng test entry point, using the shown urlRoot configuration to reproduce the failure. Trace how the custom context file resolves context.js when urlRoot is set to newBase, and compare it with the expected /karma/context.js path. Done means the test run requests the context script under the configured urlRoot without a 404.

Written by the indexing model from the issue text.

Description

area: @angular-devkit/build-angular devkit/build-angular:karma freq1: low severity3: broken type: bug/fix

🐞 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?

No.

Description

Can't set urlRoot in karma.conf.js to anything other than "/" because:

Angular CLI uses custom context file, which leads to this bug. It adds <base href="/">, which forces context.html to request http://localhost:9876/context.js instead of http://localhost:9876/karma/context.js.

which is described in detail in this issue: https://github.com/karma-runner/karma/issues/3357#issuecomment-634630974.

🔬 Minimal Reproduction

Run ng test with a karma.conf.js that contains a urlRoot set to anything but /:

{
    ...,
    urlRoot: "newBase"
}

🔥 Exception or Error

The error that is logged is the following:

09 11 2021 23:25:29.766:WARN [web-server]: 404: /_karma_webpack_/context.js

🌍 Your Environment


Angular CLI: 11.2.0
Node: 14.18.0
OS: darwin x64

Angular: 11.2.14
... common, compiler, compiler-cli, core, forms, localize
... platform-browser, platform-browser-dynamic, router, upgrade
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1102.0
@angular-devkit/build-angular   0.1102.0
@angular-devkit/core            11.2.14
@angular-devkit/schematics      11.2.14
@angular/animations             12.2.8
@angular/cdk                    11.2.13
@angular/cli                    11.2.0
@schematics/angular             11.2.14
@schematics/update              0.1102.0
rxjs                            6.6.7
typescript                      4.1.6

Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.