diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 6dc774049d..1b20fa52aa 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -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 } diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index b4d55cd70b..36f574dc26 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -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()) }) })