electron-userland / electron-userland/spectron
Effective testing for IPC events?
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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