All posts

Testing Error Scenarios in Electron Applications

A practical guide to testing error scenarios in Electron apps covering main process crashes, IPC failures, and renderer error handling.

Testing Error Scenarios in Electron Applications

Electron apps run across two processes — main and renderer — making error testing uniquely challenging. Here's how to cover both sides.

Test Main Process Crashes

Use Spectron or Playwright to verify your app handles main process errors:

const { _electron: electron } = require('playwright');

test('app recovers from main process error', async () => {
  const app = await electron.launch({ args: ['./main.js'] });
  const window = await app.firstWindow();

  // Trigger an error in main process
  await app.evaluate(async ({ app }) => {
    app.emit('renderer-process-crashed');
  });

  // Verify recovery dialog appears
  const dialog = await window.locator('.error-dialog');
  await expect(dialog).toBeVisible();
  await app.close();
});

Test IPC Communication Failures

IPC between main and renderer can fail silently. Test timeout scenarios:

test('renderer handles IPC timeout gracefully', async () => {
  // Mock a slow main process handler
  ipcMain.handle('fetch-data', async () => {
    await new Promise(resolve => setTimeout(resolve, 10000));
    return { data: 'late' };
  });

  const result = await window.evaluate(async () => {
    try {
      return await window.electronAPI.fetchData({ timeout: 3000 });
    } catch (e) {
      return { error: e.message };
    }
  });

  expect(result.error).toContain('timeout');
});

Test Renderer Errors

Capture and verify renderer process unhandled errors:

test('unhandled renderer error is captured', async () => {
  const errors = [];
  window.on('pageerror', error => errors.push(error));

  await window.evaluate(() => {
    throw new Error('Unhandled renderer error');
  });

  expect(errors).toHaveLength(1);
  expect(errors[0].message).toContain('Unhandled renderer error');
});

Error Scenarios to Cover

  • File system permission errors — app can't write to expected paths
  • Auto-update failures — download interruptions, signature mismatches
  • Native module load failures — missing or incompatible binaries
  • Offline mode — network requests fail gracefully

Production Error Visibility

Electron apps run on user machines where you can't check logs. Integrate Bugsly to capture both main and renderer process errors, giving you visibility into crashes that happen across thousands of different system configurations.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free