eslint-plugin-jest
Advanced tools
Comparing version 21.8.0 to 21.9.0
# Enforce valid `describe()` callback (valid-describe) | ||
Using an improper `describe()` callback function can lead to unexpected test errors. | ||
Using an improper `describe()` callback function can lead to unexpected test | ||
errors. | ||
## Rule Details | ||
This rule validates that the second parameter of a `describe()` function is a callback function. This callback function: | ||
This rule validates that the second parameter of a `describe()` function is a | ||
callback function. This callback function: | ||
* should not be [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) | ||
* should not be | ||
[async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) | ||
* should not contain any parameters | ||
@@ -11,0 +14,0 @@ * should not contain any `return` statements |
'use strict'; | ||
const consistentTestIt = require('./rules/consistent-test-it'); | ||
const noDisabledTests = require('./rules/no-disabled-tests'); | ||
@@ -60,2 +61,3 @@ const noFocusedTests = require('./rules/no-focused-tests'); | ||
rules: { | ||
'consistent-test-it': consistentTestIt, | ||
'no-disabled-tests': noDisabledTests, | ||
@@ -62,0 +64,0 @@ 'no-focused-tests': noFocusedTests, |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "21.8.0", | ||
"version": "21.9.0", | ||
"description": "Eslint rules for Jest", | ||
"repository": "jest-community/eslint-plugin-jest", | ||
"license": "MIT", | ||
"keywords": ["eslint", "eslintplugin", "eslint-plugin"], | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"eslint-plugin" | ||
], | ||
"author": { | ||
@@ -13,3 +17,11 @@ "name": "Jonathan Kim", | ||
}, | ||
"files": ["docs/", "rules/", "processors/", "index.js"], | ||
"files": [ | ||
"docs/", | ||
"rules/", | ||
"processors/", | ||
"index.js" | ||
], | ||
"engines": { | ||
"node": ">= 4" | ||
}, | ||
"peerDependencies": { | ||
@@ -20,2 +32,3 @@ "eslint": ">=3.6" | ||
"lint": "eslint . --ignore-pattern '!.eslintrc.js'", | ||
"prettylint": "prettylint docs/**/*.md README.md package.json", | ||
"test": "jest", | ||
@@ -31,2 +44,3 @@ "precommit": "lint-staged", | ||
"eslint-plugin-eslint-plugin": "^1.4.0", | ||
"eslint-plugin-node": "^6.0.0", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
@@ -37,2 +51,3 @@ "husky": "^0.14.3", | ||
"prettier": "^1.10.2", | ||
"prettylint": "^1.0.0", | ||
"semantic-release": "^12.2.2", | ||
@@ -42,2 +57,3 @@ "travis-deploy-once": "^4.3.1" | ||
"prettier": { | ||
"proseWrap": "always", | ||
"singleQuote": true, | ||
@@ -47,4 +63,10 @@ "trailingComma": "es5" | ||
"lint-staged": { | ||
"*.js": ["eslint --fix", "git add"], | ||
"*.{md,json}": ["prettier --write", "git add"] | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
], | ||
"*.{md,json}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
@@ -55,4 +77,6 @@ "jest": { | ||
"commitlint": { | ||
"extends": ["@commitlint/config-conventional"] | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
} | ||
} |
@@ -83,2 +83,3 @@ [![Build Status](https://travis-ci.org/jest-community/eslint-plugin-jest.svg?branch=master)](https://travis-ci.org/jest-community/eslint-plugin-jest) | ||
| ------------------------------------------------------------------ | --------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | | ||
| [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce consistent test or it keyword | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | | ||
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | | ||
@@ -85,0 +86,0 @@ | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | |
@@ -14,3 +14,2 @@ 'use strict'; | ||
valid: [ | ||
'describe("foo")', | ||
'describe("foo", function() {})', | ||
@@ -41,2 +40,27 @@ 'describe("foo", () => {})', | ||
{ | ||
code: 'describe(() => {})', | ||
errors: [ | ||
{ | ||
message: 'First argument must be name', | ||
line: 1, | ||
column: 10, | ||
}, | ||
{ | ||
message: 'Describe requires name and callback arguments', | ||
line: 1, | ||
column: 10, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'describe("foo")', | ||
errors: [ | ||
{ | ||
message: 'Describe requires name and callback arguments', | ||
line: 1, | ||
column: 10, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'describe("foo", async () => {})', | ||
@@ -43,0 +67,0 @@ errors: [{ message: 'No async describe callback', line: 1, column: 17 }], |
'use strict'; | ||
const isDescribe = require('./util').isDescribe; | ||
const isTestCase = require('./util').isTestCase; | ||
const testCaseNames = Object.assign(Object.create(null), { | ||
fit: true, | ||
it: true, | ||
'it.only': true, | ||
'it.skip': true, | ||
test: true, | ||
'test.only': true, | ||
'test.skip': true, | ||
xit: true, | ||
xtest: true, | ||
}); | ||
const getNodeName = node => { | ||
if (node.type === 'MemberExpression') { | ||
return node.object.name + '.' + node.property.name; | ||
} | ||
return node.name; | ||
}; | ||
const isTestCase = node => | ||
node && | ||
node.type === 'CallExpression' && | ||
testCaseNames[getNodeName(node.callee)]; | ||
const newDescribeContext = () => ({ | ||
@@ -30,0 +7,0 @@ describeTitles: [], |
@@ -5,3 +5,3 @@ 'use strict'; | ||
node.callee.name === 'expect' && | ||
node.arguments.length == 1 && | ||
node.arguments.length === 1 && | ||
node.parent && | ||
@@ -92,2 +92,14 @@ node.parent.type === 'MemberExpression' && | ||
const testCaseNames = Object.assign(Object.create(null), { | ||
fit: true, | ||
it: true, | ||
'it.only': true, | ||
'it.skip': true, | ||
test: true, | ||
'test.only': true, | ||
'test.skip': true, | ||
xit: true, | ||
xtest: true, | ||
}); | ||
const getNodeName = node => { | ||
@@ -100,2 +112,7 @@ if (node.type === 'MemberExpression') { | ||
const isTestCase = node => | ||
node && | ||
node.type === 'CallExpression' && | ||
testCaseNames[getNodeName(node.callee)]; | ||
const isDescribe = node => | ||
@@ -122,4 +139,6 @@ node.type === 'CallExpression' && describeAliases[getNodeName(node.callee)]; | ||
expectNotToBeUndefinedCase: expectNotToBeUndefinedCase, | ||
getNodeName: getNodeName, | ||
isDescribe: isDescribe, | ||
isFunction: isFunction, | ||
isTestCase: isTestCase, | ||
}; |
@@ -36,3 +36,16 @@ 'use strict'; | ||
if (isDescribe(node)) { | ||
const name = node.arguments[0]; | ||
const callbackFunction = node.arguments[1]; | ||
if (name.type !== 'Literal') { | ||
context.report({ | ||
message: 'First argument must be name', | ||
loc: paramsLocation(node.arguments), | ||
}); | ||
} | ||
if (callbackFunction === undefined) { | ||
context.report({ | ||
message: 'Describe requires name and callback arguments', | ||
loc: paramsLocation(node.arguments), | ||
}); | ||
} | ||
if (callbackFunction && isFunction(callbackFunction)) { | ||
@@ -39,0 +52,0 @@ if (isAsync(callbackFunction)) { |
@@ -11,3 +11,3 @@ 'use strict'; | ||
node.property && | ||
(node.property.name == 'then' || node.property.name == 'catch') | ||
(node.property.name === 'then' || node.property.name === 'catch') | ||
); | ||
@@ -31,3 +31,3 @@ }; | ||
expression && | ||
expression.type == 'CallExpression' && | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
@@ -91,4 +91,4 @@ expression.callee.object.type === 'CallExpression' && | ||
return ( | ||
testFunctionBody.type == 'CallExpression' || | ||
node.parent.parent.type == 'ReturnStatement' || | ||
testFunctionBody.type === 'CallExpression' || | ||
node.parent.parent.type === 'ReturnStatement' || | ||
isPromiseReturnedLater(node, testFunctionBody) || | ||
@@ -119,3 +119,3 @@ isThenOrCatch(node.parent.parent) | ||
const isAwaitExpression = node => { | ||
return node.parent.parent && node.parent.parent.type == 'AwaitExpression'; | ||
return node.parent.parent && node.parent.parent.type === 'AwaitExpression'; | ||
}; | ||
@@ -142,5 +142,5 @@ | ||
if ( | ||
node.type == 'MemberExpression' && | ||
node.type === 'MemberExpression' && | ||
isThenOrCatch(node) && | ||
node.parent.type == 'CallExpression' && | ||
node.parent.type === 'CallExpression' && | ||
!isAwaitExpression(node) | ||
@@ -147,0 +147,0 @@ ) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103091
43
2925
100
14