New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spec: convert debugger spec to expect #13267
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
const assert = require('assert') | ||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const http = require('http') | ||
const path = require('path') | ||
const {closeWindow} = require('./window-helpers') | ||
const BrowserWindow = require('electron').remote.BrowserWindow | ||
|
||
const {expect} = chai | ||
chai.use(dirtyChai) | ||
|
||
describe('debugger module', () => { | ||
const fixtures = path.resolve(__dirname, 'fixtures') | ||
let w = null | ||
|
@@ -19,46 +23,47 @@ describe('debugger module', () => { | |
afterEach(() => closeWindow(w).then(() => { w = null })) | ||
|
||
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.openDevTools() | ||
try { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
assert(w.webContents.debugger.isAttached()) | ||
expect(w.webContents.debugger.isAttached()).to.be.true() | ||
done() | ||
} | ||
}) | ||
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 { | ||
w.webContents.debugger.attach('2.0') | ||
} catch (err) { | ||
assert(!w.webContents.debugger.isAttached()) | ||
expect(w.webContents.debugger.isAttached()).to.be.false() | ||
done() | ||
} | ||
}) | ||
|
||
it('attaches when no protocol version is specified', (done) => { | ||
it('attaches when no protocol version is specified', done => { | ||
try { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
done(`unexpected error : ${err}`) | ||
} | ||
assert(w.webContents.debugger.isAttached()) | ||
expect(w.webContents.debugger.isAttached()).to.be.true() | ||
done() | ||
}) | ||
}) | ||
|
||
describe('debugger.detach', () => { | ||
it('fires detach event', (done) => { | ||
w.webContents.debugger.on('detach', (e, reason) => { | ||
assert.equal(reason, 'target closed') | ||
assert(!w.webContents.debugger.isAttached()) | ||
expect(reason).to.equal('target closed') | ||
expect(w.webContents.debugger.isAttached()).to.be.false() | ||
done() | ||
}) | ||
|
||
try { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
|
@@ -78,57 +83,62 @@ describe('debugger module', () => { | |
} | ||
}) | ||
|
||
it('retuns response', (done) => { | ||
it('returns response', done => { | ||
w.webContents.loadURL('about:blank') | ||
try { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
return done('unexpected error : ' + err) | ||
return done(`unexpected error : ${err}`) | ||
} | ||
var callback = function (err, res) { | ||
assert(!err.message) | ||
assert(!res.wasThrown) | ||
assert.equal(res.result.value, 6) | ||
|
||
const callback = (err, res) => { | ||
expect(err.message).to.not.exist() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There shouldn't be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be undefined :) |
||
expect(res.wasThrown).to.be.undefined() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question as for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should also be undefined |
||
expect(res.result.value).to.equal(6) | ||
|
||
w.webContents.debugger.detach() | ||
done() | ||
} | ||
const params = { | ||
'expression': '4+2' | ||
} | ||
|
||
const params = {'expression': '4+2'} | ||
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback) | ||
}) | ||
|
||
it('fires message event', (done) => { | ||
it('fires message event', done => { | ||
const url = process.platform !== 'win32' | ||
? `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) | ||
|
||
try { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
done('unexpected error : ' + err) | ||
done(`unexpected error : ${err}`) | ||
} | ||
|
||
w.webContents.debugger.on('message', (e, method, params) => { | ||
if (method === 'Console.messageAdded') { | ||
assert.equal(params.message.level, 'log') | ||
assert.equal(params.message.url, url) | ||
assert.equal(params.message.text, 'a') | ||
expect(params.message.level).to.equal('log') | ||
expect(params.message.url).to.equal(url) | ||
expect(params.message.text).to.equal('a') | ||
|
||
w.webContents.debugger.detach() | ||
done() | ||
} | ||
}) | ||
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') | ||
try { | ||
w.webContents.debugger.attach() | ||
} catch (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() | ||
done() | ||
}) | ||
|
@@ -146,7 +156,7 @@ describe('debugger module', () => { | |
w.webContents.debugger.sendCommand('Network.getResponseBody', { | ||
requestId: params.requestId | ||
}, (_, data) => { | ||
assert.equal(data.body, '\u0024') | ||
expect(data.body).to.equal('\u0024') | ||
done() | ||
}) | ||
} | ||
|
@@ -163,7 +173,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 { | ||
w.webContents.debugger.attach() | ||
} catch (err) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍