add new tests

This commit is contained in:
Shelley Vohr 2017-10-30 22:51:22 -04:00
parent c9926bed9f
commit 603060f051
No known key found for this signature in database
GPG key ID: F13993A75599653C
2 changed files with 107 additions and 45 deletions

View file

@ -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)
}