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 0.0.1 to 0.0.2

7

e2e/passing/__tests__/index.js

@@ -36,2 +36,9 @@ /**

test('.thens are chained properly', () => {
// Test that our use of zones does not break promise chaining
return Promise.resolve(1)
.then(v => v + 2)
.then(v => expect(v).toBe(3));
});
describe('it() should behave the same as test()', () => {

@@ -38,0 +45,0 @@ it('basic tests should pass', () => {

2

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,2 +6,6 @@ # `jest-plugin-must-assert`

## WARNING
The plugin is in a working state, but is under construction :construction:
## Install

@@ -8,0 +12,0 @@

@@ -0,9 +1,14 @@

const consoleMethods = Object.entries(global.console);
const restoreConsole = () =>
consoleMethods.forEach(([key, value]) => {
global.console[key] = value;
});
require('zone.js');
// NOTE: zone.js patches console methods, avoid that.
restoreConsole();
// Zone sets itself as a global...
const Zone = global.Zone;
const testHasNoExplicitAssertionChecks = (state = expect.getState()) =>
typeof state.expectedAssertionsNumber !== 'number' &&
!state.isExpectingAssertions;
let currentZone = null;

@@ -13,3 +18,45 @@ let uniqueIdentifier = 0;

const wrapTest = fn => {
const testHasNoExplicitAssertionChecks = () => {
// Some misconfigured test (eg overriding expect itself)
if (!(typeof expect !== 'undefined' && 'getState' in expect)) {
return false;
}
const state = expect.getState();
return (
typeof state.expectedAssertionsNumber !== 'number' &&
!state.isExpectingAssertions
);
};
const exitZone = () => (currentZone = null);
const enterZone = (callback, name, hasDoneCallback) => {
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 (current.get('id') !== currentZone) {
console.warn(
`Test "${current.name}" is attempting to invoke a ${task.type}(${
task.source
}) after test completion. Ignoring`
);
return;
}
return delegate.invokeTask(target, task, applyThis, applyArgs);
},
});
currentZone = id;
return zone.wrap(hasDoneCallback ? callback : done => callback(done));
};
const wrapTest = (fn, name) => {
let testMustAssert;

@@ -20,3 +67,3 @@ const hasDoneCallback = fn.length > 0;

return () => {
const result = fn();
const result = enterZone(fn, name, false)();

@@ -32,12 +79,9 @@ if (testHasNoExplicitAssertionChecks()) {

) {
return result.then(
() => (currentZone = null),
e => {
currentZone = null;
throw e;
}
);
return result.then(exitZone, e => {
exitZone();
throw e;
});
}
currentZone = null;
exitZone();
return result;

@@ -49,6 +93,6 @@ };

const done = () => {
currenZone = null;
exitZone();
doneOriginal();
};
const result = fn(done, ...args);
const result = enterZone(fn, name, true)(done, ...args);

@@ -65,39 +109,3 @@ if (testHasNoExplicitAssertionChecks()) {

return function ehanchedJestMehod(name, fn, timeout) {
const id = uuid();
const zone = Zone.root.fork({
name,
properties: {
id,
},
onInvoke(
delegate,
current,
target,
callback,
applyThis,
applyArgs,
source
) {
currentZone = id;
delegate.invoke(target, callback, applyThis, applyArgs, source);
},
onInvokeTask(delegate, current, target, task, applyThis, applyArgs) {
if (current.get('id') !== currentZone) {
console.warn(
`Test "${current.name}" is attempting to invoke a ${task.type}(${
task.source
}) after test completion. Ignoring`
);
} else {
delegate.invokeTask(target, task, applyThis, applyArgs);
}
},
});
const hasDoneCallback = fn.length > 0;
const wrapper = zone.wrap(wrapTest(fn));
return jestTest(
name,
hasDoneCallback ? done => wrapper(done) : wrapper,
timeout
);
return jestTest(name, wrapTest(fn, name), timeout);
};

@@ -104,0 +112,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