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:
commit
e62349cffb
2 changed files with 17 additions and 1 deletions
|
@ -65,6 +65,12 @@ class CrashReporter {
|
||||||
|
|
||||||
getLastCrashReport () {
|
getLastCrashReport () {
|
||||||
const reports = this.getUploadedReports()
|
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
|
return (reports.length > 0) ? reports[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -259,8 +259,18 @@ describe('crashReporter module', () => {
|
||||||
describe('getLastCrashReport', () => {
|
describe('getLastCrashReport', () => {
|
||||||
it('correctly returns the most recent report', () => {
|
it('correctly returns the most recent report', () => {
|
||||||
const reports = crashReporter.getUploadedReports()
|
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 != null)
|
||||||
|
assert(lastReport.date.toString() === newestReport.report.date.toString())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue