twolfson / karma-electron

Karma launcher and preprocessor for Electron
The Unlicense
59 stars 21 forks source link

[Bug|Unexpected] Shows 2 windows with '--show' flag and client's `useIframe` #21

Closed luchillo17 closed 7 years ago

luchillo17 commented 7 years ago

Background

I have an Electron app with Webpack, Typescript and Karma support (karma part WIP).

Problem

Originally when run it only shows the karma electron browser in launch bar, and the test output in the terminal, so far so good.

But when i use the client's useIframe: false property and the --show flag in the customLaunchers.CustomElectron it shows 2 windows, 1 for the karma testing GUI (which is almost the same as terminal) and another white screen window.

Interesting note: The second window is always white, but when i press the Debug button in the main karma window, a third one shows with my app in there as well as the specs logs, it would be cool if that window was the actual one shown by the flags in question.

Guesses

Steps to reproduce

twolfson commented 7 years ago

This is expected behavior. When we shut off useIframe, Karma moves to using window.open instead so there are 2 windows:

To demonstrate this point further, we could disable useIframe in other browsers and see the same result (e.g. Chrome, Firefox)

luchillo17 commented 7 years ago

The thing is that without useIframe: false we lose nodeIntegration, but with it, it shows 2 windows, with the second being incredibly annoying poping up all the time.

I guess the idea is to run with --show flag off and only show when we need to debug the tests, right?

twolfson commented 7 years ago

Yep, typically showing the window isn't too helpful as content is often added/remove quicker than we can see. To make it less painful to add/remove the --show flag in karma.conf.js, I use the following setup:

Add ElectronVisible browser but don't set it as default browser:

    browsers: ['Electron'],
    customLaunchers: {
      ElectronVisible: {
        base: 'Electron',
        flags: ['--show']
      }
    }

Override default browsers via CLI:

karma start --browsers ElectronVisible
# or for `npm-scripts`
npm run test-karma -- --browsers ElectronVisible
luchillo17 commented 7 years ago

Nice 😄