Cannot test Electron with Karma?


#1

I have following Electron test, and I can not get electron from window[‘electron’]. It alway shows ‘Developing with web browser…’ when I run it. Which is only the web browser. Is there any way to make electron testable with karma.

this.electron  = window ? window['electron'] : null;
    this.listener$ = this.replaySubject.asObservable();

    console.log(this.electron);
    if (!this.electron) {
      console.log('Developing with web browser...');

    } else {
      this.ipcRenderer.on(
        ELECTRON_CH.BRIDGE.CLIENT,
        (event, message) => {
          console.log('ipcRenderer event:', event);
          this.replaySubject.next(message);
        });
    }
  }

This is my karma.config.js

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-electron'),
      require('karma-chrome-launcher'),
      require('karma-electron-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli', 'electron']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'coverage-istanbul']
              : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Electron'],
    singleRun: false
  });
};