Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#22,132 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
angular, javascript, typescript
领域
testing

调研方向

从 karma.conf.js 和 ng test 入口开始,使用所示的 urlRoot 配置重现故障。跟踪自定义上下文文件在 urlRoot 设置为 newBase 时如何解析 context.js,并将其与预期的 /karma/context.js 路径进行比较。当测试运行在配置的 urlRoot 下请求上下文脚本且不出现 404 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
16 小时 35 分钟
30 天内合并 PR
176

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。