How can I run tests with a headless browser?

前端 未结 3 1227
小蘑菇
小蘑菇 2020-12-14 14:04

Using:

ng test

Angular CLI runs the tests by default in Chrome, which is great, but what if I need to run them in a console-only environment (h

3条回答
  •  生来不讨喜
    2020-12-14 14:19

    This should do the trick:

    npm i --save-dev karma-phantomjs-launcher
    

    Then modify the plugins property of the karma.conf.js file, adding the PhantomJS plugin to the list. Also add PhantomJS to the browsers property.

    plugins: [
        require( 'karma-jasmine' ),
        require( 'karma-chrome-launcher' ),
        require( 'karma-phantomjs-launcher' ),
        require( 'karma-remap-istanbul' ),
        require( 'angular-cli/plugins/karma' )
    ],
    ...
    browsers: [ 'PhantomJS', 'Chrome' ],
    

    Since you want a completely headless experience, you can remove Chrome from the browsers property, and remove the karma-chrome-launcher from the plugins array as well.

提交回复
热议问题