add new tests
This commit is contained in:
parent
c9926bed9f
commit
603060f051
2 changed files with 107 additions and 45 deletions
|
@ -9,36 +9,25 @@ const binding = process.atomBinding('crash_reporter')
|
|||
|
||||
class CrashReporter {
|
||||
start (options) {
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
if (options == null) options = {}
|
||||
this.productName = options.productName != null ? options.productName : app.getName()
|
||||
let {companyName, extra, ignoreSystemCrashHandler, submitURL, uploadToServer} = options
|
||||
|
||||
if (uploadToServer == null) {
|
||||
// TODO: Remove deprecated autoSubmit property in 2.0
|
||||
uploadToServer = options.autoSubmit
|
||||
}
|
||||
let {
|
||||
companyName,
|
||||
extra,
|
||||
ignoreSystemCrashHandler,
|
||||
submitURL,
|
||||
uploadToServer
|
||||
} = options
|
||||
|
||||
if (uploadToServer == null) {
|
||||
uploadToServer = true
|
||||
}
|
||||
if (uploadToServer == null) uploadToServer = options.autoSubmit || true
|
||||
if (ignoreSystemCrashHandler == null) ignoreSystemCrashHandler = false
|
||||
if (extra == null) extra = {}
|
||||
|
||||
if (extra._productName == null) extra._productName = this.getProductName()
|
||||
if (extra._companyName == null) extra._companyName = companyName
|
||||
if (extra._version == null) extra._version = app.getVersion()
|
||||
|
||||
if (ignoreSystemCrashHandler == null) {
|
||||
ignoreSystemCrashHandler = false
|
||||
}
|
||||
if (extra == null) {
|
||||
extra = {}
|
||||
}
|
||||
if (extra._productName == null) {
|
||||
extra._productName = this.getProductName()
|
||||
}
|
||||
if (extra._companyName == null) {
|
||||
extra._companyName = companyName
|
||||
}
|
||||
if (extra._version == null) {
|
||||
extra._version = app.getVersion()
|
||||
}
|
||||
if (companyName == null) {
|
||||
throw new Error('companyName is a required option to crashReporter.start')
|
||||
}
|
||||
|
@ -47,15 +36,14 @@ class CrashReporter {
|
|||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
const env = { ELECTRON_INTERNAL_CRASH_SERVICE: 1 }
|
||||
const args = [
|
||||
'--reporter-url=' + submitURL,
|
||||
'--application-name=' + this.getProductName(),
|
||||
'--crashes-directory=' + this.getCrashesDirectory(),
|
||||
'--v=1'
|
||||
]
|
||||
const env = {
|
||||
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
||||
}
|
||||
|
||||
this._crashServiceProcess = spawn(process.execPath, args, {
|
||||
env: env,
|
||||
detached: true
|
||||
|
@ -67,11 +55,7 @@ class CrashReporter {
|
|||
|
||||
getLastCrashReport () {
|
||||
const reports = this.getUploadedReports()
|
||||
if (reports.length > 0) {
|
||||
return reports[0]
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return (reports.length > 0) ? reports[0] : null
|
||||
}
|
||||
|
||||
getUploadedReports () {
|
||||
|
@ -79,7 +63,7 @@ class CrashReporter {
|
|||
}
|
||||
|
||||
getCrashesDirectory () {
|
||||
const crashesDir = this.getProductName() + ' Crashes'
|
||||
const crashesDir = `${this.getProductName()} Crashes`
|
||||
return path.join(this.getTempDirectory(), crashesDir)
|
||||
}
|
||||
|
||||
|
@ -95,7 +79,6 @@ class CrashReporter {
|
|||
try {
|
||||
this.tempDirectory = app.getPath('temp')
|
||||
} catch (error) {
|
||||
// app.getPath may throw so fallback to OS temp directory
|
||||
this.tempDirectory = os.tmpdir()
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +101,10 @@ class CrashReporter {
|
|||
}
|
||||
}
|
||||
|
||||
removeExtraParameter (key) {
|
||||
binding.setExtraParameter(key)
|
||||
}
|
||||
|
||||
setExtraParameter (key, value) {
|
||||
binding.setExtraParameter(key, value)
|
||||
}
|
||||
|
|
|
@ -35,9 +35,7 @@ describe('crashReporter module', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
stopServer = null
|
||||
w = new BrowserWindow(Object.assign({
|
||||
show: false
|
||||
}, browserWindowOpts))
|
||||
w = new BrowserWindow(Object.assign({ show: false }, browserWindowOpts))
|
||||
})
|
||||
|
||||
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||
|
@ -199,7 +197,22 @@ describe('crashReporter module', () => {
|
|||
}
|
||||
})
|
||||
|
||||
describe('.start(options)', () => {
|
||||
// complete
|
||||
describe('getProductName', () => {
|
||||
it('returns the product name if one is specified', () => {
|
||||
const name = crashReporter.getProductName()
|
||||
assert.equal(name, 'Zombies')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTempDirectory', () => {
|
||||
it('returns temp directory for app if one is specified', () => {
|
||||
const tempDir = crashReporter.getTempDirectory()
|
||||
assert.equal(tempDir, app.getPath('temp'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('start(options)', () => {
|
||||
it('requires that the companyName and submitURL options be specified', () => {
|
||||
assert.throws(() => {
|
||||
crashReporter.start({companyName: 'Missing submitURL'})
|
||||
|
@ -208,7 +221,6 @@ describe('crashReporter module', () => {
|
|||
crashReporter.start({submitURL: 'Missing companyName'})
|
||||
}, /companyName is a required option to crashReporter\.start/)
|
||||
})
|
||||
|
||||
it('can be called multiple times', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
crashReporter.start({
|
||||
|
@ -223,13 +235,37 @@ describe('crashReporter module', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
// complete
|
||||
describe('getCrashesDirectory', () => {
|
||||
it('correctly returns the directory', () => {
|
||||
const crashesDir = crashReporter.getCrashesDirectory()
|
||||
const dir = `${app.getPath('temp')}Zombies Crashes`
|
||||
assert.equal(crashesDir, dir)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.get/setUploadToServer', () => {
|
||||
describe('getUploadedReports', () => {
|
||||
it('returns an array of reports', () => {
|
||||
const reports = crashReporter.getUploadedReports()
|
||||
assert(typeof reports === 'object')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getLastCrashReport', () => {
|
||||
it('correctly returns the most recent report', () => {
|
||||
// TODO(codebytere): figure this out
|
||||
const reports = crashReporter.getUploadedReports()
|
||||
const lastReport = reports[0]
|
||||
assert(lastReport != null)
|
||||
})
|
||||
})
|
||||
|
||||
// complete
|
||||
describe('getUploadToServer()', () => {
|
||||
it('throws an error when called from the renderer process', () => {
|
||||
assert.throws(() => require('electron').crashReporter.getUploadToServer())
|
||||
})
|
||||
|
||||
it('can be read/set from the main process', () => {
|
||||
it('returns true when uploadToServer is true', () => {
|
||||
if (process.platform === 'darwin') {
|
||||
crashReporter.start({
|
||||
companyName: 'Umbrella Corporation',
|
||||
|
@ -237,13 +273,52 @@ describe('crashReporter module', () => {
|
|||
uploadToServer: true
|
||||
})
|
||||
assert.equal(crashReporter.getUploadToServer(), true)
|
||||
}
|
||||
})
|
||||
it('returns false when uploadToServer is false', () => {
|
||||
if (process.platform === 'darwin') {
|
||||
crashReporter.start({
|
||||
companyName: 'Umbrella Corporation',
|
||||
submitURL: 'http://127.0.0.1/crashes',
|
||||
uploadToServer: false
|
||||
})
|
||||
assert.equal(crashReporter.getUploadToServer(), false)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// complete
|
||||
describe('setUploadToServer(uploadToServer)', () => {
|
||||
it('throws an error when called from the renderer process', () => {
|
||||
assert.throws(() => require('electron').crashReporter.setUploadToServer('arg'))
|
||||
})
|
||||
it('sets uploadToServer false when called with false', () => {
|
||||
if (process.platform === 'darwin') {
|
||||
crashReporter.start({
|
||||
companyName: 'Umbrella Corporation',
|
||||
submitURL: 'http://127.0.0.1/crashes',
|
||||
uploadToServer: true
|
||||
})
|
||||
crashReporter.setUploadToServer(false)
|
||||
assert.equal(crashReporter.getUploadToServer(), false)
|
||||
} else {
|
||||
}
|
||||
})
|
||||
it('sets uploadToServer true when called with true', () => {
|
||||
if (process.platform === 'darwin') {
|
||||
crashReporter.start({
|
||||
companyName: 'Umbrella Corporation',
|
||||
submitURL: 'http://127.0.0.1/crashes',
|
||||
uploadToServer: false
|
||||
})
|
||||
crashReporter.setUploadToServer(true)
|
||||
assert.equal(crashReporter.getUploadToServer(), true)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('setExtraParameter', () => {
|
||||
//
|
||||
})
|
||||
})
|
||||
|
||||
const waitForCrashReport = () => {
|
||||
|
|
Loading…
Reference in a new issue