Skip to content

Commit

Permalink
squash: add prefix to option name and refact test
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Feb 27, 2018
1 parent df5ee8f commit 8a43ed1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
10 changes: 5 additions & 5 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const {
class AsyncHook {
constructor({ init, before, after, destroy, promiseResolve }) {
if (init !== undefined && typeof init !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'init');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.init');
if (before !== undefined && typeof before !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.before');
if (after !== undefined && typeof after !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'after');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.after');
if (destroy !== undefined && typeof destroy !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'destroy');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.destroy');
if (promiseResolve !== undefined && typeof promiseResolve !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'promiseResolve');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.promiseResolve');

this[init_symbol] = init;
this[before_symbol] = before;
Expand Down
32 changes: 10 additions & 22 deletions test/parallel/test-async-hooks-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ const common = require('../common');
const async_hooks = require('async_hooks');
const non_function = 10;

common.expectsError(() => {
async_hooks.createHook({ init: non_function });
}, typeErrorForFunction('init'));

common.expectsError(() => {
async_hooks.createHook({ before: non_function });
}, typeErrorForFunction('before'));

common.expectsError(() => {
async_hooks.createHook({ after: non_function });
}, typeErrorForFunction('after'));

common.expectsError(() => {
async_hooks.createHook({ destroy: non_function });
}, typeErrorForFunction('destroy'));

common.expectsError(() => {
async_hooks.createHook({ promiseResolve: non_function });
}, typeErrorForFunction('promiseResolve'));
typeErrorForFunction('init');
typeErrorForFunction('before');
typeErrorForFunction('after');
typeErrorForFunction('destroy');
typeErrorForFunction('promiseResolve');

function typeErrorForFunction(functionName) {
return {
common.expectsError(() => {
async_hooks.createHook({ [functionName]: non_function });
}, {
code: 'ERR_ASYNC_CALLBACK',
type: TypeError,
message: `${functionName} must be a function`,
};
message: `hook.${functionName} must be a function`
});
}

0 comments on commit 8a43ed1

Please sign in to comment.