Skip to content

Instantly share code, notes, and snippets.

@ueokande
Last active March 4, 2016 14:23
Show Gist options
  • Save ueokande/ffbcdb97992c74a7caa4 to your computer and use it in GitHub Desktop.
Save ueokande/ffbcdb97992c74a7caa4 to your computer and use it in GitHub Desktop.
ElectronのRendererプロセスのテスト ref: http://qiita.com/ueokande/items/ea5b985f0ebe0e84f29d
describe('Electron renderer process', function() {
describe('document object', function() {
it('is an Document object', function() {
expect(window.document).to.be.an.instanceof(Document);
});
});
});
├── package.json
├── test
│   └── electron_test.js
└── test-runner
├── index.html
├── index.js
└── main.js
npm install electron-prebuilt mocha chai
./node_modules/.bin/electron test-runner/main.js
<!doctype html>
<html>
<head>
<script src="./index.js"></script>
</head>
<body></body>
</html>
var remote = require('remote');
var remoteConsole = remote.require('console');
var ipc = require("electron").ipcRenderer;
var mocha = require('mocha');
var expect = require('chai').expect;
Error.stackTraceLimit = Infinity;
console.log = function () {
remoteConsole.log.apply(remoteConsole, arguments);
};
console.warn = function () {
remoteConsole.warn.apply(remoteConsole, arguments);
};
console.dir = function () {
remoteConsole.dir.apply(remoteConsole, arguments);
};
window.onerror = function (message, filename, lineno, colno, err) {
ipc.send('mocha-error', {
message: message,
filename: filename,
err: err,
stack: err.stack
})
};
var runner = new mocha();
runner.reporter('nyan');
runner.ui('bdd');
runner.files = mocha.utils.lookupFiles('test', ['js'], true);
runner.run(function (failureCount) {
ipc.send('mocha-done', failureCount);
});
var app = require('app');
var ipc = require('electron').ipcMain;
var BrowserWindow = require('browser-window');
var path = require('path');
var util = require('util');
process.on('uncaughtException', function (err) {
console.error(err);
console.error(err.stack);
process.exit(1);
});
app.on('ready', function () {
var win = new BrowserWindow({ height: 700, width: 1200 });
win.loadURL('file://' + __dirname + '/index.html');
ipc.on('mocha-done', function (event, failureCount) {
process.exit(failureCount > 0 ? 1 : 0);
});
ipc.on('mocha-error', function (event, data) {
process.stderr.write(util.format('\nError encountered in %s: %s\n%s',
path.relative(process.cwd(), data.filename),
data.message,
data.stack));
process.exit(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment