Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-plugin-must-assert

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-plugin-must-assert - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

3

package.json
{
"name": "jest-plugin-must-assert",
"version": "1.1.0",
"version": "1.2.0",
"description": "Jest plugin for async tests",

@@ -34,4 +34,5 @@ "main": "index.js",

"dependencies": {
"stack-utils": "^1.0.2",
"zone.js": "^0.9.0"
}
}

@@ -57,7 +57,23 @@ # `jest-plugin-must-assert`

*
* @throws {Error} Default: throws. This function _may_ throw an error instead of logging it if
* you would like a stack trace back to the origin of the task being ignored.
*
* @return {Boolean} true/false for whether or not the task should execute
*/
onInvokeTask(originTestId, currentTestId, log) {
return false;
}
onInvokeTask({
originZoneId,
currentZoneId,
testName,
taskType,
taskSource,
}) {
// 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`
);
}
return true;
},
/**

@@ -64,0 +80,0 @@ * Logger DI. Used by the internal methods to log warnings/errors. Should match console API.

@@ -0,3 +1,6 @@

const StackUtils = require('stack-utils');
module.exports = patchJestAPI;
const EXPOSE_ERROR = Symbol('EXPOSE_ERROR');
function onInvokeTaskDefault({

@@ -9,9 +12,7 @@ originZoneId,

taskSource,
logger,
}) {
if (originZoneId !== currentZoneId) {
logger.warn(
`Test "${testName}" is attempting to invoke a ${taskType}(${taskSource}) after test completion. Ignoring`
throw new Error(
`Test "${testName}" is attempting to invoke a ${taskType}(${taskSource}) after test completion. See stack-trace for details.`
);
return false;
}

@@ -32,6 +33,14 @@ return true;

require('zone.js');
require('zone.js/dist/long-stack-trace-zone');
// NOTE: zone.js patches console methods, avoid that.
restoreConsole();
const stack = new StackUtils({
cwd: process.cwd(),
internals: StackUtils.nodeInternals().concat([
/Zone/,
/zone\.js/,
/jest-plugin-must-assert/,
]),
});
// Zone sets itself as a global...

@@ -58,27 +67,47 @@ const Zone = global.Zone;

const id = uuid();
const zone = Zone.root.fork({
name,
properties: {
id,
},
onHandleError(delegate, current, target, e) {
return false;
},
onInvokeTask(delegate, current, target, task, applyThis, applyArgs) {
if (
!onInvokeTask({
originZoneId: current.get('id'),
currentZoneId: currentZone,
testName: name,
taskType: task.type,
taskSource: task.source,
logger: logger,
})
) {
return;
}
return delegate.invokeTask(target, task, applyThis, applyArgs);
},
});
const zone = Zone.root
.fork({
name,
properties: {
id,
},
onHandleError(delegate, current, target, e) {
if (e && e[EXPOSE_ERROR]) {
logger.warn(`${e.message}\n\n${stack.clean(e.stack)}`);
}
return false;
},
onInvokeTask(delegate, current, target, task, applyThis, applyArgs) {
let error;
let result = true;
try {
result = onInvokeTask({
originZoneId: current.get('id'),
currentZoneId: currentZone,
testName: name,
taskType: task.type,
taskSource: task.source,
logger: logger,
});
} catch (e) {
error = e;
}
if (error) {
error[EXPOSE_ERROR] = true;
error.task = task;
throw error;
}
if (!result) {
return;
}
return delegate.invokeTask(target, task, applyThis, applyArgs);
},
})
// We fork from the special stack-trace zone so that there is a trail leading
// back to the origin of the ignored tasks
.fork(Zone.longStackTraceZoneSpec);
currentZone = id;

@@ -85,0 +114,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc