Skip to content

Isolate electron apis and simplify preload testing #374

@cloverich

Description

@cloverich

Continued after #362 / #183

I migrated the test running off mocha (#368 ) along with esm (see #363 and #365 ). But in the end I realized testing electron still requires more, because:

  • node:test whether via cli or run runs tests in a node sub-processes
  • Electron api access requires an (sub) process

The current setup tried to make ^ work, by:

  • Starting an electron main process
  • Creating a hidden browser window, and loading test bundles as a preload script
  • Having node:test test and describe commands in the preload (test) script

This emits the expected output, but there is no way to trigger process.exit(1) off failures or listen to events, without dipping into internals, AFAIK. There are a few solutions I can think of:

  1. Have each node:test start its own electron sub-process and execute the scenario(s)
  2. Run proper QA style tests (Selenium, etc)
  3. Isolate and mock electron apis and run the preload tests as regular node backend tests

1 and 2 are spelled out in the electron docs. 3 is the approach I think we should take instead, because the preload bundles only use two electron apis really: electron-store and opening dialogs; mocking them should be easy. Then the tests can run like regular node backend tests. This is mostly possible because the application architecture, at the time of this writing, with only a few exceptions is:

  • Main browser bundle - operates like typical browser code
  • Preload bundle - operates like typical backend code

They talk to each other via a client exposed on window via useClient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions