node/test/parallel/test-async-hooks-asyncresource-constructor.js
Andreas Madsen 31417b6882
async_hooks: make AsyncResource match emitInit
AsyncResource previously called emitInitNative. Since AsyncResource is
just an abstraction on top of the emitEventScript functions, it should
call emitInitScript instead.

PR-URL: https://github.com/nodejs/node/pull/14152
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-07-13 14:15:06 +02:00

30 lines
795 B
JavaScript

'use strict';
require('../common');
// This tests that AsyncResource throws an error if bad parameters are passed
const assert = require('assert');
const async_hooks = require('async_hooks');
const { AsyncResource } = async_hooks;
// Setup init hook such parameters are validated
async_hooks.createHook({
init() {}
}).enable();
assert.throws(() => {
return new AsyncResource();
}, /^TypeError: type must be a string with length > 0$/);
assert.throws(() => {
new AsyncResource('');
}, /^TypeError: type must be a string with length > 0$/);
assert.throws(() => {
new AsyncResource('type', -4);
}, /^RangeError: triggerAsyncId must be an unsigned integer$/);
assert.throws(() => {
new AsyncResource('type', Math.PI);
}, /^RangeError: triggerAsyncId must be an unsigned integer$/);