update crash reporter spec

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

View file

@ -11,46 +11,42 @@ const {closeWindow} = require('./window-helpers')
const {remote} = require('electron') const {remote} = require('electron')
const {app, BrowserWindow, crashReporter} = remote.require('electron') const {app, BrowserWindow, crashReporter} = remote.require('electron')
describe('crashReporter module', function () { describe('crashReporter module', () => {
if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) { if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) return
return
}
var originalTempDirectory = null let originalTempDirectory = null
var tempDirectory = null let tempDirectory = null
before(function () { before(() => {
tempDirectory = temp.mkdirSync('electronCrashReporterSpec-') tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
originalTempDirectory = app.getPath('temp') originalTempDirectory = app.getPath('temp')
app.setPath('temp', tempDirectory) app.setPath('temp', tempDirectory)
}) })
after(function () { after(() => {
app.setPath('temp', originalTempDirectory) app.setPath('temp', originalTempDirectory)
}) })
var fixtures = path.resolve(__dirname, 'fixtures') const fixtures = path.resolve(__dirname, 'fixtures')
const generateSpecs = (description, browserWindowOpts) => { const generateSpecs = (description, browserWindowOpts) => {
describe(description, function () { describe(description, () => {
var w = null let w = null
var stopServer = null let stopServer = null
beforeEach(function () { beforeEach(() => {
stopServer = null stopServer = null
w = new BrowserWindow(Object.assign({ w = new BrowserWindow(Object.assign({
show: false show: false
}, browserWindowOpts)) }, browserWindowOpts))
}) })
afterEach(function () { afterEach(() => closeWindow(w).then(() => { w = null }))
return closeWindow(w).then(function () { w = null })
})
afterEach(function () { afterEach(() => {
stopCrashService() stopCrashService()
}) })
afterEach(function (done) { afterEach((done) => {
if (stopServer != null) { if (stopServer != null) {
stopServer(done) stopServer(done)
} else { } else {
@ -123,12 +119,8 @@ describe('crashReporter module', function () {
crashReporter.setUploadToServer(false) crashReporter.setUploadToServer(false)
} }
const testDone = (uploaded) => { const testDone = (uploaded) => {
if (uploaded) { if (uploaded) return done(new Error('Uploaded crash report'))
return done(new Error('Uploaded crash report')) if (process.platform === 'darwin') crashReporter.setUploadToServer(true)
}
if (process.platform === 'darwin') {
crashReporter.setUploadToServer(true)
}
assert(fs.existsSync(dumpFile)) assert(fs.existsSync(dumpFile))
done() done()
} }
@ -136,13 +128,10 @@ describe('crashReporter module', function () {
let pollInterval let pollInterval
const pollDumpFile = () => { const pollDumpFile = () => {
fs.readdir(crashesDir, (err, files) => { fs.readdir(crashesDir, (err, files) => {
if (err) { if (err) return
return
}
const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file)) const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file))
if (!dumps.length) { if (!dumps.length) return
return
}
assert.equal(1, dumps.length) assert.equal(1, dumps.length)
dumpFile = path.join(crashesDir, dumps[0]) dumpFile = path.join(crashesDir, dumps[0])
clearInterval(pollInterval) clearInterval(pollInterval)
@ -210,22 +199,18 @@ describe('crashReporter module', function () {
} }
}) })
describe('.start(options)', function () { describe('.start(options)', () => {
it('requires that the companyName and submitURL options be specified', function () { it('requires that the companyName and submitURL options be specified', () => {
assert.throws(function () { assert.throws(() => {
crashReporter.start({ crashReporter.start({companyName: 'Missing submitURL'})
companyName: 'Missing submitURL'
})
}, /submitURL is a required option to crashReporter\.start/) }, /submitURL is a required option to crashReporter\.start/)
assert.throws(function () { assert.throws(() => {
crashReporter.start({ crashReporter.start({submitURL: 'Missing companyName'})
submitURL: 'Missing companyName'
})
}, /companyName is a required option to crashReporter\.start/) }, /companyName is a required option to crashReporter\.start/)
}) })
it('can be called multiple times', function () { it('can be called multiple times', () => {
assert.doesNotThrow(function () { assert.doesNotThrow(() => {
crashReporter.start({ crashReporter.start({
companyName: 'Umbrella Corporation', companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1/crashes' submitURL: 'http://127.0.0.1/crashes'
@ -239,12 +224,12 @@ describe('crashReporter module', function () {
}) })
}) })
describe('.get/setUploadToServer', function () { describe('.get/setUploadToServer', () => {
it('throws an error when called from the renderer process', function () { it('throws an error when called from the renderer process', () => {
assert.throws(() => require('electron').crashReporter.getUploadToServer()) assert.throws(() => require('electron').crashReporter.getUploadToServer())
}) })
it('can be read/set from the main process', function () { it('can be read/set from the main process', () => {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
crashReporter.start({ crashReporter.start({
companyName: 'Umbrella Corporation', companyName: 'Umbrella Corporation',
@ -279,9 +264,9 @@ const waitForCrashReport = () => {
} }
const startServer = ({callback, processType, done}) => { const startServer = ({callback, processType, done}) => {
var called = false let called = false
var server = http.createServer((req, res) => { let server = http.createServer((req, res) => {
var form = new multiparty.Form() const form = new multiparty.Form()
form.parse(req, (error, fields) => { form.parse(req, (error, fields) => {
if (error) throw error if (error) throw error
if (called) return if (called) return
@ -335,7 +320,7 @@ const startServer = ({callback, processType, done}) => {
for (const connection of activeConnections) { for (const connection of activeConnections) {
connection.destroy() connection.destroy()
} }
server.close(function () { server.close(() => {
done() done()
}) })
} }