update debugger spec

This commit is contained in:
Shelley Vohr 2017-10-26 20:32:04 -04:00
parent d4350079c9
commit 83a290a411
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -4,11 +4,11 @@ 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
describe('debugger module', function () { describe.only('debugger module', () => {
var fixtures = path.resolve(__dirname, 'fixtures') const fixtures = path.resolve(__dirname, 'fixtures')
var w = null let w = null
beforeEach(function () { beforeEach(() => {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
width: 400, width: 400,
@ -16,13 +16,11 @@ describe('debugger module', function () {
}) })
}) })
afterEach(function () { afterEach(() => closeWindow(w).then(() => { w = null }))
return closeWindow(w).then(function () { w = null })
})
describe('debugger.attach', function () { describe('debugger.attach', () => {
it('fails when devtools is already open', function (done) { it('fails when devtools is already open', (done) => {
w.webContents.on('did-finish-load', function () { w.webContents.on('did-finish-load', () => {
w.webContents.openDevTools() w.webContents.openDevTools()
try { try {
w.webContents.debugger.attach() w.webContents.debugger.attach()
@ -31,10 +29,10 @@ describe('debugger module', function () {
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', function (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) {
@ -43,20 +41,20 @@ describe('debugger module', function () {
} }
}) })
it('attaches when no protocol version is specified', function (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()) assert(w.webContents.debugger.isAttached())
done() done()
}) })
}) })
describe('debugger.detach', function () { describe('debugger.detach', () => {
it('fires detach event', function (done) { it('fires detach event', (done) => {
w.webContents.debugger.on('detach', function (e, reason) { w.webContents.debugger.on('detach', (e, reason) => {
assert.equal(reason, 'target closed') assert.equal(reason, 'target closed')
assert(!w.webContents.debugger.isAttached()) assert(!w.webContents.debugger.isAttached())
done() done()
@ -64,23 +62,23 @@ describe('debugger module', function () {
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.detach() w.webContents.debugger.detach()
}) })
}) })
describe('debugger.sendCommand', function () { describe('debugger.sendCommand', () => {
let server let server
afterEach(function () { afterEach(() => {
if (server != null) { if (server != null) {
server.close() server.close()
server = null server = null
} }
}) })
it('retuns response', function (done) { it('retuns response', (done) => {
w.webContents.loadURL('about:blank') w.webContents.loadURL('about:blank')
try { try {
w.webContents.debugger.attach() w.webContents.debugger.attach()
@ -100,9 +98,9 @@ describe('debugger module', function () {
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback) w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
}) })
it('fires message event', function (done) { it('fires message event', (done) => {
var 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 {
@ -110,7 +108,7 @@ describe('debugger module', function () {
} catch (err) { } catch (err) {
done('unexpected error : ' + err) done('unexpected error : ' + err)
} }
w.webContents.debugger.on('message', function (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') assert.equal(params.message.level, 'log')
assert.equal(params.message.url, url) assert.equal(params.message.url, url)
@ -122,25 +120,25 @@ describe('debugger module', function () {
w.webContents.debugger.sendCommand('Console.enable') w.webContents.debugger.sendCommand('Console.enable')
}) })
it('returns error message when command fails', function (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', function (err) { w.webContents.debugger.sendCommand('Test', (err) => {
assert.equal(err.message, "'Test' wasn't found") assert.equal(err.message, "'Test' wasn't found")
w.webContents.debugger.detach() w.webContents.debugger.detach()
done() done()
}) })
}) })
it('handles invalid unicode characters in message', function (done) { it('handles invalid unicode characters in message', (done) => {
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', (event, method, params) => { w.webContents.debugger.on('message', (event, method, params) => {