Skip to content

Commit 9ab5e4e

Browse files
netkardamShelex
authored andcommitted
remove js optional chaining expressions
1 parent 6282855 commit 9ab5e4e

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineConfig([
3232
Cypress: true
3333
},
3434

35-
ecmaVersion: 2022,
35+
ecmaVersion: 2018,
3636
sourceType: 'module'
3737
},
3838

reporter/allure-cypress/AllureReporter.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ module.exports = class AllureReporter {
8282
get testNameForAttachment() {
8383
const cyTest = cy.state().test;
8484
return (
85-
cyTest?.title ||
86-
this.currentTest?.info.name ||
85+
(cyTest && cyTest.title) ||
86+
(this.currentTest && this.currentTest.info.name) ||
8787
this.previousTestName
8888
);
8989
}
@@ -244,15 +244,19 @@ module.exports = class AllureReporter {
244244
this.currentTest.info.stage = Stage.RUNNING;
245245
this.addPackageLabel();
246246

247-
if (config?.clearFilesForPreviousAttempt() && test._currentRetry > 0) {
247+
if (
248+
config &&
249+
config.clearFilesForPreviousAttempt() &&
250+
test._currentRetry > 0
251+
) {
248252
logger.allure(`clearing screenshots from previous retries`);
249253
// remove screenshots from previous attempt
250254
this.files = this.files.filter(
251255
(file) => file.testName !== test.title
252256
);
253257
}
254258

255-
if (config?.addAnalyticLabels()) {
259+
if (config && config.addAnalyticLabels()) {
256260
logger.allure(`adding analytic labels`);
257261
this.currentTest.addLabel(LabelName.FRAMEWORK, 'Cypress');
258262
const language = languageLabel(test);
@@ -387,9 +391,12 @@ module.exports = class AllureReporter {
387391
}
388392

389393
finishRemainingSteps(status = Status.PASSED) {
390-
const alreadyHasFailedStep = this.currentTest?.info?.steps.some(
391-
(step) => step.status === Status.FAILED
392-
);
394+
const alreadyHasFailedStep =
395+
this.currentTest &&
396+
this.currentTest.info &&
397+
this.currentTest.info.steps.some(
398+
(step) => step.status === Status.FAILED
399+
);
393400

394401
this.steps.forEach((step) => {
395402
step.info.stage = Stage.FINISHED;
@@ -474,7 +481,7 @@ module.exports = class AllureReporter {
474481

475482
// in case hook is a step we should complete it
476483
if (this.originalNameOf(hook).includes('each')) {
477-
this.currentHook?.endStep();
484+
this.currentHook && this.currentHook.endStep();
478485
}
479486
!isAllureReport && !failed && (this.currentHook = null);
480487
this.finishRemainingSteps(currentHookInfo.status);
@@ -527,7 +534,8 @@ module.exports = class AllureReporter {
527534
}
528535
// update test, which may had a pending event previously
529536
if (
530-
test?.state &&
537+
test &&
538+
test.state &&
531539
[Status.FAILED, Status.PASSED, Status.SKIPPED].includes(test.state)
532540
) {
533541
this.updateTest(

reporter/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@ const config = {
7575
};
7676

7777
const invokeResultsWriter = (allure, isGlobal) => {
78-
if (!config?.allureEnabled()) {
78+
if (!config || !config.allureEnabled()) {
7979
return;
8080
}
8181
try {
8282
clearAllureHookStepsFromTests(
83-
allure.reporter.runtime.config?.writer?.tests,
83+
allure &&
84+
allure.reporter &&
85+
allure.reporter.runtime &&
86+
allure.reporter.runtime.config &&
87+
allure.reporter.runtime.config.writer &&
88+
allure.reporter.runtime.config.writer.tests,
8489
config.logAllureHooksEnabled()
8590
);
8691
return cy
@@ -207,7 +212,10 @@ class CypressAllureReporter {
207212
if (log.state === 'failed') {
208213
logger.cy('found failed log:added %O', log);
209214

210-
if (this.reporter.currentExecutable?.info) {
215+
if (
216+
this.reporter.currentExecutable &&
217+
this.reporter.currentExecutable.info
218+
) {
211219
this.reporter.currentExecutable.info.status = 'failed';
212220
}
213221
}
@@ -233,7 +241,7 @@ class CypressAllureReporter {
233241
logger.cy(`found gherkin step, creating allure entity`);
234242
const step = this.reporter.cy.startStep(command, {
235243
...log,
236-
displayName: log?.displayName || log.name,
244+
displayName: (log && log.displayName) || log.name,
237245
name: 'step'
238246
});
239247

@@ -292,7 +300,9 @@ Cypress.Screenshot.defaults({
292300
logger.cy(`onAfterScreenshot: %O`, details);
293301
setTestIdToScreenshot(
294302
config.allureEnabled(),
295-
Cypress.Allure?.reporter?.mochaIdToAllure,
303+
Cypress.Allure &&
304+
Cypress.Allure.reporter &&
305+
Cypress.Allure.reporter.mochaIdToAllure,
296306
details
297307
);
298308
if (

reporter/patching.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const reorderAllureHooksGeneric = (
4242
};
4343

4444
const clearAllureHookSteps = (test, allureLogHooks = false) => {
45-
if (!test?.steps?.length) {
45+
if (!(test && test.steps && test.steps.length)) {
4646
return test;
4747
}
4848

@@ -98,13 +98,13 @@ const isLastRootHook = () => {
9898
}
9999
const { hookName } = currentRunnable;
100100
let rootSuite = currentRunnable.parent;
101-
while (rootSuite?.parent && !rootSuite.root) {
101+
while (rootSuite && rootSuite.parent && !rootSuite.root) {
102102
rootSuite = rootSuite.parent;
103103
}
104104
if (!rootSuite) {
105105
return false;
106106
}
107-
const hooks = rootSuite?.hooks || [];
107+
const hooks = (rootSuite && rootSuite.hooks) || [];
108108
const lastHook = hooks.findLast((h) => h.hookName === hookName);
109109

110110
return lastHook && lastHook.hookId === currentRunnable.hookId;
@@ -114,7 +114,7 @@ const setTestIdToScreenshot = (allureEnabled, mochaIdToAllure, details) => {
114114
if (allureEnabled) {
115115
let currentTest = cy.state('test');
116116
if (details && currentTest && mochaIdToAllure) {
117-
const testIds = mochaIdToAllure[currentTest?.id];
117+
const testIds = mochaIdToAllure[currentTest && currentTest.id];
118118
if (testIds) {
119119
details['testId'] = currentTest.id;
120120
let testId = testIds.at(-1);

writer/attachments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const attachScreenshotsAndVideo = (allureMapping, results, config) => {
2222

2323
const needVideo = results.tests.filter((test, index) => {
2424
let shouldAttachVideo = false;
25-
test.testId = test?.testId || testIdIndex[index];
25+
test.testId = (test && test.testId) || testIdIndex[index];
2626
const testIds = allureMapping[test.testId];
2727
if (!testIds) {
2828
return false;

writer/handleMultiDomain.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const sanitizeSuites = (folder, files = [], isGlobal = false) => {
7575
continue;
7676
}
7777

78-
if (child?.steps?.length) {
78+
if (child && child.steps && child.steps.length) {
7979
logger.writer('child %s %s has steps', child.uuid, child.name);
8080
continue;
8181
}
@@ -84,7 +84,8 @@ const sanitizeSuites = (folder, files = [], isGlobal = false) => {
8484
(file) =>
8585
file.historyId === child.historyId &&
8686
file.uuid !== child.uuid &&
87-
file?.steps?.length
87+
file.steps &&
88+
file.steps.length
8889
);
8990

9091
duplicates.sort((a, b) => a.start - b.start);

0 commit comments

Comments
 (0)