Add spec for exit code on event

This commit is contained in:
Kevin Sawicki 2015-12-07 17:05:08 -08:00
parent 63c0095efb
commit aa82eddca8
3 changed files with 32 additions and 0 deletions

View file

@ -1,4 +1,6 @@
assert = require 'assert'
ChildProcess = require 'child_process'
path = require 'path'
{remote} = require 'electron'
{app, BrowserWindow} = remote.require 'electron'
@ -29,6 +31,23 @@ describe 'app module', ->
it 'should not be empty', ->
assert.notEqual app.getLocale(), ''
describe 'app.exit(exitCode)', ->
appProcess = null
afterEach ->
appProcess?.kill()
it 'emits a process exit event with the code', (done) ->
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
electronPath = remote.getGlobal('process').execPath
appProcess = ChildProcess.spawn(electronPath, [appPath])
output = ''
appProcess.stdout.on 'data', (data) -> output += data
appProcess.on 'close', (code) ->
assert.notEqual output.indexOf('Exit event with code: 123'), -1
assert.equal code, 123
done()
describe 'BrowserWindow events', ->
w = null
afterEach ->

9
spec/fixtures/api/quit-app/main.js vendored Normal file
View file

@ -0,0 +1,9 @@
var app = require('electron').app
app.on('ready', function () {
app.exit(123)
})
process.on('exit', function (code) {
console.log('Exit event with code: ' + code)
})

View file

@ -0,0 +1,4 @@
{
"name": "quit-app",
"main": "main.js"
}