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:
Samuel Attard 2018-03-14 10:36:27 +09:00 committed by GitHub
commit e62349cffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

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

View file

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