various timeout changes

This commit is contained in:
John McLear 2021-01-27 21:50:18 +00:00
parent c43de8ea59
commit 189786979f
8 changed files with 62 additions and 62 deletions

View file

@ -37,7 +37,7 @@ describe(__filename, function () {
describe('OpenAPI definition', function () { describe('OpenAPI definition', function () {
it('generates valid openapi definition document', function (done) { it('generates valid openapi definition document', function (done) {
this.timeout(150); this.timeout(5000);
api api
.get('/api/openapi.json') .get('/api/openapi.json')
.expect((res) => { .expect((res) => {

View file

@ -64,7 +64,7 @@ describe(__filename, function () {
describe('setHTML', function () { describe('setHTML', function () {
it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function (done) { it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function (done) {
this.timeout(150); this.timeout(600);
fs.readFile('../tests/backend/specs/api/emojis.html', 'utf8', (err, html) => { fs.readFile('../tests/backend/specs/api/emojis.html', 'utf8', (err, html) => {
api.post(endPoint('setHTML')) api.post(endPoint('setHTML'))
.send({ .send({
@ -82,7 +82,7 @@ describe(__filename, function () {
describe('getHTML', function () { describe('getHTML', function () {
it('get the HTML of Pad with emojis', function (done) { it('get the HTML of Pad with emojis', function (done) {
this.timeout(150); this.timeout(400);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.html.indexOf('&#127484') === -1) { if (res.body.data.html.indexOf('&#127484') === -1) {

View file

@ -39,7 +39,7 @@ describe(__filename, function () {
*/ */
describe('createPad', function () { describe('createPad', function () {
this.timeout(40); this.timeout(250);
it('creates a new Pad', function (done) { it('creates a new Pad', function (done) {
api.get(`${endPoint('createPad')}&padID=${padID}`) api.get(`${endPoint('createPad')}&padID=${padID}`)
.expect((res) => { .expect((res) => {
@ -51,7 +51,7 @@ describe(__filename, function () {
}); });
describe('createAuthor', function () { describe('createAuthor', function () {
this.timeout(30); this.timeout(100);
it('Creates an author with a name set', function (done) { it('Creates an author with a name set', function (done) {
api.get(endPoint('createAuthor')) api.get(endPoint('createAuthor'))
.expect((res) => { .expect((res) => {
@ -66,7 +66,7 @@ describe(__filename, function () {
}); });
describe('appendChatMessage', function () { describe('appendChatMessage', function () {
this.timeout(30); this.timeout(100);
it('Adds a chat message to the pad', function (done) { it('Adds a chat message to the pad', function (done) {
api.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha&authorID=${authorID}&time=${timestamp}`) api.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha&authorID=${authorID}&time=${timestamp}`)
.expect((res) => { .expect((res) => {
@ -93,7 +93,7 @@ describe(__filename, function () {
}); });
describe('getChatHistory', function () { describe('getChatHistory', function () {
this.timeout(20); this.timeout(40);
it('Gets Chat History of a Pad', function (done) { it('Gets Chat History of a Pad', function (done) {
api.get(`${endPoint('getChatHistory')}&padID=${padID}`) api.get(`${endPoint('getChatHistory')}&padID=${padID}`)
.expect((res) => { .expect((res) => {

View file

@ -246,7 +246,7 @@ describe(__filename, function () {
}); });
it('setHTML', function (done) { it('setHTML', function (done) {
this.timeout(100); this.timeout(150);
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${encodeURIComponent(test.input)}`) api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${encodeURIComponent(test.input)}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error(`Error:${testName}`); if (res.body.code !== 0) throw new Error(`Error:${testName}`);
@ -256,7 +256,7 @@ describe(__filename, function () {
}); });
it('getHTML', function (done) { it('getHTML', function (done) {
this.timeout(100); this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
const gotHtml = res.body.data.html; const gotHtml = res.body.data.html;

View file

@ -40,7 +40,7 @@ describe(__filename, function () {
describe('API Versioning', function () { describe('API Versioning', function () {
it('finds the version tag', async function () { it('finds the version tag', async function () {
this.timeout(100); this.timeout;
await agent.get('/api/') await agent.get('/api/')
.expect(200) .expect(200)
.expect((res) => assert(res.body.currentVersion)); .expect((res) => assert(res.body.currentVersion));

View file

@ -71,7 +71,7 @@ describe(__filename, function () {
settings.minify = false; settings.minify = false;
}); });
it('gets packages uncompressed without Accept-Encoding gzip', async function () { it('gets packages uncompressed without Accept-Encoding gzip', async function () {
this.timeout(1500); this.timeout(2500);
await Promise.all(packages.map(async (resource) => agent.get(resource) await Promise.all(packages.map(async (resource) => agent.get(resource)
.set('Accept-Encoding', fantasyEncoding) .set('Accept-Encoding', fantasyEncoding)
.use(disableAutoDeflate) .use(disableAutoDeflate)

View file

@ -285,7 +285,7 @@ describe(__filename, function () {
} }
it(testObj.description, async function () { it(testObj.description, async function () {
this.timeout(150); this.timeout(250);
const $ = cheerio.load(testObj.html); // Load HTML into Cheerio const $ = cheerio.load(testObj.html); // Load HTML into Cheerio
const doc = $('body')[0]; // Creates a dom-like representation of HTML const doc = $('body')[0]; // Creates a dom-like representation of HTML
// Create an empty attribute pool // Create an empty attribute pool

View file

@ -95,13 +95,13 @@ describe(__filename, function () {
describe('basic behavior', function () { describe('basic behavior', function () {
it('passes hook name', async function () { it('passes hook name', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn) => { assert.equal(hn, hookName); }; hook.hook_fn = (hn) => { assert.equal(hn, hookName); };
callHookFnSync(hook); callHookFnSync(hook);
}); });
it('passes context', async function () { it('passes context', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
hook.hook_fn = (hn, ctx) => { assert.equal(ctx, val); }; hook.hook_fn = (hn, ctx) => { assert.equal(ctx, val); };
callHookFnSync(hook, val); callHookFnSync(hook, val);
@ -109,7 +109,7 @@ describe(__filename, function () {
}); });
it('returns the value provided to the callback', async function () { it('returns the value provided to the callback', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
hook.hook_fn = (hn, ctx, cb) => { cb(ctx); }; hook.hook_fn = (hn, ctx, cb) => { cb(ctx); };
assert.equal(callHookFnSync(hook, val), val); assert.equal(callHookFnSync(hook, val), val);
@ -117,7 +117,7 @@ describe(__filename, function () {
}); });
it('returns the value returned by the hook function', async function () { it('returns the value returned by the hook function', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
// Must not have the cb parameter otherwise returning undefined will error. // Must not have the cb parameter otherwise returning undefined will error.
hook.hook_fn = (hn, ctx) => ctx; hook.hook_fn = (hn, ctx) => ctx;
@ -126,19 +126,19 @@ describe(__filename, function () {
}); });
it('does not catch exceptions', async function () { it('does not catch exceptions', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = () => { throw new Error('test exception'); }; hook.hook_fn = () => { throw new Error('test exception'); };
assert.throws(() => callHookFnSync(hook), {message: 'test exception'}); assert.throws(() => callHookFnSync(hook), {message: 'test exception'});
}); });
it('callback returns undefined', async function () { it('callback returns undefined', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => { assert.equal(cb('foo'), undefined); }; hook.hook_fn = (hn, ctx, cb) => { assert.equal(cb('foo'), undefined); };
callHookFnSync(hook); callHookFnSync(hook);
}); });
it('checks for deprecation', async function () { it('checks for deprecation', async function () {
this.timeout(10); this.timeout(30);
sinon.stub(console, 'warn'); sinon.stub(console, 'warn');
hooks.deprecationNotices[hookName] = 'test deprecation'; hooks.deprecationNotices[hookName] = 'test deprecation';
callHookFnSync(hook); callHookFnSync(hook);
@ -149,7 +149,7 @@ describe(__filename, function () {
}); });
describe('supported hook function styles', function () { describe('supported hook function styles', function () {
this.timeout(10); this.timeout(30);
for (const tc of supportedSyncHookFunctions) { for (const tc of supportedSyncHookFunctions) {
it(tc.name, async function () { it(tc.name, async function () {
sinon.stub(console, 'warn'); sinon.stub(console, 'warn');
@ -168,7 +168,7 @@ describe(__filename, function () {
}); });
describe('bad hook function behavior (other than double settle)', function () { describe('bad hook function behavior (other than double settle)', function () {
this.timeout(10); this.timeout(30);
const promise1 = Promise.resolve('val1'); const promise1 = Promise.resolve('val1');
const promise2 = Promise.resolve('val2'); const promise2 = Promise.resolve('val2');
@ -248,7 +248,7 @@ describe(__filename, function () {
if (step1.async && step2.async) continue; if (step1.async && step2.async) continue;
it(`${step1.name} then ${step2.name} (diff. outcomes) -> log+throw`, async function () { it(`${step1.name} then ${step2.name} (diff. outcomes) -> log+throw`, async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => { hook.hook_fn = (hn, ctx, cb) => {
step1.fn(cb, new Error(ctx.ret1), ctx.ret1); step1.fn(cb, new Error(ctx.ret1), ctx.ret1);
return step2.fn(cb, new Error(ctx.ret2), ctx.ret2); return step2.fn(cb, new Error(ctx.ret2), ctx.ret2);
@ -312,7 +312,7 @@ describe(__filename, function () {
if (step1.rejects !== step2.rejects) continue; if (step1.rejects !== step2.rejects) continue;
it(`${step1.name} then ${step2.name} (same outcome) -> only log`, async function () { it(`${step1.name} then ${step2.name} (same outcome) -> only log`, async function () {
this.timeout(10); this.timeout(30);
const err = new Error('val'); const err = new Error('val');
hook.hook_fn = (hn, ctx, cb) => { hook.hook_fn = (hn, ctx, cb) => {
step1.fn(cb, err, 'val'); step1.fn(cb, err, 'val');
@ -338,32 +338,32 @@ describe(__filename, function () {
describe('hooks.callAll', function () { describe('hooks.callAll', function () {
describe('basic behavior', function () { describe('basic behavior', function () {
it('calls all in order', async function () { it('calls all in order', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(1), makeHook(2), makeHook(3)); testHooks.push(makeHook(1), makeHook(2), makeHook(3));
assert.deepEqual(hooks.callAll(hookName), [1, 2, 3]); assert.deepEqual(hooks.callAll(hookName), [1, 2, 3]);
}); });
it('passes hook name', async function () { it('passes hook name', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn) => { assert.equal(hn, hookName); }; hook.hook_fn = (hn) => { assert.equal(hn, hookName); };
hooks.callAll(hookName); hooks.callAll(hookName);
}); });
it('undefined context -> {}', async function () { it('undefined context -> {}', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); }; hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
hooks.callAll(hookName); hooks.callAll(hookName);
}); });
it('null context -> {}', async function () { it('null context -> {}', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); }; hook.hook_fn = (hn, ctx) => { assert.deepEqual(ctx, {}); };
hooks.callAll(hookName, null); hooks.callAll(hookName, null);
}); });
it('context unmodified', async function () { it('context unmodified', async function () {
this.timeout(10); this.timeout(30);
const wantContext = {}; const wantContext = {};
hook.hook_fn = (hn, ctx) => { assert.equal(ctx, wantContext); }; hook.hook_fn = (hn, ctx) => { assert.equal(ctx, wantContext); };
hooks.callAll(hookName, wantContext); hooks.callAll(hookName, wantContext);
@ -372,40 +372,40 @@ describe(__filename, function () {
describe('result processing', function () { describe('result processing', function () {
it('no registered hooks (undefined) -> []', async function () { it('no registered hooks (undefined) -> []', async function () {
this.timeout(10); this.timeout(30);
delete plugins.hooks.testHook; delete plugins.hooks.testHook;
assert.deepEqual(hooks.callAll(hookName), []); assert.deepEqual(hooks.callAll(hookName), []);
}); });
it('no registered hooks (empty list) -> []', async function () { it('no registered hooks (empty list) -> []', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
assert.deepEqual(hooks.callAll(hookName), []); assert.deepEqual(hooks.callAll(hookName), []);
}); });
it('flattens one level', async function () { it('flattens one level', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(1), makeHook([2]), makeHook([[3]])); testHooks.push(makeHook(1), makeHook([2]), makeHook([[3]]));
assert.deepEqual(hooks.callAll(hookName), [1, 2, [3]]); assert.deepEqual(hooks.callAll(hookName), [1, 2, [3]]);
}); });
it('filters out undefined', async function () { it('filters out undefined', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(), makeHook([2]), makeHook([[3]])); testHooks.push(makeHook(), makeHook([2]), makeHook([[3]]));
assert.deepEqual(hooks.callAll(hookName), [2, [3]]); assert.deepEqual(hooks.callAll(hookName), [2, [3]]);
}); });
it('preserves null', async function () { it('preserves null', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(null), makeHook([2]), makeHook([[3]])); testHooks.push(makeHook(null), makeHook([2]), makeHook([[3]]));
assert.deepEqual(hooks.callAll(hookName), [null, 2, [3]]); assert.deepEqual(hooks.callAll(hookName), [null, 2, [3]]);
}); });
it('all undefined -> []', async function () { it('all undefined -> []', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(), makeHook()); testHooks.push(makeHook(), makeHook());
assert.deepEqual(hooks.callAll(hookName), []); assert.deepEqual(hooks.callAll(hookName), []);
@ -418,13 +418,13 @@ describe(__filename, function () {
describe('basic behavior', function () { describe('basic behavior', function () {
it('passes hook name', async function () { it('passes hook name', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn) => { assert.equal(hn, hookName); }; hook.hook_fn = (hn) => { assert.equal(hn, hookName); };
await callHookFnAsync(hook); await callHookFnAsync(hook);
}); });
it('passes context', async function () { it('passes context', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
hook.hook_fn = (hn, ctx) => { assert.equal(ctx, val); }; hook.hook_fn = (hn, ctx) => { assert.equal(ctx, val); };
await callHookFnAsync(hook, val); await callHookFnAsync(hook, val);
@ -432,7 +432,7 @@ describe(__filename, function () {
}); });
it('returns the value provided to the callback', async function () { it('returns the value provided to the callback', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
hook.hook_fn = (hn, ctx, cb) => { cb(ctx); }; hook.hook_fn = (hn, ctx, cb) => { cb(ctx); };
assert.equal(await callHookFnAsync(hook, val), val); assert.equal(await callHookFnAsync(hook, val), val);
@ -441,7 +441,7 @@ describe(__filename, function () {
}); });
it('returns the value returned by the hook function', async function () { it('returns the value returned by the hook function', async function () {
this.timeout(10); this.timeout(30);
for (const val of ['value', null, undefined]) { for (const val of ['value', null, undefined]) {
// Must not have the cb parameter otherwise returning undefined will never resolve. // Must not have the cb parameter otherwise returning undefined will never resolve.
hook.hook_fn = (hn, ctx) => ctx; hook.hook_fn = (hn, ctx) => ctx;
@ -451,31 +451,31 @@ describe(__filename, function () {
}); });
it('rejects if it throws an exception', async function () { it('rejects if it throws an exception', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = () => { throw new Error('test exception'); }; hook.hook_fn = () => { throw new Error('test exception'); };
await assert.rejects(callHookFnAsync(hook), {message: 'test exception'}); await assert.rejects(callHookFnAsync(hook), {message: 'test exception'});
}); });
it('rejects if rejected Promise passed to callback', async function () { it('rejects if rejected Promise passed to callback', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => cb(Promise.reject(new Error('test exception'))); hook.hook_fn = (hn, ctx, cb) => cb(Promise.reject(new Error('test exception')));
await assert.rejects(callHookFnAsync(hook), {message: 'test exception'}); await assert.rejects(callHookFnAsync(hook), {message: 'test exception'});
}); });
it('rejects if rejected Promise returned', async function () { it('rejects if rejected Promise returned', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => Promise.reject(new Error('test exception')); hook.hook_fn = (hn, ctx, cb) => Promise.reject(new Error('test exception'));
await assert.rejects(callHookFnAsync(hook), {message: 'test exception'}); await assert.rejects(callHookFnAsync(hook), {message: 'test exception'});
}); });
it('callback returns undefined', async function () { it('callback returns undefined', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => { assert.equal(cb('foo'), undefined); }; hook.hook_fn = (hn, ctx, cb) => { assert.equal(cb('foo'), undefined); };
await callHookFnAsync(hook); await callHookFnAsync(hook);
}); });
it('checks for deprecation', async function () { it('checks for deprecation', async function () {
this.timeout(10); this.timeout(30);
sinon.stub(console, 'warn'); sinon.stub(console, 'warn');
hooks.deprecationNotices[hookName] = 'test deprecation'; hooks.deprecationNotices[hookName] = 'test deprecation';
await callHookFnAsync(hook); await callHookFnAsync(hook);
@ -568,7 +568,7 @@ describe(__filename, function () {
for (const tc of supportedSyncHookFunctions.concat(supportedHookFunctions)) { for (const tc of supportedSyncHookFunctions.concat(supportedHookFunctions)) {
it(tc.name, async function () { it(tc.name, async function () {
this.timeout(10); this.timeout(30);
sinon.stub(console, 'warn'); sinon.stub(console, 'warn');
sinon.stub(console, 'error'); sinon.stub(console, 'error');
hook.hook_fn = tc.fn; hook.hook_fn = tc.fn;
@ -716,7 +716,7 @@ describe(__filename, function () {
if (step1.name.startsWith('return ') || step1.name === 'throw') continue; if (step1.name.startsWith('return ') || step1.name === 'throw') continue;
for (const step2 of behaviors) { for (const step2 of behaviors) {
it(`${step1.name} then ${step2.name} (diff. outcomes) -> log+throw`, async function () { it(`${step1.name} then ${step2.name} (diff. outcomes) -> log+throw`, async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = (hn, ctx, cb) => { hook.hook_fn = (hn, ctx, cb) => {
step1.fn(cb, new Error(ctx.ret1), ctx.ret1); step1.fn(cb, new Error(ctx.ret1), ctx.ret1);
return step2.fn(cb, new Error(ctx.ret2), ctx.ret2); return step2.fn(cb, new Error(ctx.ret2), ctx.ret2);
@ -770,7 +770,7 @@ describe(__filename, function () {
if (step1.rejects !== step2.rejects) continue; if (step1.rejects !== step2.rejects) continue;
it(`${step1.name} then ${step2.name} (same outcome) -> only log`, async function () { it(`${step1.name} then ${step2.name} (same outcome) -> only log`, async function () {
this.timeout(10); this.timeout(30);
const err = new Error('val'); const err = new Error('val');
hook.hook_fn = (hn, ctx, cb) => { hook.hook_fn = (hn, ctx, cb) => {
step1.fn(cb, err, 'val'); step1.fn(cb, err, 'val');
@ -796,7 +796,7 @@ describe(__filename, function () {
describe('hooks.aCallAll', function () { describe('hooks.aCallAll', function () {
describe('basic behavior', function () { describe('basic behavior', function () {
it('calls all asynchronously, returns values in order', async function () { it('calls all asynchronously, returns values in order', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; // Delete the boilerplate hook -- this test doesn't use it. testHooks.length = 0; // Delete the boilerplate hook -- this test doesn't use it.
let nextIndex = 0; let nextIndex = 0;
const hookPromises = []; const hookPromises = [];
@ -831,25 +831,25 @@ describe(__filename, function () {
}); });
it('passes hook name', async function () { it('passes hook name', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = async (hn) => { assert.equal(hn, hookName); }; hook.hook_fn = async (hn) => { assert.equal(hn, hookName); };
await hooks.aCallAll(hookName); await hooks.aCallAll(hookName);
}); });
it('undefined context -> {}', async function () { it('undefined context -> {}', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); }; hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.aCallAll(hookName); await hooks.aCallAll(hookName);
}); });
it('null context -> {}', async function () { it('null context -> {}', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); }; hook.hook_fn = async (hn, ctx) => { assert.deepEqual(ctx, {}); };
await hooks.aCallAll(hookName, null); await hooks.aCallAll(hookName, null);
}); });
it('context unmodified', async function () { it('context unmodified', async function () {
this.timeout(10); this.timeout(30);
const wantContext = {}; const wantContext = {};
hook.hook_fn = async (hn, ctx) => { assert.equal(ctx, wantContext); }; hook.hook_fn = async (hn, ctx) => { assert.equal(ctx, wantContext); };
await hooks.aCallAll(hookName, wantContext); await hooks.aCallAll(hookName, wantContext);
@ -858,13 +858,13 @@ describe(__filename, function () {
describe('aCallAll callback', function () { describe('aCallAll callback', function () {
it('exception in callback rejects', async function () { it('exception in callback rejects', async function () {
this.timeout(10); this.timeout(30);
const p = hooks.aCallAll(hookName, {}, () => { throw new Error('test exception'); }); const p = hooks.aCallAll(hookName, {}, () => { throw new Error('test exception'); });
await assert.rejects(p, {message: 'test exception'}); await assert.rejects(p, {message: 'test exception'});
}); });
it('propagates error on exception', async function () { it('propagates error on exception', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = () => { throw new Error('test exception'); }; hook.hook_fn = () => { throw new Error('test exception'); };
await hooks.aCallAll(hookName, {}, (err) => { await hooks.aCallAll(hookName, {}, (err) => {
assert(err instanceof Error); assert(err instanceof Error);
@ -873,14 +873,14 @@ describe(__filename, function () {
}); });
it('propagages null error on success', async function () { it('propagages null error on success', async function () {
this.timeout(10); this.timeout(30);
await hooks.aCallAll(hookName, {}, (err) => { await hooks.aCallAll(hookName, {}, (err) => {
assert(err == null, `got non-null error: ${err}`); assert(err == null, `got non-null error: ${err}`);
}); });
}); });
it('propagages results on success', async function () { it('propagages results on success', async function () {
this.timeout(10); this.timeout(30);
hook.hook_fn = () => 'val'; hook.hook_fn = () => 'val';
await hooks.aCallAll(hookName, {}, (err, results) => { await hooks.aCallAll(hookName, {}, (err, results) => {
assert.deepEqual(results, ['val']); assert.deepEqual(results, ['val']);
@ -888,47 +888,47 @@ describe(__filename, function () {
}); });
it('returns callback return value', async function () { it('returns callback return value', async function () {
this.timeout(10); this.timeout(30);
assert.equal(await hooks.aCallAll(hookName, {}, () => 'val'), 'val'); assert.equal(await hooks.aCallAll(hookName, {}, () => 'val'), 'val');
}); });
}); });
describe('result processing', function () { describe('result processing', function () {
it('no registered hooks (undefined) -> []', async function () { it('no registered hooks (undefined) -> []', async function () {
this.timeout(10); this.timeout(30);
delete plugins.hooks[hookName]; delete plugins.hooks[hookName];
assert.deepEqual(await hooks.aCallAll(hookName), []); assert.deepEqual(await hooks.aCallAll(hookName), []);
}); });
it('no registered hooks (empty list) -> []', async function () { it('no registered hooks (empty list) -> []', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
assert.deepEqual(await hooks.aCallAll(hookName), []); assert.deepEqual(await hooks.aCallAll(hookName), []);
}); });
it('flattens one level', async function () { it('flattens one level', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(1), makeHook([2]), makeHook([[3]])); testHooks.push(makeHook(1), makeHook([2]), makeHook([[3]]));
assert.deepEqual(await hooks.aCallAll(hookName), [1, 2, [3]]); assert.deepEqual(await hooks.aCallAll(hookName), [1, 2, [3]]);
}); });
it('filters out undefined', async function () { it('filters out undefined', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(), makeHook([2]), makeHook([[3]]), makeHook(Promise.resolve())); testHooks.push(makeHook(), makeHook([2]), makeHook([[3]]), makeHook(Promise.resolve()));
assert.deepEqual(await hooks.aCallAll(hookName), [2, [3]]); assert.deepEqual(await hooks.aCallAll(hookName), [2, [3]]);
}); });
it('preserves null', async function () { it('preserves null', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(null), makeHook([2]), makeHook(Promise.resolve(null))); testHooks.push(makeHook(null), makeHook([2]), makeHook(Promise.resolve(null)));
assert.deepEqual(await hooks.aCallAll(hookName), [null, 2, null]); assert.deepEqual(await hooks.aCallAll(hookName), [null, 2, null]);
}); });
it('all undefined -> []', async function () { it('all undefined -> []', async function () {
this.timeout(10); this.timeout(30);
testHooks.length = 0; testHooks.length = 0;
testHooks.push(makeHook(), makeHook(Promise.resolve())); testHooks.push(makeHook(), makeHook(Promise.resolve()));
assert.deepEqual(await hooks.aCallAll(hookName), []); assert.deepEqual(await hooks.aCallAll(hookName), []);