diff --git a/benchmarks/runtime.bench.js b/benchmarks/runtime.bench.js index 9906f5a..94f7609 100644 --- a/benchmarks/runtime.bench.js +++ b/benchmarks/runtime.bench.js @@ -86,7 +86,7 @@ function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) { describe('runtime', () => { it('should not take longer as the defined budget to lint many files with the recommended config', () => { const nodeVersionMultiplier = getNodeVersionMultiplier(); - const budget = 80000000 / cpuSpeed * nodeVersionMultiplier; + const budget = 70000000 / cpuSpeed * nodeVersionMultiplier; const { medianDuration } = runBenchmark(() => { lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 }); diff --git a/lib/rules/no-exclusive-tests.js b/lib/rules/no-exclusive-tests.js index 862bb05..8fc25cc 100644 --- a/lib/rules/no-exclusive-tests.js +++ b/lib/rules/no-exclusive-tests.js @@ -12,11 +12,13 @@ module.exports = { create(context) { const astUtils = createAstUtils(context.settings); + const options = { modifiers: [ 'only' ], modifiersOnly: true }; + const isDescribe = astUtils.buildIsDescribeAnswerer(options); + const isTestCase = astUtils.buildIsTestCaseAnswerer(options); + return { CallExpression(node) { - const options = { modifiers: [ 'only' ], modifiersOnly: true }; - - if (astUtils.isDescribe(node, options) || astUtils.isTestCase(node, options)) { + if (isDescribe(node) || isTestCase(node)) { const callee = node.callee; context.report({ diff --git a/lib/rules/no-pending-tests.js b/lib/rules/no-pending-tests.js index e9c182e..db97e4f 100644 --- a/lib/rules/no-pending-tests.js +++ b/lib/rules/no-pending-tests.js @@ -11,9 +11,10 @@ module.exports = { }, create(context) { const astUtils = createAstUtils(context.settings); + const isTestCase = astUtils.buildIsTestCaseAnswerer(); function isPendingMochaTest(node) { - return astUtils.isTestCase(node) && + return isTestCase(node) && node.arguments.length === 1 && node.arguments[0].type === 'Literal'; } diff --git a/lib/util/ast.js b/lib/util/ast.js index d2e2bba..95fe823 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -63,21 +63,30 @@ function isFunctionCallWithName(node, names) { return isCallExpression(node) && names.includes(getNodeName(node.callee)); } +// eslint-disable-next-line max-statements function createAstUtils(settings) { const additionalCustomNames = getAddtionalNames(settings); - function isDescribe(node, options = {}) { + function buildIsDescribeAnswerer(options) { const { modifiers = [ 'skip', 'only' ], modifiersOnly = false } = options; const describeAliases = getSuiteNames({ modifiersOnly, modifiers, additionalCustomNames }); - return isFunctionCallWithName(node, describeAliases); + return (node) => isFunctionCallWithName(node, describeAliases); } - function isTestCase(node, options = {}) { + function isDescribe(node, options = {}) { + return buildIsDescribeAnswerer(options)(node); + } + + function buildIsTestCaseAnswerer(options = {}) { const { modifiers = [ 'skip', 'only' ], modifiersOnly = false } = options; const testCaseNames = getTestCaseNames({ modifiersOnly, modifiers, additionalCustomNames }); - return isFunctionCallWithName(node, testCaseNames); + return (node) => isFunctionCallWithName(node, testCaseNames); + } + + function isTestCase(node, options = {}) { + return buildIsTestCaseAnswerer(options)(node); } function isSuiteConfigExpression(node) { @@ -132,7 +141,9 @@ function createAstUtils(settings) { isSuiteConfigCall, hasParentMochaFunctionCall, findReturnStatement, - isReturnOfUndefined + isReturnOfUndefined, + buildIsDescribeAnswerer, + buildIsTestCaseAnswerer }; }