From 6a59b37beaf7e101d1cfdcb9fe2163398edb61dd Mon Sep 17 00:00:00 2001 From: Alexey Kuzmin Date: Thu, 14 Jun 2018 11:24:28 +0200 Subject: [PATCH] spec: better texts for the Crash Reporter tests (#13227) * Better failure messages for a Crash Reporter test * Add a TODO --- spec/api-crash-reporter-spec.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index ffa3c03705..0305473ef8 100644 --- a/spec/api-crash-reporter-spec.js +++ b/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() - 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 newestReport = reports.reduce((acc, cur) => { + const lastReport = crashReporter.getLastCrashReport() + 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() 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.') }) })