【问题标题】:Angular 7 Unit testing - PhantomJS has crashedAngular 7 单元测试 - PhantomJS 崩溃了
【发布时间】:2020-05-05 01:01:00
【问题描述】:

我正在使用 Angular 7 使用 karma 和 phantom JS 进行单元测试。当我从本地机器运行时,从我的 MAC --

ng test --watch=false

本地机器输出 -

ng test
10% building modules 2/2 modules 0 active18 01 2020 14:54:57.990:WARN [karma]: No captured browser, open http://localhost:9876/
18 01 2020 14:54:57.995:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
18 01 2020 14:54:57.997:INFO [launcher]: Launching browsers PhantomJS with concurrency unlimited
18 01 2020 14:54:58.011:INFO [launcher]: Starting browser PhantomJS
 10% building modules 5/7 modules 2 active ..._weather_forcast_testing/src/styles.cssBrowserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
18 01 2020 14:55:05.820:WARN [karma]: No captured browser, open http://localhost:9876/    
18 01 2020 14:55:06.004:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket i77IuK4nefa0HrxhAAAA with id 31463905
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 6 of 6 SUCCESS (1.598 secs / 1.535 secs)
TOTAL: 6 SUCCESS
TOTAL: 6 SUCCESS

一切正常。 MAC 配置 -

Angular CLI: 7.3.7
Node: 8.9.4
OS: darwin x64
Angular: 7.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.3.7
@angular/cdk                      7.3.6
@angular/cli                      7.3.7
@angular/flex-layout              7.0.0-beta.22
@angular/material                 7.3.6
@ngtools/webpack                  7.1.4
@schematics/angular               7.3.7
@schematics/update                0.13.7
rxjs                              6.4.0
typescript                        3.2.2
webpack                           4.23.1

我在 AWS EC2 - Ubuntu 18.04 中部署了相同的代码,尝试运行相同的命令 -

ng test --watch=false

Ubuntu机器输出-

ng test
10% building modules 2/2 modules 0 active18 01 2020 09:22:29.639:WARN [karma]: No captured browser, open http://localhost:9876/
    18 01 2020 09:22:29.710:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
    18 01 2020 09:22:29.710:INFO [launcher]: Launching browsers PhantomJS with concurrency unlimited
    18 01 2020 09:22:29.831:INFO [launcher]: Starting browser PhantomJS
     10% building modules 7/10 modules 3 active ..._weather_forcast_testing/src/styles.cssBrowserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
     52% building modules 354/354 modules 0 active18 01 2020 09:23:29.869:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
     56% building modules 390/390 modules 0 active18 01 2020 09:23:34.149:INFO [launcher]: Trying to start PhantomJS again (1/2).
     95% emitting CopyPlugin                                                                  

    18 01 2020 09:24:54.635:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
    18 01 2020 09:25:24.043:WARN [karma]: No captured browser, open http://localhost:9876/
    18 01 2020 09:25:24.793:INFO [launcher]: Trying to start PhantomJS again (2/2).
    18 01 2020 09:25:25.515:ERROR [karma-server]: { Error: spawn ENOMEM

    Cannot read property 'success' of undefined
    TypeError: Cannot read property 'success' of undefined
        at TestCommand.runSingleTarget (/home/ubuntu/youtube_angular7__weather_forcast_testing/node_modules/@angular/cli/models/packages/angular/cli/models/architect-command.ts:242:21)
        at <anonymous>
        at Immediate._tickCallback (internal/process/next_tick.js:189:7)
        at runCallback (timers.js:810:20)
        at tryOnImmediate (timers.js:768:5)
        at processImmediate [as _immediateCallback] (timers.js:745:5)

Ubuntu 机器配置 -

Angular CLI: 7.3.7
Node: 8.17.0
OS: linux x64
Angular: 7.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.3.7
@angular/cdk                      7.3.6
@angular/cli                      7.3.7
@angular/flex-layout              7.0.0-beta.22
@angular/material                 7.3.6
@ngtools/webpack                  7.1.4
@schematics/angular               7.3.7
@schematics/update                0.13.7
rxjs                              6.4.0
typescript                        3.2.2
webpack                           4.23.1

为什么相同的代码和相同的配置在 MAC 中运行良好,而在 Ubuntu 中却无法运行?

【问题讨论】:

    标签: phantomjs angular7 karma-jasmine angular-test


    【解决方案1】:

    问题通过添加解决 -

    ng test --source-map=false --watch=false
    

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 2017-08-15
      • 2015-11-27
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多