Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Provide whole task object to onTaskInvoke
Browse files Browse the repository at this point in the history
  • Loading branch information
kbruccoleri committed Jun 17, 2021
1 parent 19709a2 commit 2f91dbf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules

.idea/
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2f91dbf

Please sign in to comment.