Browse Source

spec: better texts for the Crash Reporter tests (#13227)

* Better failure messages for a Crash Reporter test

* Add a TODO
Alexey Kuzmin 6 years ago
parent
commit
6a59b37bea
1 changed files with 16 additions and 7 deletions
  1. 16 7
      spec/api-crash-reporter-spec.js

+ 16 - 7
spec/api-crash-reporter-spec.js

@@ -1,5 +1,6 @@
 const assert = require('assert')
 const childProcess = require('child_process')
+const {expect} = require('chai')
 const fs = require('fs')
 const http = require('http')
 const multiparty = require('multiparty')
@@ -256,23 +257,31 @@ describe('crashReporter module', () => {
     })
   })
 
+  // TODO(alexeykuzmin): This suite should explicitly
+  // generate several crash reports instead of hoping
+  // that there will be enough of them already.
   describe('getLastCrashReport', () => {
     it('correctly returns the most recent report', () => {
       const reports = crashReporter.getUploadedReports()
+      expect(reports).to.be.an('array')
+      expect(reports).to.have.lengthOf.at.least(2,
+          'There are not enough reports for this test')
+
       const lastReport = crashReporter.getLastCrashReport()
+      expect(lastReport).to.be.an('object').that.includes.a.key('date')
 
-      // Let's find the newest report
-      const newestReport = reports.reduce((acc, cur) => {
+      // Let's find the newest report.
+      const {report: newestReport} = reports.reduce((acc, cur) => {
         const timestamp = new Date(cur.date).getTime()
         return (timestamp > acc.timestamp)
           ? { report: cur, timestamp: timestamp }
           : acc
-      }, { timestamp: 0 })
+      }, { timestamp: -Infinity })
+      assert(newestReport, 'Hey!')
 
-      assert(reports.length > 1, 'has more than 1 report')
-      assert(lastReport != null, 'found a last report')
-      assert(lastReport.date.toString() === newestReport.report.date.toString(),
-        'last report is correct')
+      expect(lastReport.date.getTime()).to.be.equal(
+          newestReport.date.getTime(),
+          'Last report is not the newest.')
     })
   })