From aa82eddca8500a6d3fae9b7dbbcc6bfcd6895ddc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Dec 2015 17:05:08 -0800 Subject: [PATCH] Add spec for exit code on event --- spec/api-app-spec.coffee | 19 +++++++++++++++++++ spec/fixtures/api/quit-app/main.js | 9 +++++++++ spec/fixtures/api/quit-app/package.json | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 spec/fixtures/api/quit-app/main.js create mode 100644 spec/fixtures/api/quit-app/package.json diff --git a/spec/api-app-spec.coffee b/spec/api-app-spec.coffee index 490727488d9..adb64d363eb 100644 --- a/spec/api-app-spec.coffee +++ b/spec/api-app-spec.coffee @@ -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 -> diff --git a/spec/fixtures/api/quit-app/main.js b/spec/fixtures/api/quit-app/main.js new file mode 100644 index 00000000000..4bdeb93a5e3 --- /dev/null +++ b/spec/fixtures/api/quit-app/main.js @@ -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) +}) diff --git a/spec/fixtures/api/quit-app/package.json b/spec/fixtures/api/quit-app/package.json new file mode 100644 index 00000000000..ea5bb1643b9 --- /dev/null +++ b/spec/fixtures/api/quit-app/package.json @@ -0,0 +1,4 @@ +{ + "name": "quit-app", + "main": "main.js" +}