angular / angular/angular-cli

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

未關閉
#22,132 4 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
area: @angular-devkit/build-angular devkit/build-angular:karma freq1: low severity3: broken type: bug/fix
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

# 🐞 Bug report

### Command (mark with an `x`)

- [ ] new
- [ ] build
- [ ] serve
- [x] 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 ``, 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 `/`:

```js
{
...,
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

貢獻指南

開啟貢獻指南

研究方向

從 karma.conf.js 和 ng test 進入點開始,使用所示的 urlRoot 設定重現失敗。追蹤自訂內容檔案在 urlRoot 設定為 newBase 時如何解析 context.js,並將其與預期的 /karma/context.js 路徑比較。當測試執行在設定的 urlRoot 下要求內容指令碼且沒有 404 時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
angular, javascript, typescript
領域
testing
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。