]> khamidou — GitHub mirrors - electron.git/commitdiff
Add spec for exit code on event
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 8 Dec 2015 01:05:08 +0000 (17:05 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Wed, 9 Dec 2015 22:40:53 +0000 (14:40 -0800)
spec/api-app-spec.coffee
spec/fixtures/api/quit-app/main.js [new file with mode: 0644]
spec/fixtures/api/quit-app/package.json [new file with mode: 0644]

index 490727488d99c4596a1abe0441d0db3ab855ffa9..adb64d363eb1b300abeaa7c070730b4752f026c3 100644 (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 ->
diff --git a/spec/fixtures/api/quit-app/main.js b/spec/fixtures/api/quit-app/main.js
new file mode 100644 (file)
index 0000000..4bdeb93
--- /dev/null
@@ -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 (file)
index 0000000..ea5bb16
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "name": "quit-app",
+  "main": "main.js"
+}