迁移到 Angular9 后错误附加了 Webpack 目录

JFP*_*ard 1 karma-jasmine jasmine2.0 karma-webpack angular

我最近将我的项目从 angular 7 升级到了 angular 9。

当我运行测试 ( ng test) 时,我总是会http://localhost:9876/_karma_webpack_/附加到错误,因此在 Visual Studio 代码中,我们无法单击错误直接访问文件。

为了测试,我expect(2).toEqual(1);app.component.spec.ts文件中添加了

例如,使用开箱即用的 angular 7 projet,我在 ng test 中收到此错误:

Chrome 81.0.4044 (Windows 10.0.0) AppComponent should have as title 'angular7app' FAILED
        Expected 2 to equal 1.
            at UserContext.<anonymous> (src/app/app.component.spec.ts:23:12)
Run Code Online (Sandbox Code Playgroud)

至于角度 9,我收到此错误:

Chrome 81.0.4044.122 (Windows 10) AppComponent should have as title 'untaire' FAILED
        Error: Expected 2 to be 1.
            at <Jasmine>
            at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/src/app/app.component.spec.ts:23:12)
Run Code Online (Sandbox Code Playgroud)

当我检查 package.json 中的版本时,这些是影响 Karma 和 jasmine 的更改:

"@types/jasmine": "~2.8.8"                    to "~3.5.0"
"@types/jasminewd2": "~2.0.3"                 to "~2.0.3" (no changes)
"jasmine-core": "~2.99.1"                     to "~3.5.0"
"jasmine-spec-reporter": "~4.2.1",            to "~4.2.1" (no changes)
"karma": "~4.0.0",                            to "~5.0.0"
"karma-chrome-launcher": "~2.2.0",            to "~3.1.0"
"karma-coverage-istanbul-reporter": "~2.0.1", to "~2.1.0"
"karma-jasmine": "~1.1.2",                    to "~3.0.1"
"karma-jasmine-html-reporter": "^0.2.2",      to "^1.4.2"
Run Code Online (Sandbox Code Playgroud)

我已经检查过,但在任何这些软件包中都没有发现有关这种新行为的任何信息

DMI*_*KIN 5

您可以添加到karma.conf.js配置属性formatError

formatError: (msg) =>
  msg.replace(/http:\/\/localhost:9876\/_karma_webpack_\//g, '')
Run Code Online (Sandbox Code Playgroud)

但不确定这是最佳实践,但是我无法在文档业力http://karma-runner.github.io/4.0/config/configuration-file.html 中搜索替代更改格式输出位置错误