Skip to content

test: add coverage for AsyncResource constructor #13327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/parallel/test-async-wrap-asyncresource-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
require('../common');

// This tests that AsyncResource throws an error if bad parameters are passed

const assert = require('assert');
const AsyncResource = require('async_hooks').AsyncResource;
const async_wrap = process.binding('async_wrap');

assert.throws(() => {
return new AsyncResource();
}, new RegExp('^TypeError: type must be a string with length > 0$'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure @jasnell’s nit was actually addressed… why are these new RegExp() calls? It might be confusing to readers of our tests because we almost exclusively use them to create dynamic regexes that depend on variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my comments were not addressed. I would prefer to see the /..../ regex pattern used but I'm fine with this either way.


assert.throws(() => {
new AsyncResource('');
}, new RegExp('^TypeError: type must be a string with length > 0$'));

assert.throws(() => {
new AsyncResource('type', -4);
}, new RegExp('^RangeError: triggerId must be an unsigned integer$'));

assert.throws(() => {
new AsyncResource('type', Math.PI);
}, new RegExp('^RangeError: triggerId must be an unsigned integer$'));