nathanbuchar / electron-settings

📝 A simple persistent user settings framework for Electron.
https://electron-settings.js.org
MIT License
817 stars 60 forks source link

Add setElectron to the API #94

Closed kontrollanten closed 4 years ago

kontrollanten commented 7 years ago

I'm implementing e2e tests with Spectron and would like to clear all my settings before each test. When running Spectron the electron instance isn't available via require('electron') from Spectron, why it isn't possible to run

beforeEach(function() {
  const app = new Application({...});
  const settings = require('electron-settings');
  settings.deleteAll();
});

Would it be possible to add something like setElectron to the API? Then it would be:

beforeEach(function() {
  const app = new Application({...});
  const settings = require('electron-settings');
  settings.setElectron(app.electron);
  settings.deleteAll();
});

I'm pretty new to Electron and I'm not sure that this is the right approach to solve my problem. But if you agree I'm happy to make a PR.

nathanbuchar commented 7 years ago

Why not just move the electron-settings require outside of the beforeEach directive?

const settings = require('electron-settings');

beforeEach(() => {
  // ...
  settings.deletAll();
});
kontrollanten commented 7 years ago

Then I get the following error

TypeError: Cannot read property 'app' of undefined
    at Object.<anonymous> (.../node_modules/electron-settings/lib/settings.js:26:44)

Which comes from

const app = electron.app || electron.remote.app;
hql287 commented 6 years ago

I'm also encountering this issue! Have you found a way to fix this @kontrollanten?

nathanbuchar commented 4 years ago

Closing this as it pertains to an older version of Electron Settings. A new major release (v4) of Electron Settings was just released! Electron Settings v4 does have support to define a custom electron instance via configure().