title: How to setup PhantomJS with Angular 8? ----> Switched to Puppeteer
body: <p>I have an Angular 8 application with unit tests and when I run ng test the tests are executed. I want to include the tests in TFS to complete automate my CI/CD pipeline and for that I'm trying to use PhantomJS.</p>
  
  <p>My Current setup is:</p>
  
  <pre><code>Angular CLI: 8.0.4
  Node: 12.4.0
  OS: win32 x64
  Angular: 8.0.2
  ... animations, common, compiler, compiler-cli, core, forms
  ... language-service, platform-browser, platform-browser-dynamic
  ... router
  
  Package                           Version
  -----------------------------------------------------------
  @angular-devkit/architect         0.800.4
  @angular-devkit/build-angular     0.800.4
  @angular-devkit/build-optimizer   0.800.4
  @angular-devkit/build-webpack     0.800.4
  @angular-devkit/core              8.0.4
  @angular-devkit/schematics        8.0.4
  @angular/cdk                      8.0.1
  @angular/cli                      8.0.4
  @angular/material                 8.0.1
  @ngtools/webpack                  8.0.4
  @schematics/angular               8.0.4
  @schematics/update                0.800.4
  rxjs                              6.5.2
  typescript                        3.4.5
  webpack                           4.30.0
  </code></pre>
  
  <p>My karma.conf.js file:</p>
  
  <pre><code>module.exports = function (config) {
    config.set({
      basePath: '',
      frameworks: ['jasmine', '@angular-devkit/build-angular'],
      plugins: [
        require('karma-jasmine'),
        require('karma-chrome-launcher'),
        require('karma-phantomjs-launcher'),
        require('karma-jasmine-html-reporter'),
        require('karma-coverage-istanbul-reporter'),
        require('karma-junit-reporter'),
        require('@angular-devkit/build-angular/plugins/karma')
      ],
      client: {
        clearContext: false // leave Jasmine Spec Runner output visible in browser
      },
      coverageIstanbulReporter: {
        dir: require('path').join(__dirname, '../coverage/FeedbackApp'),
        reports: ['html', 'lcovonly', 'text-summary'],
        fixWebpackSourcePaths: true
      },
      reporters: ['progress', 'kjhtml', 'junit'],
      port: 9876,
      colors: true,
      logLevel: config.LOG_INFO,
      autoWatch: true,
      browsers: ['Chrome'],
      captureTimeout: 60000,
      singleRun: true
    });
  };
  </code></pre>
  
  <p>When I run ng test --browsers=PhantomJS I get this errors:</p>
  
  <pre><code>10% building 2/2 modules 0 active26 06 2019 08:55:52.878:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
  26 06 2019 08:55:52.881:INFO [launcher]: Launching browsers PhantomJS with concurrency unlimited
  26 06 2019 08:55:52.892:INFO [launcher]: Starting browser PhantomJS                     26 06 2019 08:55:59.266:INFO [PhantomJS 2.1.1 (Windows 8.0.0)]: Connected on socket HEg48BpEY_ePpotFAAAA with id 68924062
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Use of reserved word 'class'
    at http://localhost:9876/_karma_webpack_/polyfills.js:3008:0
  
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Use of reserved word 'class'
    at http://localhost:9876/_karma_webpack_/polyfills.js:3008:0
  
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Use of reserved word 'class'
    at http://localhost:9876/_karma_webpack_/vendor.js:88:0
  
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Use of reserved word 'class'
    at http://localhost:9876/_karma_webpack_/vendor.js:88:0
  
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Unexpected token ')'
    at http://localhost:9876/_karma_webpack_/main.js:362:0
  
  PhantomJS 2.1.1 (Windows 8.0.0) ERROR
    SyntaxError: Unexpected token ')'
    at http://localhost:9876/_karma_webpack_/main.js:362:0
  </code></pre>
  
  <p>Can anyone help me with this ?</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I replaced PhantomJS by Puppeteer, and everything is working now.</p>
  
  <p>Here is what I have done:</p>
  
  <blockquote>
    <p>npm install --save-dev puppeteer</p>
  </blockquote>
  
  <p>Changed my karma.conf.js file to look like this:</p>
  
  <pre><code>const process = require('process'); process.env.CHROME_BIN = 
  require('puppeteer').executablePath();
  
  module.exports = function (config) {   config.set({
      basePath: '',
      frameworks: ['jasmine', '@angular-devkit/build-angular'],
      plugins: [
        require('karma-jasmine'),
        require('karma-chrome-launcher'),
        require('karma-jasmine-html-reporter'),
        require('karma-coverage-istanbul-reporter'),
        require('@angular-devkit/build-angular/plugins/karma')
      ],
      client: {
        clearContext: false // leave Jasmine Spec Runner output visible in browser
      },
      coverageIstanbulReporter: {
        dir: require('path').join(__dirname, '../coverage/FeedbackApp'),
        reports: ['html', 'lcovonly'],
        fixWebpackSourcePaths: true
      },
      reporters: ['progress', 'kjhtml'],
      port: 9876,
      colors: true,
      logLevel: config.LOG_INFO,
      autoWatch: true,
      browsers: ['ChromeHeadlessNoSandbox'],
      customLaunchers: {
        ChromeHeadlessNoSandbox: {
          base: 'ChromeHeadless',
          flags: ['--no-sandbox','--headless','--disable-gpu','--disable-translate','--disable-extensions']
        }
      },
      singleRun: true   }); };
  </code></pre>
  
  <p>Added to scripts section in my package.json:</p>
  
  <blockquote>
    <p>"test-puppeteer": "ng test --watch=false --source-map=false"</p>
  </blockquote>
  
  <p>Attention to the <strong>--source-map=false</strong> - without this it always fails</p>
  
  <p>In TFS, in a custom NPM task:</p>
  
  <blockquote>
    <p>run test-puppeteer</p>
  </blockquote>