Skip to content

Commit

Permalink
spec: add tests to ensure clean shutdown with connected inspector agent
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Apr 29, 2019
1 parent 595c6cb commit 9fd5e80
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/fixtures/module/delay-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { app } = require('electron')

process.on('message', () => app.quit())
44 changes: 42 additions & 2 deletions spec/node-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const os = require('os')
const { ipcRenderer, remote } = require('electron')
const features = process.electronBinding('features')

const { emittedOnce } = require('./events-helpers')

const isCI = remote.getGlobal('isCi')
chai.use(dirtyChai)

Expand Down Expand Up @@ -231,15 +233,22 @@ describe('node feature', () => {

describe('inspector', () => {
let child = null
let exitPromise = null

beforeEach(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})

afterEach(() => {
if (child !== null) child.kill()
afterEach(async () => {
if (child && exitPromise) {
const [code, signal] = await exitPromise
expect(signal).to.equal(null)
expect(code).to.equal(0)
} else if (child) {
child.kill()
}
})

it('supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
Expand Down Expand Up @@ -275,6 +284,7 @@ describe('node feature', () => {
ELECTRON_RUN_AS_NODE: true
}
})
exitPromise = emittedOnce(child, 'exit')

let output = ''
function cleanup () {
Expand All @@ -299,6 +309,7 @@ describe('node feature', () => {

it('does not start the v8 inspector when --inspect is after a -- argument', (done) => {
child = ChildProcess.spawn(remote.process.execPath, [path.join(__dirname, 'fixtures', 'module', 'noop.js'), '--', '--inspect'])
exitPromise = emittedOnce(child, 'exit')

let output = ''
function dataListener (data) {
Expand All @@ -315,13 +326,42 @@ describe('node feature', () => {
})
})

it('does does not crash when quitting with the inspector connected', function (done) {
this.timeout(240000)
child = ChildProcess.spawn(remote.process.execPath, [path.join(__dirname, 'fixtures', 'module', 'delay-exit'), '--inspect=0'], {
stdio: ['ipc']
})
exitPromise = emittedOnce(child, 'exit')

let output = ''
function dataListener (data) {
output += data

if (output.trim().startsWith('Debugger listening on ws://') && output.endsWith('\n')) {
const socketMatch = output.trim().match(/(ws:\/\/.+:[0-9]+\/.+?)\n/gm)
if (socketMatch && socketMatch[0]) {
child.stderr.removeListener('data', dataListener)
child.stdout.removeListener('data', dataListener)
const connection = new WebSocket(socketMatch[0])
connection.onopen = () => {
child.send('plz-quit')
done()
}
}
}
}
child.stderr.on('data', dataListener)
child.stdout.on('data', dataListener)
})

it('supports js binding', (done) => {
child = ChildProcess.spawn(process.execPath, ['--inspect', path.join(__dirname, 'fixtures', 'module', 'inspector-binding.js')], {
env: {
ELECTRON_RUN_AS_NODE: true
},
stdio: ['ipc']
})
exitPromise = emittedOnce(child, 'exit')

child.on('message', ({ cmd, debuggerEnabled, success }) => {
if (cmd === 'assert') {
Expand Down

0 comments on commit 9fd5e80

Please sign in to comment.