spec: Add test case for app.makeSingleInstance
This commit is contained in:
parent
b7119b5756
commit
b4075bed87
3 changed files with 40 additions and 0 deletions
|
@ -157,6 +157,28 @@ describe('app module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('app.makeSingleInstance', function () {
|
||||
it('prevents the second launch of app', function (done) {
|
||||
this.timeout(120000)
|
||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
||||
// First launch should exit with 0.
|
||||
let secondLaunched = false
|
||||
const first = ChildProcess.spawn(remote.process.execPath, [appPath])
|
||||
first.once('exit', (code) => {
|
||||
assert.ok(secondLaunched)
|
||||
assert.equal(code, 0)
|
||||
done()
|
||||
})
|
||||
// Second launch should exit with 1.
|
||||
const second = ChildProcess.spawn(remote.process.execPath, [appPath])
|
||||
second.once('exit', (code) => {
|
||||
assert.ok(!secondLaunched)
|
||||
assert.equal(code, 1)
|
||||
secondLaunched = true
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('app.relaunch', function () {
|
||||
let server = null
|
||||
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
|
||||
|
|
13
spec/fixtures/api/singleton/main.js
vendored
Normal file
13
spec/fixtures/api/singleton/main.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
const {app} = require('electron')
|
||||
|
||||
process.on('uncaughtException', () => {
|
||||
app.exit(2)
|
||||
})
|
||||
|
||||
const shouldExit = app.makeSingleInstance(() => {
|
||||
process.nextTick(() => app.exit(0))
|
||||
})
|
||||
|
||||
if (shouldExit) {
|
||||
app.exit(1)
|
||||
}
|
5
spec/fixtures/api/singleton/package.json
vendored
Normal file
5
spec/fixtures/api/singleton/package.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "electron-app-singleton",
|
||||
"main": "main.js"
|
||||
}
|
||||
|
Loading…
Reference in a new issue