Angular & StompJS provokes Karma test load failure

╄→尐↘猪︶ㄣ 提交于 2019-12-24 19:14:50

问题


We are using Angular 5.2.0 and we recently added StompJS 2.2.3 for WS features.

  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "...",
    "stompjs": "^2.3.3",
  },

However, since the addition, Karma tests won't load with the error :

ERROR in ./node_modules/stompjs/lib/stomp-node.js
Module not found: Error: Can't resolve 'net' in 'C:\Workspace\Projets\HAW_WEB\common\hubanywhere-angular-common\node_modules\stompjs\lib'
 @ ./node_modules/stompjs/lib/stomp-node.js 14:8-22
 @ ./node_modules/stompjs/index.js
 @ ./src/app/common/service/stomp/stomp.service.ts
 @ ./src/app/common/service/stomp/stomp.service.spec.ts
 @ ./src \.spec\.ts$
 @ ./src/test.ts

It seems we have to allow karma to load the native 'net' packages, but I can't find the correct configuration to place in the karma.conf.js file.

Thanks for any help.


回答1:


Please use maintained version of stompjs from https://github.com/stomp-js/stompjs (npm @stomp/stompjs). There is also a specialized version for Angular https://github.com/stomp-js/ng2-stompjs (npm @stomp/ng2-stompjs).

These work well with Webpack, Rollup, RxJS and other newer libraries/tool-chain.

These have been re-written in TypeScript and all of these are distributed with type libraries. These come with guides and samples (see: https://stomp-js.github.io/).



来源:https://stackoverflow.com/questions/51112304/angular-stompjs-provokes-karma-test-load-failure

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