electron-userland / electron-userland/spectron

Effective testing for IPC events?

Open
#91 13 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.7k
Forks
225
PR merge metrics
No merged PRs in 30d

Description

I'm trying to find a way of effectively testing for IPC events being sent/received on either the main or renderer processes.

Looking at the spectron tests, I came across this: https://github.com/electron/spectron/blob/master/test/application-test.js#L219. However, this approach of assigning a global variable within the main process seems awkward. It also requires modifying the application's code just to enable the test capability for any given IPC event.

I tried the following to no avail:

it("listens for a message on ipcRenderer", function(done) {
    app.client.waitUntilWindowLoaded().then(() => {
      const ipcRenderer = app.electron.ipcRenderer;

      ipcRenderer.on('msg-received', function(evt, payload) {
        payload.should.be("SUCCESS")
        done()
      })

      ipcRenderer.send("msg-received", "SUCCESS")
    })
  });

Evens sent directly from within the renderer process also won't be captured by tests, and I suspect it's because mocha's test process is separate from the process running Electron.

So, is it possible to receive Electron events from either process within a Spectron test, in a similar manner to the example above? I suspect not, but if this is the case, what can be done to enable this capability?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Spectron's referenced test/application-test.js#L219 and the ipcRenderer test example in this issue. Trace how the test process communicates with the main and renderer processes, then check whether an existing Spectron entry point supports IPC observation without application changes. Done means a supported approach is identified or the limitation and required capability are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, javascript
Domain
desktop-dev, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.