spec: convert debugger spec to expect
This commit is contained in:
Родитель
a0d252870c
Коммит
e023035393
|
@ -1,9 +1,14 @@
|
||||||
|
const chai = require('chai')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
|
const dirtyChai = require('dirty-chai')
|
||||||
const http = require('http')
|
const http = require('http')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const {closeWindow} = require('./window-helpers')
|
const {closeWindow} = require('./window-helpers')
|
||||||
const BrowserWindow = require('electron').remote.BrowserWindow
|
const BrowserWindow = require('electron').remote.BrowserWindow
|
||||||
|
|
||||||
|
const {expect} = chai
|
||||||
|
chai.use(dirtyChai)
|
||||||
|
|
||||||
describe('debugger module', () => {
|
describe('debugger module', () => {
|
||||||
const fixtures = path.resolve(__dirname, 'fixtures')
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
let w = null
|
let w = null
|
||||||
|
@ -19,35 +24,35 @@ describe('debugger module', () => {
|
||||||
afterEach(() => closeWindow(w).then(() => { w = null }))
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
|
|
||||||
describe('debugger.attach', () => {
|
describe('debugger.attach', () => {
|
||||||
it('fails when devtools is already open', (done) => {
|
it('fails when devtools is already open', done => {
|
||||||
w.webContents.on('did-finish-load', () => {
|
w.webContents.on('did-finish-load', () => {
|
||||||
w.webContents.openDevTools()
|
w.webContents.openDevTools()
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(w.webContents.debugger.isAttached())
|
expect(w.webContents.debugger.isAttached()).to.be.true()
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.webContents.loadURL(`file://${path.join(fixtures, 'pages', 'a.html')}`)
|
w.webContents.loadURL(`file://${path.join(fixtures, 'pages', 'a.html')}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fails when protocol version is not supported', (done) => {
|
it('fails when protocol version is not supported', done => {
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach('2.0')
|
w.webContents.debugger.attach('2.0')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(!w.webContents.debugger.isAttached())
|
expect(w.webContents.debugger.isAttached()).to.be.false()
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('attaches when no protocol version is specified', (done) => {
|
it('attaches when no protocol version is specified', done => {
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
done(`unexpected error : ${err}`)
|
done(`unexpected error : ${err}`)
|
||||||
}
|
}
|
||||||
assert(w.webContents.debugger.isAttached())
|
expect(w.webContents.debugger.isAttached()).to.be.true()
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -55,10 +60,11 @@ describe('debugger module', () => {
|
||||||
describe('debugger.detach', () => {
|
describe('debugger.detach', () => {
|
||||||
it('fires detach event', (done) => {
|
it('fires detach event', (done) => {
|
||||||
w.webContents.debugger.on('detach', (e, reason) => {
|
w.webContents.debugger.on('detach', (e, reason) => {
|
||||||
assert.equal(reason, 'target closed')
|
expect(reason).to.equal('target closed')
|
||||||
assert(!w.webContents.debugger.isAttached())
|
expect(w.webContents.debugger.isAttached()).to.be.false()
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -78,41 +84,45 @@ describe('debugger module', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('retuns response', (done) => {
|
it('returns response', done => {
|
||||||
w.webContents.loadURL('about:blank')
|
w.webContents.loadURL('about:blank')
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return done('unexpected error : ' + err)
|
return done(`unexpected error : ${err}`)
|
||||||
}
|
}
|
||||||
var callback = function (err, res) {
|
|
||||||
assert(!err.message)
|
const callback = (err, res) => {
|
||||||
assert(!res.wasThrown)
|
expect(err.message).to.not.exist()
|
||||||
assert.equal(res.result.value, 6)
|
expect(res.wasThrown).to.be.undefined()
|
||||||
|
expect(res.result.value).to.equal(6)
|
||||||
|
|
||||||
w.webContents.debugger.detach()
|
w.webContents.debugger.detach()
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
const params = {
|
|
||||||
'expression': '4+2'
|
const params = {'expression': '4+2'}
|
||||||
}
|
|
||||||
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
|
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fires message event', (done) => {
|
it('fires message event', done => {
|
||||||
const url = process.platform !== 'win32'
|
const url = process.platform !== 'win32'
|
||||||
? `file://${path.join(fixtures, 'pages', 'a.html')}`
|
? `file://${path.join(fixtures, 'pages', 'a.html')}`
|
||||||
: 'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')
|
: `file:///${path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')}`
|
||||||
w.webContents.loadURL(url)
|
w.webContents.loadURL(url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
done('unexpected error : ' + err)
|
done(`unexpected error : ${err}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.webContents.debugger.on('message', (e, method, params) => {
|
w.webContents.debugger.on('message', (e, method, params) => {
|
||||||
if (method === 'Console.messageAdded') {
|
if (method === 'Console.messageAdded') {
|
||||||
assert.equal(params.message.level, 'log')
|
expect(params.message.level).to.equal('log')
|
||||||
assert.equal(params.message.url, url)
|
expect(params.message.url).to.equal(url)
|
||||||
assert.equal(params.message.text, 'a')
|
expect(params.message.text).to.equal('a')
|
||||||
|
|
||||||
w.webContents.debugger.detach()
|
w.webContents.debugger.detach()
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -120,15 +130,16 @@ describe('debugger module', () => {
|
||||||
w.webContents.debugger.sendCommand('Console.enable')
|
w.webContents.debugger.sendCommand('Console.enable')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns error message when command fails', (done) => {
|
it('returns error message when command fails', done => {
|
||||||
w.webContents.loadURL('about:blank')
|
w.webContents.loadURL('about:blank')
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
done(`unexpected error : ${err}`)
|
done(`unexpected error : ${err}`)
|
||||||
}
|
}
|
||||||
w.webContents.debugger.sendCommand('Test', (err) => {
|
|
||||||
assert.equal(err.message, "'Test' wasn't found")
|
w.webContents.debugger.sendCommand('Test', err => {
|
||||||
|
expect(err.message).to.equal("'Test' wasn't found")
|
||||||
w.webContents.debugger.detach()
|
w.webContents.debugger.detach()
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -146,7 +157,7 @@ describe('debugger module', () => {
|
||||||
w.webContents.debugger.sendCommand('Network.getResponseBody', {
|
w.webContents.debugger.sendCommand('Network.getResponseBody', {
|
||||||
requestId: params.requestId
|
requestId: params.requestId
|
||||||
}, (_, data) => {
|
}, (_, data) => {
|
||||||
assert.equal(data.body, '\u0024')
|
expect(data.body).to.equal('\u0024')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -163,7 +174,7 @@ describe('debugger module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash for invalid unicode characters in message', (done) => {
|
it('does not crash for invalid unicode characters in message', done => {
|
||||||
try {
|
try {
|
||||||
w.webContents.debugger.attach()
|
w.webContents.debugger.attach()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче