From 72579f9bab03a3802d523c074c21d220ae2ba05e Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 13:57:12 -0700 Subject: [PATCH 1/6] :wrench: Sort crashes --- lib/common/api/crash-reporter.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 6dc774049d..69962ddd6a 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.timestamp) ? new Date(a.timestamp).getTime() : 0 + const bts = (b && b.timestamp) ? new Date(b.timestamp).getTime() : 0 + return bts - ats + }) + return (reports.length > 0) ? reports[0] : null } From 673335de4b70e1f651e82dd7cf605a2aaca1ed7a Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 16:51:20 -0700 Subject: [PATCH 2/6] :wrench: Actually test the method --- spec/api-crash-reporter-spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index b4d55cd70b..61c733c7c5 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -259,8 +259,11 @@ describe('crashReporter module', () => { describe('getLastCrashReport', () => { it('correctly returns the most recent report', () => { const reports = crashReporter.getUploadedReports() - const lastReport = reports[0] + const lastReport = crashReporter.getLastCrashReport() + + // In our case, the first report is actually the newest\ assert(lastReport != null) + assert(lastReport === reports[0]) }) }) From 3575dae75c0805ed9090d3d456c3e85bad4da02d Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 16:58:40 -0700 Subject: [PATCH 3/6] :hocho: Cut typo --- spec/api-crash-reporter-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 61c733c7c5..b89d6557d7 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -261,7 +261,7 @@ describe('crashReporter module', () => { const reports = crashReporter.getUploadedReports() const lastReport = crashReporter.getLastCrashReport() - // In our case, the first report is actually the newest\ + // In our case, the first report is actually the newest assert(lastReport != null) assert(lastReport === reports[0]) }) From 1b3568e66e0df62a564646234f027c679c3b68bc Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 17:28:15 -0700 Subject: [PATCH 4/6] :construction_worker: Fancy test --- spec/api-crash-reporter-spec.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index b89d6557d7..26d580d56d 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -261,9 +261,17 @@ describe('crashReporter module', () => { const reports = crashReporter.getUploadedReports() const lastReport = crashReporter.getLastCrashReport() + // Let's find the newest report + const newestReport = reports.reduce((acc, cur) => { + const timestamp = new Date(cur.timestamp).getTime(); + return (timestamp > acc.timestamp) + ? { report: cur, timestamp: timestamp } + : acc + }, { timestamp: 0 }) + // In our case, the first report is actually the newest assert(lastReport != null) - assert(lastReport === reports[0]) + assert(lastReport === newestReport.report) }) }) From 582ef30b4a2eaaa333ee5622562b2ba656c4d63f Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 17:35:55 -0700 Subject: [PATCH 5/6] :construction_worker: Tests, how do they work --- lib/common/api/crash-reporter.js | 4 ++-- spec/api-crash-reporter-spec.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 69962ddd6a..1b20fa52aa 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -66,8 +66,8 @@ class CrashReporter { getLastCrashReport () { const reports = this.getUploadedReports() .sort((a, b) => { - const ats = (a && a.timestamp) ? new Date(a.timestamp).getTime() : 0 - const bts = (b && b.timestamp) ? new Date(b.timestamp).getTime() : 0 + 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 }) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 26d580d56d..de403dc1f2 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -263,15 +263,15 @@ describe('crashReporter module', () => { // Let's find the newest report const newestReport = reports.reduce((acc, cur) => { - const timestamp = new Date(cur.timestamp).getTime(); + const timestamp = new Date(cur.date).getTime(); return (timestamp > acc.timestamp) ? { report: cur, timestamp: timestamp } : acc }, { timestamp: 0 }) - // In our case, the first report is actually the newest + assert(lastReport != null) - assert(lastReport === newestReport.report) + assert(lastReport.date.toString() === newestReport.report.date.toString()) }) }) From ee6721103599574f75a5e2ee866b10d6576c2767 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 13 Mar 2018 17:40:41 -0700 Subject: [PATCH 6/6] :wrench: Linter's gotta lint --- spec/api-crash-reporter-spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index de403dc1f2..36f574dc26 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -263,13 +263,12 @@ describe('crashReporter module', () => { // Let's find the newest report const newestReport = reports.reduce((acc, cur) => { - const timestamp = new Date(cur.date).getTime(); + 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()) })