acme: async'ify

This commit is contained in:
Girish Ramakrishnan
2021-05-06 22:29:34 -07:00
parent 31503e2625
commit cc684b4ea0
5 changed files with 258 additions and 260 deletions

View File

@@ -0,0 +1,38 @@
/* jslint node:true */
/* global it:false */
/* global describe:false */
'use strict';
const expect = require('expect.js'),
promiseRetry = require('../promise-retry.js'),
safe = require('safetydance');
describe('promiseRetry', function () {
this.timeout(0);
it('normal return', async function () {
const result = await promiseRetry({ times: 5, interval: 1000 }, async () => {
return 42;
});
expect(result).to.be(42);
});
it('throws error', async function () {
await safe(promiseRetry({ times: 5, interval: 1000 }, async () => {
throw new Error('42');
}));
expect(safe.error.message).to.be('42');
});
it('3 tries', async function () {
let tryCount = 0;
const result = await promiseRetry({ times: 5, interval: 1000 }, async () => {
if (++tryCount == 3) return 42; else throw new Error('42');
});
expect(result).to.be(42);
});
});