Socket
Socket
Sign inDemoInstall

eslint-plugin-jest

Package Overview
Dependencies
Maintainers
11
Versions
325
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest - npm Package Compare versions

Comparing version 26.4.7 to 26.5.0

5

lib/rules/consistent-test-it.js

@@ -53,4 +53,3 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -96,3 +95,3 @@ if (!jestFnCall) {

'CallExpression:exit'(node) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['describe'])) {
describeNestingLevel--;

@@ -99,0 +98,0 @@ }

4

lib/rules/expect-expect.js

@@ -79,3 +79,3 @@ "use strict";

const declaredVariables = context.getDeclaredVariables(node);
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context.getScope());
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
checkCallExpressionUsed(testCallExpressions);

@@ -97,3 +97,3 @@ }

if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test']) || additionalTestBlockFunctions.includes(name)) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test']) || additionalTestBlockFunctions.includes(name)) {
if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'todo')) {

@@ -100,0 +100,0 @@ return;

@@ -49,3 +49,3 @@ "use strict";

if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isTypeOfJestFnCall)(parent, context.getScope(), ['describe'])) {
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isTypeOfJestFnCall)(parent, context, ['describe'])) {
return;

@@ -73,3 +73,3 @@ }

if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, context.getScope(), ['describe'])) {
if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, context, ['describe'])) {
describeCallbackStack.pop();

@@ -76,0 +76,0 @@ }

@@ -42,3 +42,3 @@ "use strict";

const declaredVariables = context.getDeclaredVariables(node);
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context.getScope());
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);

@@ -51,3 +51,3 @@ if (testCallExpressions.length > 0) {

CallExpression(node) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCase = true;

@@ -76,3 +76,3 @@ }

'CallExpression:exit'(node) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCase = false;

@@ -79,0 +79,0 @@ }

@@ -40,3 +40,3 @@ "use strict";

CallExpression(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCase = true;

@@ -47,3 +47,3 @@ }

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCase = false;

@@ -50,0 +50,0 @@ }

@@ -36,3 +36,3 @@ "use strict";

CallExpression(node) {
const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -68,3 +68,3 @@ if (!jestFnCall) {

'CallExpression:exit'(node) {
const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -71,0 +71,0 @@ if (!jestFnCall) {

@@ -12,3 +12,3 @@ "use strict";

const findCallbackArg = (node, isJestEach, scope) => {
const findCallbackArg = (node, isJestEach, context) => {
if (isJestEach) {

@@ -18,3 +18,3 @@ return node.arguments[1];

const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -67,3 +67,3 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'hook' && node.arguments.length >= 1) {

const callback = findCallbackArg(node, isJestEach, context.getScope());
const callback = findCallbackArg(node, isJestEach, context);
const callbackArgIndex = Number(isJestEach);

@@ -70,0 +70,0 @@

@@ -32,4 +32,3 @@ "use strict";

const scope = context.getScope();
const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -60,3 +59,3 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'describe') {

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe'])) {
hookContexts.pop();

@@ -63,0 +62,0 @@ }

@@ -44,3 +44,3 @@ "use strict";

CallExpression(node) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
hasTestCase = true;

@@ -47,0 +47,0 @@ }

@@ -34,4 +34,3 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -38,0 +37,0 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe') {

@@ -42,3 +42,3 @@ "use strict";

CallExpression(node) {
const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -45,0 +45,0 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'hook' && !allow.includes(jestFnCall.name)) {

@@ -36,5 +36,4 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const currentLayer = contexts[contexts.length - 1];
const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -87,3 +86,3 @@ if (!jestFnCall) {

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe'])) {
contexts.pop();

@@ -90,0 +89,0 @@ }

@@ -61,3 +61,3 @@ "use strict";

CallExpression(node) {
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -79,3 +79,3 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'test') {

const declaredVariables = context.getDeclaredVariables(node);
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context.getScope());
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
stack.push(testCallExpressions.length > 0);

@@ -82,0 +82,0 @@ },

@@ -12,3 +12,3 @@ "use strict";

const getBlockType = (statement, scope) => {
const getBlockType = (statement, context) => {
const func = statement.parent;

@@ -34,3 +34,3 @@ /* istanbul ignore if */

if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(expr, scope, ['describe'])) {
if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(expr, context, ['describe'])) {
return 'describe';

@@ -78,3 +78,3 @@ }

const isTestBlock = node => (0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test']) || isCustomTestBlockFunction(node);
const isTestBlock = node => (0, _utils2.isTypeOfJestFnCall)(node, context, ['test']) || isCustomTestBlockFunction(node);

@@ -114,3 +114,3 @@ return {

BlockStatement(statement) {
const blockType = getBlockType(statement, context.getScope());
const blockType = getBlockType(statement, context);

@@ -123,3 +123,3 @@ if (blockType) {

'BlockStatement:exit'(statement) {
if (callStack[callStack.length - 1] === getBlockType(statement, context.getScope())) {
if (callStack[callStack.length - 1] === getBlockType(statement, context)) {
callStack.pop();

@@ -126,0 +126,0 @@ }

@@ -32,4 +32,3 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -36,0 +35,0 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test') {

@@ -41,3 +41,3 @@ "use strict";

CallExpression(node) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
return;

@@ -57,3 +57,3 @@ }

const declaredVariables = context.getDeclaredVariables(node);
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context.getScope());
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
if (testCallExpressions.length === 0) return;

@@ -60,0 +60,0 @@ const returnStmt = node.body.body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);

@@ -119,3 +119,3 @@ "use strict";

CallExpression(node) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCaseCall = true;

@@ -137,3 +137,3 @@ return;

'CallExpression:exit'(node) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
return;

@@ -140,0 +140,0 @@ }

@@ -38,3 +38,3 @@ "use strict";

const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -67,3 +67,3 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'hook') {

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['hook'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['hook'])) {
inHook = false;

@@ -70,0 +70,0 @@ return;

@@ -30,9 +30,7 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
if ((0, _utils.isTypeOfJestFnCall)(node, scope, ['test'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
hooksContext[hooksContext.length - 1] = true;
}
if (hooksContext[hooksContext.length - 1] && (0, _utils.isTypeOfJestFnCall)(node, scope, ['hook'])) {
if (hooksContext[hooksContext.length - 1] && (0, _utils.isTypeOfJestFnCall)(node, context, ['hook'])) {
context.report({

@@ -39,0 +37,0 @@ messageId: 'noHookOnTop',

@@ -83,4 +83,3 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -132,3 +131,3 @@ if (!jestFnCall || !hasStringAsFirstArgument(node)) {

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe'])) {
numberOfDescribeBlocks--;

@@ -135,0 +134,0 @@ }

@@ -109,5 +109,3 @@ "use strict";

'CallExpression:exit'(node) {
const scope = context.getScope();
if ((0, _utils.isTypeOfJestFnCall)(node, scope, ['describe', 'test'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe', 'test'])) {
var _depths$pop;

@@ -121,5 +119,3 @@

CallExpression(node) {
const scope = context.getScope();
if ((0, _utils.isTypeOfJestFnCall)(node, scope, ['describe', 'test'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe', 'test'])) {
depths.push(expressionDepth);

@@ -126,0 +122,0 @@ expressionDepth = 0;

@@ -63,3 +63,3 @@ "use strict";

const [title, callback] = node.arguments;
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -66,0 +66,0 @@ if (!title || (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test' || !isTargetedTestCase(jestFnCall) || !(0, _utils2.isStringNode)(title)) {

@@ -12,6 +12,6 @@ "use strict";

const isJestFnCall = (node, scope) => {
const isJestFnCall = (node, context) => {
var _getNodeName;
if ((0, _utils2.parseJestFnCall)(node, scope)) {
if ((0, _utils2.parseJestFnCall)(node, context)) {
return true;

@@ -27,9 +27,9 @@ }

const shouldBeInHook = (node, scope, allowedFunctionCalls = []) => {
const shouldBeInHook = (node, context, allowedFunctionCalls = []) => {
switch (node.type) {
case _utils.AST_NODE_TYPES.ExpressionStatement:
return shouldBeInHook(node.expression, scope, allowedFunctionCalls);
return shouldBeInHook(node.expression, context, allowedFunctionCalls);
case _utils.AST_NODE_TYPES.CallExpression:
return !(isJestFnCall(node, scope) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));
return !(isJestFnCall(node, context) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));

@@ -90,3 +90,3 @@ case _utils.AST_NODE_TYPES.VariableDeclaration:

for (const statement of body) {
if (shouldBeInHook(statement, context.getScope(), allowedFunctionCalls)) {
if (shouldBeInHook(statement, context, allowedFunctionCalls)) {
context.report({

@@ -106,3 +106,3 @@ node: statement,

CallExpression(node) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['describe']) || node.arguments.length < 2) {
if (!(0, _utils2.isTypeOfJestFnCall)(node, context, ['describe']) || node.arguments.length < 2) {
return;

@@ -109,0 +109,0 @@ }

@@ -49,4 +49,3 @@ "use strict";

CallExpression(node) {
const scope = context.getScope();
const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);

@@ -98,3 +97,3 @@ if (!jestFnCall) {

'CallExpression:exit'(node) {
if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe'])) {
numberOfDescribeBlocks--;

@@ -101,0 +100,0 @@ }

@@ -99,3 +99,3 @@ "use strict";

const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, scope) => {
const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context) => {
return declaredVariables.reduce((acc, {

@@ -105,3 +105,3 @@ references

identifier
}) => identifier.parent).filter(node => (node === null || node === void 0 ? void 0 : node.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, scope, ['test']))), []);
}) => identifier.parent).filter(node => (node === null || node === void 0 ? void 0 : node.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, context, ['test']))), []);
};

@@ -108,0 +108,0 @@ /**

@@ -13,4 +13,4 @@ "use strict";

const isTypeOfJestFnCall = (node, scope, types) => {
const jestFnCall = parseJestFnCall(node, scope);
const isTypeOfJestFnCall = (node, context, types) => {
const jestFnCall = parseJestFnCall(node, context);
return jestFnCall !== null && types.includes(jestFnCall.type);

@@ -71,3 +71,16 @@ };

const parseJestFnCall = (node, scope) => {
const resolvePossibleAliasedGlobal = (global, context) => {
var _context$settings$jes, _context$settings$jes2;
const globalAliases = (_context$settings$jes = (_context$settings$jes2 = context.settings.jest) === null || _context$settings$jes2 === void 0 ? void 0 : _context$settings$jes2.globalAliases) !== null && _context$settings$jes !== void 0 ? _context$settings$jes : {};
const alias = Object.entries(globalAliases).find(([, aliases]) => aliases.includes(global));
if (alias) {
return alias[0];
}
return null;
};
const parseJestFnCall = (node, context) => {
var _node$parent, _node$parent2, _resolved$original;

@@ -110,3 +123,3 @@

const resolved = resolveToJestFn(scope, (0, _utils2.getAccessorValue)(first)); // we're not a jest function
const resolved = resolveToJestFn(context, (0, _utils2.getAccessorValue)(first)); // we're not a jest function

@@ -272,4 +285,4 @@ if (!resolved) {

const resolveToJestFn = (scope, identifier) => {
const references = collectReferences(scope);
const resolveToJestFn = (context, identifier) => {
const references = collectReferences(context.getScope());
const maybeImport = references.imports.get(identifier);

@@ -298,3 +311,3 @@

return {
original: null,
original: resolvePossibleAliasedGlobal(identifier, context),
local: identifier,

@@ -301,0 +314,0 @@ type: 'global'

@@ -44,3 +44,3 @@ "use strict";

CallExpression(node) {
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context.getScope());
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -47,0 +47,0 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe') {

@@ -55,4 +55,4 @@ "use strict";

const isTestCaseCallWithCallbackArg = (node, scope) => {
const jestCallFn = (0, _utils2.parseJestFnCall)(node, scope);
const isTestCaseCallWithCallbackArg = (node, context) => {
const jestCallFn = (0, _utils2.parseJestFnCall)(node, context);

@@ -256,3 +256,3 @@ if ((jestCallFn === null || jestCallFn === void 0 ? void 0 : jestCallFn.type) !== 'test') {

const isDirectlyWithinTestCaseCall = (node, scope) => {
const isDirectlyWithinTestCaseCall = (node, context) => {
let parent = node;

@@ -265,3 +265,3 @@

parent = parent.parent;
return ((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, scope, ['test']);
return ((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, context, ['test']);
}

@@ -316,3 +316,3 @@

// promises that contain expect that would make the promise safe for us
if (isTestCaseCallWithCallbackArg(node, context.getScope())) {
if (isTestCaseCallWithCallbackArg(node, context)) {
inTestCaseWithDoneCallback = true;

@@ -341,3 +341,3 @@ return;

if (inTestCaseWithDoneCallback) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
inTestCaseWithDoneCallback = false;

@@ -369,3 +369,3 @@ }

if (!parent || !isDirectlyWithinTestCaseCall(parent, context.getScope())) {
if (!parent || !isDirectlyWithinTestCaseCall(parent, context)) {
return;

@@ -372,0 +372,0 @@ }

@@ -133,4 +133,3 @@ "use strict";

const scope = context.getScope();
const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);

@@ -137,0 +136,0 @@ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test') {

{
"name": "eslint-plugin-jest",
"version": "26.4.7",
"version": "26.5.0",
"description": "ESLint rules for Jest",

@@ -5,0 +5,0 @@ "keywords": [

@@ -62,2 +62,21 @@ <div align="center">

#### Aliased Jest globals
You can tell this plugin about any global Jests you have aliased using the
`globalAliases` setting:
```json
{
"settings": {
"jest": {
"globalAliases": {
"describe": ["context"],
"fdescribe": ["fcontext"],
"xdescribe": ["xcontext"]
}
}
}
}
```
### Running rules only on test-related files

@@ -64,0 +83,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