Skip to content

Commit a5a270a

Browse files
authored
ESLint: Run linter on Cypress support file (#6026)
1 parent 32fae9b commit a5a270a

File tree

5 files changed

+68
-28
lines changed

5 files changed

+68
-28
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dev,benchmark,MIT,Copyright 2010-2016 Mathias Bynens Robert Kieffer John-David D
4444
dev,body-parser,MIT,Copyright 2014 Jonathan Ong 2014-2015 Douglas Christopher Wilson
4545
dev,chai,MIT,Copyright 2017 Chai.js Assertion Library
4646
dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundation
47+
dev,eslint-plugin-cypress,MIT,Copyright (c) 2019 Cypress.io
4748
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
4849
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
4950
dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import eslintPluginJs from '@eslint/js'
22
import eslintPluginStylistic from '@stylistic/eslint-plugin'
3+
import eslintPluginCypress from 'eslint-plugin-cypress'
34
import eslintPluginImport from 'eslint-plugin-import'
45
import eslintPluginMocha from 'eslint-plugin-mocha'
56
import eslintPluginN from 'eslint-plugin-n'
@@ -406,6 +407,12 @@ export default [
406407
'unicorn/switch-case-braces': 'off', // Questionable benefit
407408
}
408409
},
410+
{
411+
...eslintPluginCypress.configs.recommended,
412+
files: [
413+
'packages/datadog-plugin-cypress/src/support.js'
414+
]
415+
},
409416
{
410417
name: 'mocha/recommended',
411418
...eslintPluginMocha.configs.flat.recommended,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"body-parser": "^2.2.0",
133133
"chai": "^4.5.0",
134134
"eslint": "^9.29.0",
135+
"eslint-plugin-cypress": "^5.1.0",
135136
"eslint-plugin-import": "^2.32.0",
136137
"eslint-plugin-mocha": "^10.5.0",
137138
"eslint-plugin-n": "^17.20.0",

packages/datadog-plugin-cypress/src/support.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable unicorn/no-abusive-eslint-disable */
2-
/* eslint-disable */
31
let isEarlyFlakeDetectionEnabled = false
42
let isKnownTestsEnabled = false
53
let knownTestsForSuite = []
@@ -20,7 +18,7 @@ let originalWindow
2018
function safeGetRum (window) {
2119
try {
2220
return window.DD_RUM
23-
} catch (e) {
21+
} catch {
2422
return null
2523
}
2624
}
@@ -30,12 +28,13 @@ function isNewTest (test) {
3028
}
3129

3230
function getTestProperties (testName) {
33-
// We neeed to do it in this way because of compatibility with older versions as '?' is not supported in older versions of Cypress
34-
const properties = testManagementTests[testName] && testManagementTests[testName].properties || {};
31+
// We neeed to do it in this way because of compatibility with older versions as '?' is not supported in older
32+
// versions of Cypress
33+
const properties = testManagementTests[testName] && testManagementTests[testName].properties || {}
3534

36-
const { attempt_to_fix: isAttemptToFix, disabled: isDisabled, quarantined: isQuarantined } = properties;
35+
const { attempt_to_fix: isAttemptToFix, disabled: isDisabled, quarantined: isQuarantined } = properties
3736

38-
return { isAttemptToFix, isDisabled, isQuarantined };
37+
return { isAttemptToFix, isDisabled, isQuarantined }
3938
}
4039

4140
function retryTest (test, suiteTests, numRetries, tags) {
@@ -63,11 +62,9 @@ Cypress.mocha.getRunner().runTests = function (suite, fn) {
6362

6463
const { isAttemptToFix } = getTestProperties(testName)
6564

66-
if (isTestManagementEnabled) {
67-
if (isAttemptToFix && !test.isPending()) {
68-
test._ddIsAttemptToFix = true
69-
retryTest(test, suite.tests, testManagementAttemptToFixRetries, ['_ddIsAttemptToFix'])
70-
}
65+
if (isTestManagementEnabled && isAttemptToFix && !test.isPending()) {
66+
test._ddIsAttemptToFix = true
67+
retryTest(test, suite.tests, testManagementAttemptToFixRetries, ['_ddIsAttemptToFix'])
7168
}
7269
if (isImpactedTestsEnabled && isModifiedTest) {
7370
test._ddIsModified = true
@@ -80,15 +77,13 @@ Cypress.mocha.getRunner().runTests = function (suite, fn) {
8077
)
8178
}
8279
}
83-
if (isKnownTestsEnabled) {
84-
if (!test._ddIsNew && !test.isPending() && isNewTest(test)) {
85-
test._ddIsNew = true
86-
if (isImpactedTestsEnabled && isModifiedTest) {
87-
test._ddIsModified = true
88-
}
89-
if (isEarlyFlakeDetectionEnabled && !isAttemptToFix && !isModifiedTest) {
90-
retryTest(test, suite.tests, earlyFlakeDetectionNumRetries, ['_ddIsNew', '_ddIsEfdRetry'])
91-
}
80+
if (isKnownTestsEnabled && !test._ddIsNew && !test.isPending() && isNewTest(test)) {
81+
test._ddIsNew = true
82+
if (isImpactedTestsEnabled && isModifiedTest) {
83+
test._ddIsModified = true
84+
}
85+
if (isEarlyFlakeDetectionEnabled && !isAttemptToFix && !isModifiedTest) {
86+
retryTest(test, suite.tests, earlyFlakeDetectionNumRetries, ['_ddIsNew', '_ddIsEfdRetry'])
9287
}
9388
}
9489
})
@@ -135,12 +130,11 @@ after(() => {
135130
if (safeGetRum(originalWindow)) {
136131
originalWindow.dispatchEvent(new Event('beforeunload'))
137132
}
138-
} catch (e) {
133+
} catch {
139134
// ignore error. It's usually a multi origin issue.
140135
}
141136
})
142137

143-
144138
afterEach(function () {
145139
const currentTest = Cypress.mocha.getRunner().suite.ctx.currentTest
146140
const testInfo = {
@@ -156,15 +150,15 @@ afterEach(function () {
156150
}
157151
try {
158152
testInfo.testSourceLine = Cypress.mocha.getRunner().currentRunnable.invocationDetails.line
159-
} catch (e) {}
153+
} catch {}
160154

161155
if (safeGetRum(originalWindow)) {
162156
testInfo.isRUMActive = true
163157
}
164158
let coverage
165159
try {
166160
coverage = originalWindow.__coverage__
167-
} catch (e) {
161+
} catch {
168162
// ignore error and continue
169163
}
170164
cy.task('dd:afterEach', { test: testInfo, coverage })

yarn.lock

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,13 @@ eslint-module-utils@^2.12.1:
19861986
dependencies:
19871987
debug "^3.2.7"
19881988

1989+
eslint-plugin-cypress@^5.1.0:
1990+
version "5.1.0"
1991+
resolved "https://registry.yarnpkg.com/eslint-plugin-cypress/-/eslint-plugin-cypress-5.1.0.tgz#348c63f2afb2b336ab2063bf27347c1219be64b6"
1992+
integrity sha512-tdLXm4aq9vX2hTtKJTUFD3gdNseMKqsf8+P6hI4TtOPdz1LU4xvTpQBd1++qPAsPZP2lyYh71B5mvzu2lBr4Ow==
1993+
dependencies:
1994+
globals "^16.2.0"
1995+
19891996
eslint-plugin-es-x@^7.8.0:
19901997
version "7.8.0"
19911998
resolved "https://registry.yarnpkg.com/eslint-plugin-es-x/-/eslint-plugin-es-x-7.8.0.tgz#a207aa08da37a7923f2a9599e6d3eb73f3f92b74"
@@ -2581,6 +2588,11 @@ globals@^15.11.0, globals@^15.15.0:
25812588
resolved "https://registry.yarnpkg.com/globals/-/globals-15.15.0.tgz#7c4761299d41c32b075715a4ce1ede7897ff72a8"
25822589
integrity sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==
25832590

2591+
globals@^16.2.0:
2592+
version "16.3.0"
2593+
resolved "https://registry.yarnpkg.com/globals/-/globals-16.3.0.tgz#66118e765ddaf9e2d880f7e17658543f93f1f667"
2594+
integrity sha512-bqWEnJ1Nt3neqx2q5SFfGS8r/ahumIakg3HcwtNlrVlwXIeNumWn/c7Pn/wKzGhf6SaW6H6uWXLqC30STCMchQ==
2595+
25842596
globalthis@^1.0.4:
25852597
version "1.0.4"
25862598
resolved "https://registry.yarnpkg.com/globalthis/-/globalthis-1.0.4.tgz#7430ed3a975d97bfb59bcce41f5cabbafa651236"
@@ -4643,7 +4655,16 @@ streamsearch@^1.1.0:
46434655
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
46444656
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
46454657

4646-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
4658+
"string-width-cjs@npm:string-width@^4.2.0":
4659+
version "4.2.3"
4660+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
4661+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
4662+
dependencies:
4663+
emoji-regex "^8.0.0"
4664+
is-fullwidth-code-point "^3.0.0"
4665+
strip-ansi "^6.0.1"
4666+
4667+
string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
46474668
version "4.2.3"
46484669
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
46494670
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -4707,7 +4728,14 @@ string_decoder@~1.1.1:
47074728
dependencies:
47084729
safe-buffer "~5.1.0"
47094730

4710-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
4731+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
4732+
version "6.0.1"
4733+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
4734+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
4735+
dependencies:
4736+
ansi-regex "^5.0.1"
4737+
4738+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
47114739
version "6.0.1"
47124740
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
47134741
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -5213,7 +5241,7 @@ workerpool@^9.2.0:
52135241
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.2.tgz#4c045a8b437ae1bc70c646af11929a8b4d238656"
52145242
integrity sha512-Xz4Nm9c+LiBHhDR5bDLnNzmj6+5F+cyEAWPMkbs2awq/dYazR/efelZzUAjB/y3kNHL+uzkHvxVVpaOfGCPV7A==
52155243

5216-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
5244+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
52175245
version "7.0.0"
52185246
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
52195247
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -5231,6 +5259,15 @@ wrap-ansi@^6.2.0:
52315259
string-width "^4.1.0"
52325260
strip-ansi "^6.0.0"
52335261

5262+
wrap-ansi@^7.0.0:
5263+
version "7.0.0"
5264+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
5265+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
5266+
dependencies:
5267+
ansi-styles "^4.0.0"
5268+
string-width "^4.1.0"
5269+
strip-ansi "^6.0.0"
5270+
52345271
wrap-ansi@^8.1.0:
52355272
version "8.1.0"
52365273
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)