[Libreoffice-commits] online.git: cypress_test/eslint_plugin cypress_test/.eslintrc
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 1 12:10:16 UTC 2020
cypress_test/.eslintrc | 3 ++-
cypress_test/eslint_plugin/index.js | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
New commits:
commit 8853547ee0c414a894ef97f949e8af64d583af18
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Jun 1 13:22:14 2020 +0200
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Mon Jun 1 14:09:53 2020 +0200
cypress: add no-get-invoke-match-chain rule.
We can avoid retriability problems caused by using
this long chain as an indicator in tests.
Change-Id: Iec78087d080c3759e446a061222eb4d9f4dd3ae5
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95280
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
diff --git a/cypress_test/.eslintrc b/cypress_test/.eslintrc
index 19001679f..2a4452399 100644
--- a/cypress_test/.eslintrc
+++ b/cypress_test/.eslintrc
@@ -2,7 +2,8 @@
"extends": "../loleaflet/.eslintrc",
"plugins": ["cypress-rules"],
"rules": {
- "cypress-rules/no-get-contains-chain": 2
+ "cypress-rules/no-get-contains-chain": 2,
+ "cypress-rules/no-get-invoke-match-chain": 2
},
"parserOptions": {
"ecmaVersion": 6,
diff --git a/cypress_test/eslint_plugin/index.js b/cypress_test/eslint_plugin/index.js
index 4c2d71c16..d69d2ff60 100644
--- a/cypress_test/eslint_plugin/index.js
+++ b/cypress_test/eslint_plugin/index.js
@@ -26,6 +26,35 @@ module.exports = {
}
};
}
+ },
+ 'no-get-invoke-match-chain': {
+ /**
+ * Catches cy.get(selector).invoke('text').should('match',...) calls in the code.
+ *
+ * Issue: In cypress test framework only the last getter command is retried.
+ * In this case it's the invoke method and so the get() method is
+ * not retried. Sometimes, it behaves unexpectedly, because the test
+ * retries to call the text method on an element, which might be removed
+ * in the meantime. Instead of searching for a new element matching both
+ * with the selector and the regular expression.
+ *
+ * Fix: We can use cy.contains(seletor, regexp) method instead.
+ * This is a compact command which will retry to match both the
+ * selector and the text matcher.
+ *
+ **/
+ create: function(context) {
+ return {
+ 'CallExpression[callee.property.name=\'should\'][callee.object.callee.property.name=\'invoke\'][callee.object.callee.object.callee.property.name=\'get\']': function(expr) {
+ if (expr.arguments && expr.arguments.length === 2 && expr.arguments[0].value === 'match' &&
+ expr.callee.object.arguments &&
+ expr.callee.object.arguments.length === 1 &&
+ expr.callee.object.arguments[0].value === 'text') {
+ context.report(expr, 'Do not use this long chain for matching text. Use cy.contains(selector, regexp) instead for better retriability!');
+ }
+ }
+ };
+ }
}
}
};
More information about the Libreoffice-commits
mailing list