From 2f91dbf401ae1d2344171c04d944d327d18b0de9 Mon Sep 17 00:00:00 2001 From: Kevin Bruccoleri Date: Thu, 17 Jun 2021 15:40:41 -0400 Subject: [PATCH] Provide whole task object to onTaskInvoke --- .gitignore | 1 + README.md | 10 ++++------ src/index.js | 8 +++----- src/zones.js | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index a56a7ef..b9f5f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +.idea/ diff --git a/README.md b/README.md index 64d516a..38eb14a 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,10 @@ patchJestAPI({ * @param {Object} options Options for the handler (see below) * * Options: - * @param {Number} originTestId The unique ID of the test where the task is oginating from + * @param {Number} originTestId The unique ID of the test where the task is originating from * @param {Number} currentTestId The unique ID of the currently executing test * @param {String} testName The name of the test which triggered this event - * @param {String} taskType The type of task being invoked (micro/macro task) - * @param {String} taskSource The source of the taks ("promise.then", "setTimeout" etc) + * @param {ZoneTask} task The task being invoked (micro/macro task) * @param {Object} logger The logger object (defaults to console) * * @throws {Error} Default: throws. This function _may_ throw an error instead of logging it if @@ -90,14 +89,13 @@ patchJestAPI({ originZoneId, currentZoneId, testName, - taskType, - taskSource, + task, }) { // This is the default implementation of onInvokeTask. The error thrown will // be displayed as a logger.warn with a cleaned up stack trace. if (originZoneId !== currentZoneId) { throw new Error( - `Test "${testName}" is attempting to invoke a ${taskType}(${taskSource}) after test completion. Ignoring` + `Test "${testName}" is attempting to invoke a ${task.type}(${task.source}) after test completion. See stack-trace for details.` ); } return true; diff --git a/src/index.js b/src/index.js index f9f2f79..216ee25 100644 --- a/src/index.js +++ b/src/index.js @@ -21,16 +21,14 @@ function onInvokeTaskDefault({ currentZoneId, // The name of the test from where this task originates testName, - // The type of the task being acted upon [micro || macro]Task - taskType, - // Promise, setTimeout etc. - taskSource, + // The task being invoked + task, }) { // Note that we do not use "testName" for this as they are not guaranteed to be // unique if (originZoneId !== currentZoneId) { throw new Error( - `Test "${testName}" is attempting to invoke a ${taskType}(${taskSource}) after test completion. See stack-trace for details.` + `Test "${testName}" is attempting to invoke a ${task.type}(${task.source}) after test completion. See stack-trace for details.` ); } return true; diff --git a/src/zones.js b/src/zones.js index 355c064..c0e866a 100644 --- a/src/zones.js +++ b/src/zones.js @@ -87,8 +87,7 @@ const getZones = ({ onInvokeTask, logger, ignoreStack }) => { originZoneId: current.get('id'), currentZoneId: currentZone, testName: name, - taskType: task.type, - taskSource: task.source, + task: task, logger: logger, }); } catch (e) {