gewl gewl - 7 days ago 6
Javascript Question

Dummying an Electron session for Mocha/Chai tests

I've built a single-page app off of chentsulin's electron/react boilerplate, which comes with the following node script for testing:

"test": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --compilers js:babel-register --recursive --require ./test/setup.js test/**/*.spec.js"


The boilerplate comes with a number of generic tests that are runnable at the outset (I confirmed this myself). It also comes with a number of webpack configs to suit different environments.

The app is fairly far along now, and is using electron-json-storage to handle local storage. I just went back to writing tests, and when I run the
test
node script (with or without --renderer) I get the following:

[dirpath]/node_modules/electron-json-storage/lib/utils.js:30
const app = electron.app || electron.remote.app;
^

TypeError: Cannot read property 'app' of undefined


I've tried using webpack.IgnorePlugin to ignore electron-json-storage, but that doesn't do anything. My guess is that electron-json-storage is trying to refer to an instantiated electron session that doesn't exist. What's the easiest way of dummying this up?

Answer

The problem was that I was using mocha (which came as part of the Electron-React boilerplate). Installing electron-mocha and changing the test script in the package.json resolved this problem immediately.

Comments