Last active
March 4, 2016 14:23
-
-
Save ueokande/ffbcdb97992c74a7caa4 to your computer and use it in GitHub Desktop.
ElectronのRendererプロセスのテスト ref: http://qiita.com/ueokande/items/ea5b985f0ebe0e84f29d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Electron renderer process', function() { | |
describe('document object', function() { | |
it('is an Document object', function() { | |
expect(window.document).to.be.an.instanceof(Document); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── package.json | |
├── test | |
│ └── electron_test.js | |
└── test-runner | |
├── index.html | |
├── index.js | |
└── main.js | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install electron-prebuilt mocha chai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./node_modules/.bin/electron test-runner/main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="./index.js"></script> | |
</head> | |
<body></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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