From b8fd70beb1169fd7aa969f638b05b5e11a1a331c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 5 Mar 2021 09:45:59 +0100 Subject: [PATCH 1/5] Speed up AST utils --- lib/rules/no-exclusive-tests.js | 8 +++++--- lib/rules/no-pending-tests.js | 3 ++- lib/util/ast.js | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) 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..87b2025 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -66,18 +66,26 @@ function isFunctionCallWithName(node, names) { 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 +140,9 @@ function createAstUtils(settings) { isSuiteConfigCall, hasParentMochaFunctionCall, findReturnStatement, - isReturnOfUndefined + isReturnOfUndefined, + buildIsDescribeAnswerer, + buildIsTestCaseAnswerer, }; } From a10d920a85f161d63516cdfffcc1f456ba939a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 5 Mar 2021 10:07:39 +0100 Subject: [PATCH 2/5] Apply linter fixes, but ignore max-statements for 'createAstUtils' --- lib/util/ast.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/util/ast.js b/lib/util/ast.js index 87b2025..95fe823 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -63,6 +63,7 @@ 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); @@ -74,7 +75,7 @@ function createAstUtils(settings) { } function isDescribe(node, options = {}) { - return (buildIsDescribeAnswerer(options))(node); + return buildIsDescribeAnswerer(options)(node); } function buildIsTestCaseAnswerer(options = {}) { @@ -85,7 +86,7 @@ function createAstUtils(settings) { } function isTestCase(node, options = {}) { - return (buildIsTestCaseAnswerer(options))(node); + return buildIsTestCaseAnswerer(options)(node); } function isSuiteConfigExpression(node) { @@ -142,7 +143,7 @@ function createAstUtils(settings) { findReturnStatement, isReturnOfUndefined, buildIsDescribeAnswerer, - buildIsTestCaseAnswerer, + buildIsTestCaseAnswerer }; } From 153609a6e363fe039bbb49d76cb8b4506730b347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 5 Mar 2021 10:43:17 +0100 Subject: [PATCH 3/5] Update runtime CPU budget --- benchmarks/runtime.bench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/runtime.bench.js b/benchmarks/runtime.bench.js index 7560444..d883c4c 100644 --- a/benchmarks/runtime.bench.js +++ b/benchmarks/runtime.bench.js @@ -85,7 +85,7 @@ function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) { describe('runtime', () => { it('should not take longer as the defined budget to lint many files with the recommended config', () => { - const budget = 80000000 / cpuSpeed; + const budget = 60000000 / cpuSpeed; const { medianDuration } = runBenchmark(() => { lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 }); From f5ed7338c5aa9801c13c63e3f902e005503f43c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 5 Mar 2021 11:46:40 +0100 Subject: [PATCH 4/5] Revert "Update runtime CPU budget" CQ doesn't like the reduced budget. This reverts commit 153609a6e363fe039bbb49d76cb8b4506730b347. --- benchmarks/runtime.bench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/runtime.bench.js b/benchmarks/runtime.bench.js index d883c4c..7560444 100644 --- a/benchmarks/runtime.bench.js +++ b/benchmarks/runtime.bench.js @@ -85,7 +85,7 @@ function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) { describe('runtime', () => { it('should not take longer as the defined budget to lint many files with the recommended config', () => { - const budget = 60000000 / cpuSpeed; + const budget = 80000000 / cpuSpeed; const { medianDuration } = runBenchmark(() => { lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 }); From 1a69e88ea0eaf51249df06060c6786681183f5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 5 Mar 2021 12:56:36 +0100 Subject: [PATCH 5/5] Re-apply lower budget after benchmark runner has been updated --- benchmarks/runtime.bench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 });