mirror of
https://github.com/electron/electron.git
synced 2026-01-27 16:28:23 -05:00
Merge pull request #12253 from felixrieseberg/fix-last-crash-report
fix: Ensure that `getLastCrashReport()` is actually the last crash report
This commit is contained in:
@@ -65,6 +65,12 @@ class CrashReporter {
|
||||
|
||||
getLastCrashReport () {
|
||||
const reports = this.getUploadedReports()
|
||||
.sort((a, b) => {
|
||||
const ats = (a && a.date) ? new Date(a.date).getTime() : 0
|
||||
const bts = (b && b.date) ? new Date(b.date).getTime() : 0
|
||||
return bts - ats
|
||||
})
|
||||
|
||||
return (reports.length > 0) ? reports[0] : null
|
||||
}
|
||||
|
||||
|
||||
@@ -259,8 +259,18 @@ describe('crashReporter module', () => {
|
||||
describe('getLastCrashReport', () => {
|
||||
it('correctly returns the most recent report', () => {
|
||||
const reports = crashReporter.getUploadedReports()
|
||||
const lastReport = reports[0]
|
||||
const lastReport = crashReporter.getLastCrashReport()
|
||||
|
||||
// Let's find the newest report
|
||||
const newestReport = reports.reduce((acc, cur) => {
|
||||
const timestamp = new Date(cur.date).getTime()
|
||||
return (timestamp > acc.timestamp)
|
||||
? { report: cur, timestamp: timestamp }
|
||||
: acc
|
||||
}, { timestamp: 0 })
|
||||
|
||||
assert(lastReport != null)
|
||||
assert(lastReport.date.toString() === newestReport.report.date.toString())
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user