test: move ipcMain spec (#19230)
This commit is contained in:
parent
3957a791b7
commit
8a57fe5466
1 changed files with 14 additions and 37 deletions
81
spec-main/api-ipc-main-spec.ts
Normal file
81
spec-main/api-ipc-main-spec.ts
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { expect } from 'chai'
|
||||
import * as path from 'path'
|
||||
import * as cp from 'child_process'
|
||||
import { closeAllWindows } from './window-helpers'
|
||||
import { emittedOnce } from './events-helpers'
|
||||
import { ipcMain, BrowserWindow } from 'electron'
|
||||
|
||||
describe('ipc main module', () => {
|
||||
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures')
|
||||
|
||||
afterEach(closeAllWindows)
|
||||
|
||||
describe('ipc.sendSync', () => {
|
||||
afterEach(() => { ipcMain.removeAllListeners('send-sync-message') })
|
||||
|
||||
it('does not crash when reply is not sent and browser is destroyed', (done) => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
ipcMain.once('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
done()
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'api', 'send-sync-message.html'))
|
||||
})
|
||||
|
||||
it('does not crash when reply is sent by multiple listeners', (done) => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
ipcMain.on('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
})
|
||||
ipcMain.on('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
done()
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'api', 'send-sync-message.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote objects registry', () => {
|
||||
it('does not dereference until the render view is deleted (regression)', (done) => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.once('error-message', (event, message) => {
|
||||
expect(message).to.match(/^Cannot call method 'getURL' on missing remote object/)
|
||||
done()
|
||||
})
|
||||
|
||||
w.loadFile(path.join(fixtures, 'api', 'render-view-deleted.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipcMain.on', () => {
|
||||
it('is not used for internals', async () => {
|
||||
const appPath = path.join(fixtures, 'api', 'ipc-main-listeners')
|
||||
const electronPath = process.execPath
|
||||
const appProcess = cp.spawn(electronPath, [appPath])
|
||||
|
||||
let output = ''
|
||||
appProcess.stdout.on('data', (data) => { output += data })
|
||||
|
||||
await emittedOnce(appProcess.stdout, 'end')
|
||||
|
||||
output = JSON.parse(output)
|
||||
expect(output).to.deep.equal(['error'])
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue