Backport - fix: Ensure that getLastCrashReport() is actually the last crash report (#12255)

* 🔧 Sort crashes

* 🔧 Actually test the method

* 🔪 Cut typo

* 👷 Fancy test

* 👷 Tests, how do they work

* 🔧 Linter's gotta lint
This commit is contained in:
trop[bot]
2018-03-14 11:36:58 +09:00
committed by Samuel Attard
parent 9843ce743e
commit c9e2140bca
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())
})
})