Webpack directory appended at error after migrating to Angular9

雨燕双飞 提交于 2020-06-13 05:28:26

问题


I've recently upgraded my projet from angular 7 to angular 9.

When I run the tests (ng test), I always get http://localhost:9876/_karma_webpack_/ appendend to the error, hence in visual studio code, we can't click on the error to got directly to the file.

For the sake of testing, I've added expect(2).toEqual(1); in the app.component.spec.ts file

For example, with the angular 7 projet out of the box, I get this error with 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)

as for the angular 9, I get this error:

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)

When I ckeck the versions in the package.json, theses are the changes that affects Karma and 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"

I've checked and I didn't found anything about this new behavior on any of theses packages


回答1:


You can add to karma.conf.js configuration property formatError:

formatError: (msg) =>
  msg.replace(/http:\/\/localhost:9876\/_karma_webpack_\//g, '')

But not sure that is the best practice, however I cannot search alternative change format output location error in documentation karma http://karma-runner.github.io/4.0/config/configuration-file.html



来源:https://stackoverflow.com/questions/61819887/webpack-directory-appended-at-error-after-migrating-to-angular9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!