From 4a8dcec63a76af18393b0cc3a23693235fc9fb2d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Oct 2016 09:45:58 -0700 Subject: [PATCH] Wait for crash report to become available --- spec/api-crash-reporter-spec.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 72e9317..fe8c3f6 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -61,10 +61,12 @@ describe('crashReporter module', function () { const reportId = 'abc-123-def-456-abc-789-abc-123-abcd' res.end(reportId, () => { - assert.equal(crashReporter.getLastCrashReport().id, reportId) - assert.notEqual(crashReporter.getUploadedReports().length, 0) - assert.equal(crashReporter.getUploadedReports()[0].id, reportId) - done() + waitForCrashReport().then(() => { + assert.equal(crashReporter.getLastCrashReport().id, reportId) + assert.notEqual(crashReporter.getUploadedReports().length, 0) + assert.equal(crashReporter.getUploadedReports()[0].id, reportId) + done() + }, done) }) }) }) @@ -116,3 +118,20 @@ describe('crashReporter module', function () { }) }) }) + +const waitForCrashReport = () => { + return new Promise((resolve, reject) => { + let times = 0 + const checkForReport = () => { + if (crashReporter.getLastCrashReport() != null) { + resolve() + } else if (times >= 10) { + reject(new Error('No crash report available')) + } else { + times++ + setTimeout(checkForReport, 100) + } + } + checkForReport() + }) +} -- 2.7.4