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

* Better failure messages for a Crash Reporter test

* Add a TODO
This commit is contained in:
Alexey Kuzmin 2018-06-14 11:24:28 +02:00 committed by Samuel Attard
parent dee9aef975
commit 6a59b37bea

View file

@ -1,5 +1,6 @@
const assert = require('assert') const assert = require('assert')
const childProcess = require('child_process') const childProcess = require('child_process')
const {expect} = require('chai')
const fs = require('fs') const fs = require('fs')
const http = require('http') const http = require('http')
const multiparty = require('multiparty') 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', () => { 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 = crashReporter.getLastCrashReport() expect(reports).to.be.an('array')
expect(reports).to.have.lengthOf.at.least(2,
'There are not enough reports for this test')
// Let's find the newest report const lastReport = crashReporter.getLastCrashReport()
const newestReport = reports.reduce((acc, cur) => { expect(lastReport).to.be.an('object').that.includes.a.key('date')
// Let's find the newest report.
const {report: newestReport} = reports.reduce((acc, cur) => {
const timestamp = new Date(cur.date).getTime() const timestamp = new Date(cur.date).getTime()
return (timestamp > acc.timestamp) return (timestamp > acc.timestamp)
? { report: cur, timestamp: timestamp } ? { report: cur, timestamp: timestamp }
: acc : acc
}, { timestamp: 0 }) }, { timestamp: -Infinity })
assert(newestReport, 'Hey!')
assert(reports.length > 1, 'has more than 1 report') expect(lastReport.date.getTime()).to.be.equal(
assert(lastReport != null, 'found a last report') newestReport.date.getTime(),
assert(lastReport.date.toString() === newestReport.report.date.toString(), 'Last report is not the newest.')
'last report is correct')
}) })
}) })