From e82a2e8ad543e1dcd1a4a7dbe77a0527a992bd83 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 24 Dec 2020 15:51:23 -0800 Subject: [PATCH] test: increase runInAsyncScope() coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't appear to have any test coverage for passing the `thisArg` argument to `runInAsyncScope()`. Test coverage stats seem to bear this out. Add a test for it. PR-URL: https://github.com/nodejs/node/pull/36624 Reviewed-By: Antoine du Hamel Reviewed-By: Michaƫl Zasso --- ...t-async-hooks-run-in-async-scope-this-arg.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/parallel/test-async-hooks-run-in-async-scope-this-arg.js diff --git a/test/parallel/test-async-hooks-run-in-async-scope-this-arg.js b/test/parallel/test-async-hooks-run-in-async-scope-this-arg.js new file mode 100644 index 00000000000000..a5016da9d5fcd3 --- /dev/null +++ b/test/parallel/test-async-hooks-run-in-async-scope-this-arg.js @@ -0,0 +1,17 @@ +'use strict'; + +// Test that passing thisArg to runInAsyncScope() works. + +const common = require('../common'); +const assert = require('assert'); +const { AsyncResource } = require('async_hooks'); + +const thisArg = {}; + +const res = new AsyncResource('fhqwhgads'); + +function callback() { + assert.strictEqual(this, thisArg); +} + +res.runInAsyncScope(common.mustCall(callback), thisArg);