From 52c89129ebd9f43661de2fb1813dd980a5eaa415 Mon Sep 17 00:00:00 2001 From: javierbrea Date: Tue, 15 Aug 2023 20:19:54 +0200 Subject: [PATCH] refactor: Use optional chain expressions --- .eslintrc.json | 2 +- CHANGELOG.md | 1 + src/helpers/cypress.js | 16 +++++----------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 858d392..f8961da 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,7 @@ "es6": true }, "parserOptions": { - "ecmaVersion": "2018" + "ecmaVersion": 2022 }, "plugins": ["prettier"], "rules": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a64d8e..4d6cc1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - chore(deps): Update devDependencies - chore(deps): Use NodeJs 16.x, 18.x and 20.x in pipelines - refactor: Remove redundant double negation +- refactor: Use optional chain expressions ### Added - chore: Handle concurrency in pipelines diff --git a/src/helpers/cypress.js b/src/helpers/cypress.js index 38c25af..5eb6f56 100644 --- a/src/helpers/cypress.js +++ b/src/helpers/cypress.js @@ -1,5 +1,5 @@ function isHeaded(Cypress) { - return Cypress.browser && Cypress.browser.isHeaded; + return Cypress.browser?.isHeaded; } function testHasFailed(currentTest) { @@ -55,22 +55,16 @@ function getTestConfig(test) { } // Cypress >9 if ( - test.ctx && - test.ctx.test && - test.ctx.test._testConfig && - test.ctx.test._testConfig.testConfigList && - test.ctx.test._testConfig.testConfigList[ - test.ctx.test._testConfig.testConfigList.length - 1 - ] && - test.ctx.test._testConfig.testConfigList[test.ctx.test._testConfig.testConfigList.length - 1] - .overrides + test.ctx?.test?._testConfig?.testConfigList?.[ + test.ctx?.test?._testConfig?.testConfigList?.length - 1 + ]?.overrides ) { return test.ctx.test._testConfig.testConfigList[ test.ctx.test._testConfig.testConfigList.length - 1 ].overrides; } // Cypress >6.7 - if (test.ctx && test.ctx.test && test.ctx.test._testConfig) { + if (test.ctx?.test?._testConfig) { return test.ctx.test._testConfig; } return {};