feat: promisify debugger.sendCommand() (#16861)

* remove duplicate entry for desktopCapturer.getSources

* feat: promisify debugger.sendCommand
This commit is contained in:
Milan Burda 2019-02-13 18:23:53 +01:00 committed by John Kleinschmidt
parent ee4c9aa3d0
commit 1f458eb177
7 changed files with 101 additions and 47 deletions

View file

@ -2,6 +2,7 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const http = require('http')
const path = require('path')
const { emittedOnce } = require('./events-helpers')
const { closeWindow } = require('./window-helpers')
const { BrowserWindow } = require('electron').remote
@ -102,7 +103,21 @@ describe('debugger module', () => {
}
})
it('returns response', done => {
it('returns response', async () => {
w.webContents.loadURL('about:blank')
w.webContents.debugger.attach()
const params = { 'expression': '4+2' }
const res = await w.webContents.debugger.sendCommand('Runtime.evaluate', params)
expect(res.wasThrown).to.be.undefined()
expect(res.result.value).to.equal(6)
w.webContents.debugger.detach()
})
// TODO(miniak): remove when promisification is complete
it('returns response (callback)', done => {
w.webContents.loadURL('about:blank')
try {
w.webContents.debugger.attach()
@ -123,7 +138,24 @@ describe('debugger module', () => {
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
})
it('returns response when devtools is opened', done => {
it('returns response when devtools is opened', async () => {
w.webContents.loadURL('about:blank')
w.webContents.debugger.attach()
w.webContents.openDevTools()
await emittedOnce(w.webContents, 'devtools-opened')
const params = { 'expression': '4+2' }
const res = await w.webContents.debugger.sendCommand('Runtime.evaluate', params)
expect(res.wasThrown).to.be.undefined()
expect(res.result.value).to.equal(6)
w.webContents.debugger.detach()
})
// TODO(miniak): remove when promisification is complete
it('returns response when devtools is opened (callback)', done => {
w.webContents.loadURL('about:blank')
try {
w.webContents.debugger.attach()
@ -169,7 +201,18 @@ describe('debugger module', () => {
w.webContents.debugger.sendCommand('Console.enable')
})
it('returns error message when command fails', done => {
it('returns error message when command fails', async () => {
w.webContents.loadURL('about:blank')
w.webContents.debugger.attach()
const promise = w.webContents.debugger.sendCommand('Test')
await expect(promise).to.be.eventually.rejectedWith(Error, "'Test' wasn't found")
w.webContents.debugger.detach()
})
// TODO(miniak): remove when promisification is complete
it('returns error message when command fails (callback)', done => {
w.webContents.loadURL('about:blank')
try {
w.webContents.debugger.attach()
@ -177,9 +220,8 @@ describe('debugger module', () => {
done(`unexpected error : ${err}`)
}
w.webContents.debugger.sendCommand('Test', err => {
expect(err).to.not.be.null()
expect(err.message).to.equal("'Test' wasn't found")
w.webContents.debugger.sendCommand('Test', (err, res) => {
expect(err).to.be.an.instanceOf(Error).with.property('message', "'Test' wasn't found")
w.webContents.debugger.detach()
done()
})