Skip to content

Commit d1c91c6

Browse files
authored
Bump eslint to ^9.1.17 and removed dep to eslint-config-airbnb-base (#4724)
* Bump eslint to 9.1.15 and removed dep to eslint-config-airbnb-base * eslint ^9.17.0 * Re-added no-return-await
1 parent 8c6acfe commit d1c91c6

21 files changed

+339
-378
lines changed

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ export default [
1616
{
1717
ignores: ['test/data/output', 'lib/css2xpath/*'],
1818
},
19-
...compat.extends('airbnb-base'),
2019
{
2120
languageOptions: {
2221
globals: {
2322
...globals.node,
2423
},
2524

2625
ecmaVersion: 2020,
27-
sourceType: 'commonjs',
26+
sourceType: 'module',
2827
},
2928

3029
rules: {

lib/heal.js

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,170 @@
1-
const debug = require('debug')('codeceptjs:heal');
2-
const colors = require('chalk');
3-
const Container = require('./container');
4-
const recorder = require('./recorder');
5-
const output = require('./output');
6-
const event = require('./event');
1+
const debug = require('debug')('codeceptjs:heal')
2+
const colors = require('chalk')
3+
const Container = require('./container')
4+
const recorder = require('./recorder')
5+
const output = require('./output')
6+
const event = require('./event')
77

88
/**
99
* @class
1010
*/
1111
class Heal {
1212
constructor() {
13-
this.recipes = {};
14-
this.fixes = [];
15-
this.prepareFns = [];
16-
this.contextName = null;
17-
this.numHealed = 0;
13+
this.recipes = {}
14+
this.fixes = []
15+
this.prepareFns = []
16+
this.contextName = null
17+
this.numHealed = 0
1818
}
1919

2020
clear() {
21-
this.recipes = {};
22-
this.fixes = [];
23-
this.prepareFns = [];
24-
this.contextName = null;
25-
this.numHealed = 0;
21+
this.recipes = {}
22+
this.fixes = []
23+
this.prepareFns = []
24+
this.contextName = null
25+
this.numHealed = 0
2626
}
2727

2828
addRecipe(name, opts = {}) {
29-
if (!opts.priority) opts.priority = 0;
29+
if (!opts.priority) opts.priority = 0
3030

31-
if (!opts.fn) throw new Error(`Recipe ${name} should have a function 'fn' to execute`);
31+
if (!opts.fn) throw new Error(`Recipe ${name} should have a function 'fn' to execute`)
3232

33-
this.recipes[name] = opts;
33+
this.recipes[name] = opts
3434
}
3535

3636
connectToEvents() {
3737
event.dispatcher.on(event.suite.before, suite => {
38-
this.contextName = suite.title;
39-
});
38+
this.contextName = suite.title
39+
})
4040

4141
event.dispatcher.on(event.test.started, test => {
42-
this.contextName = test.fullTitle();
43-
});
42+
this.contextName = test.fullTitle()
43+
})
4444

4545
event.dispatcher.on(event.test.finished, () => {
46-
this.contextName = null;
47-
});
46+
this.contextName = null
47+
})
4848
}
4949

5050
hasCorrespondingRecipes(step) {
51-
return matchRecipes(this.recipes, this.contextName).filter(r => !r.steps || r.steps.includes(step.name)).length > 0;
51+
return matchRecipes(this.recipes, this.contextName).filter(r => !r.steps || r.steps.includes(step.name)).length > 0
5252
}
5353

5454
async getCodeSuggestions(context) {
55-
const suggestions = [];
56-
const recipes = matchRecipes(this.recipes, this.contextName);
55+
const suggestions = []
56+
const recipes = matchRecipes(this.recipes, this.contextName)
5757

58-
debug('Recipes', recipes);
58+
debug('Recipes', recipes)
5959

60-
const currentOutputLevel = output.level();
61-
output.level(0);
60+
const currentOutputLevel = output.level()
61+
output.level(0)
6262

6363
for (const [property, prepareFn] of Object.entries(
6464
recipes
6565
.map(r => r.prepare)
6666
.filter(p => !!p)
6767
.reduce((acc, obj) => ({ ...acc, ...obj }), {}),
6868
)) {
69-
if (!prepareFn) continue;
69+
if (!prepareFn) continue
7070

71-
if (context[property]) continue;
72-
context[property] = await prepareFn(Container.support());
71+
if (context[property]) continue
72+
context[property] = await prepareFn(Container.support())
7373
}
7474

75-
output.level(currentOutputLevel);
75+
output.level(currentOutputLevel)
7676

7777
for (const recipe of recipes) {
78-
let snippets = await recipe.fn(context);
79-
if (!Array.isArray(snippets)) snippets = [snippets];
78+
let snippets = await recipe.fn(context)
79+
if (!Array.isArray(snippets)) snippets = [snippets]
8080

8181
suggestions.push({
8282
name: recipe.name,
8383
snippets,
84-
});
84+
})
8585
}
8686

87-
return suggestions.filter(s => !isBlank(s.snippets));
87+
return suggestions.filter(s => !isBlank(s.snippets))
8888
}
8989

9090
async healStep(failedStep, error, failureContext = {}) {
91-
output.debug(`Trying to heal ${failedStep.toCode()} step`);
91+
output.debug(`Trying to heal ${failedStep.toCode()} step`)
9292

9393
Object.assign(failureContext, {
9494
error,
9595
step: failedStep,
9696
prevSteps: failureContext?.test?.steps?.slice(0, -1) || [],
97-
});
97+
})
9898

99-
const suggestions = await this.getCodeSuggestions(failureContext);
99+
const suggestions = await this.getCodeSuggestions(failureContext)
100100

101101
if (suggestions.length === 0) {
102-
debug('No healing suggestions found');
103-
throw error;
102+
debug('No healing suggestions found')
103+
throw error
104104
}
105105

106-
output.debug(`Received ${suggestions.length} suggestion${suggestions.length === 1 ? '' : 's'}`);
106+
output.debug(`Received ${suggestions.length} suggestion${suggestions.length === 1 ? '' : 's'}`)
107107

108-
debug(suggestions);
108+
debug(suggestions)
109109

110110
for (const suggestion of suggestions) {
111111
for (const codeSnippet of suggestion.snippets) {
112112
try {
113-
debug('Executing', codeSnippet);
113+
debug('Executing', codeSnippet)
114114
recorder.catch(e => {
115-
debug(e);
116-
});
115+
debug(e)
116+
})
117117

118118
if (typeof codeSnippet === 'string') {
119-
const I = Container.support('I');
120-
await eval(codeSnippet); // eslint-disable-line
119+
const I = Container.support('I')
120+
await eval(codeSnippet)
121121
} else if (typeof codeSnippet === 'function') {
122-
await codeSnippet(Container.support());
122+
await codeSnippet(Container.support())
123123
}
124124

125125
this.fixes.push({
126126
recipe: suggestion.name,
127127
test: failureContext?.test,
128128
step: failedStep,
129129
snippet: codeSnippet,
130-
});
130+
})
131131

132-
recorder.add('healed', () => output.print(colors.bold.green(` Code healed successfully by ${suggestion.name}`), colors.gray('(no errors thrown)')));
133-
this.numHealed++;
132+
recorder.add('healed', () => output.print(colors.bold.green(` Code healed successfully by ${suggestion.name}`), colors.gray('(no errors thrown)')))
133+
this.numHealed++
134134
// recorder.session.restore();
135-
return;
135+
return
136136
} catch (err) {
137-
debug('Failed to execute code', err);
138-
recorder.ignoreErr(err); // healing did not help
139-
recorder.catchWithoutStop(err);
140-
await recorder.promise(); // wait for all promises to resolve
137+
debug('Failed to execute code', err)
138+
recorder.ignoreErr(err) // healing did not help
139+
recorder.catchWithoutStop(err)
140+
await recorder.promise() // wait for all promises to resolve
141141
}
142142
}
143143
}
144-
output.debug(`Couldn't heal the code for ${failedStep.toCode()}`);
145-
recorder.throw(error);
144+
output.debug(`Couldn't heal the code for ${failedStep.toCode()}`)
145+
recorder.throw(error)
146146
}
147147

148148
static setDefaultHealers() {
149-
require('./template/heal');
149+
require('./template/heal')
150150
}
151151
}
152152

153-
const heal = new Heal();
153+
const heal = new Heal()
154154

155-
module.exports = heal;
155+
module.exports = heal
156156

157157
function matchRecipes(recipes, contextName) {
158158
return Object.entries(recipes)
159159
.filter(([, recipe]) => !contextName || !recipe.grep || new RegExp(recipe.grep).test(contextName))
160160
.sort(([, a], [, b]) => a.priority - b.priority)
161161
.map(([name, recipe]) => {
162-
recipe.name = name;
163-
return recipe;
162+
recipe.name = name
163+
return recipe
164164
})
165-
.filter(r => !!r.fn);
165+
.filter(r => !!r.fn)
166166
}
167167

168168
function isBlank(value) {
169-
return value == null || (Array.isArray(value) && value.length === 0) || (typeof value === 'object' && Object.keys(value).length === 0) || (typeof value === 'string' && value.trim() === '');
169+
return value == null || (Array.isArray(value) && value.length === 0) || (typeof value === 'object' && Object.keys(value).length === 0) || (typeof value === 'string' && value.trim() === '')
170170
}

lib/helper/Playwright.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,6 @@ class Playwright extends Helper {
21822182
let chunked = chunkArray(props, values.length)
21832183
chunked = chunked.filter(val => {
21842184
for (let i = 0; i < val.length; ++i) {
2185-
// eslint-disable-next-line eqeqeq
21862185
if (val[i] != values[i]) return false
21872186
}
21882187
return true
@@ -2451,7 +2450,7 @@ class Playwright extends Helper {
24512450
waiter = context.waitForFunction(valueFn, [locator.value], { timeout: waitTimeout })
24522451
} else {
24532452
const enabledFn = function ([locator, $XPath]) {
2454-
eval($XPath) // eslint-disable-line no-eval
2453+
eval($XPath)
24552454
return $XPath(null, locator).filter(el => !el.disabled).length > 0
24562455
}
24572456
waiter = context.waitForFunction(enabledFn, [locator.value, $XPath.toString()], { timeout: waitTimeout })
@@ -2477,7 +2476,7 @@ class Playwright extends Helper {
24772476
waiter = context.waitForFunction(valueFn, [locator.value], { timeout: waitTimeout })
24782477
} else {
24792478
const disabledFn = function ([locator, $XPath]) {
2480-
eval($XPath) // eslint-disable-line no-eval
2479+
eval($XPath)
24812480
return $XPath(null, locator).filter(el => el.disabled).length > 0
24822481
}
24832482
waiter = context.waitForFunction(disabledFn, [locator.value, $XPath.toString()], { timeout: waitTimeout })
@@ -2503,7 +2502,7 @@ class Playwright extends Helper {
25032502
waiter = context.waitForFunction(valueFn, [locator.value, value], { timeout: waitTimeout })
25042503
} else {
25052504
const valueFn = function ([locator, $XPath, value]) {
2506-
eval($XPath) // eslint-disable-line no-eval
2505+
eval($XPath)
25072506
return $XPath(null, locator).filter(el => (el.value || '').indexOf(value) !== -1).length > 0
25082507
}
25092508
waiter = context.waitForFunction(valueFn, [locator.value, $XPath.toString(), value], {
@@ -2537,7 +2536,7 @@ class Playwright extends Helper {
25372536
waiter = context.waitForFunction(visibleFn, [locator.value, num], { timeout: waitTimeout })
25382537
} else {
25392538
const visibleFn = function ([locator, $XPath, num]) {
2540-
eval($XPath) // eslint-disable-line no-eval
2539+
eval($XPath)
25412540
return $XPath(null, locator).filter(el => el.offsetParent !== null).length === num
25422541
}
25432542
waiter = context.waitForFunction(visibleFn, [locator.value, $XPath.toString(), num], {
@@ -2771,7 +2770,7 @@ class Playwright extends Helper {
27712770
if (locator.isXPath()) {
27722771
return contextObject.waitForFunction(
27732772
([locator, text, $XPath]) => {
2774-
eval($XPath) // eslint-disable-line no-eval
2773+
eval($XPath)
27752774
const el = $XPath(null, locator)
27762775
if (!el.length) return false
27772776
return el[0].innerText.indexOf(text) > -1
@@ -2975,7 +2974,7 @@ class Playwright extends Helper {
29752974
}
29762975
} else {
29772976
const visibleFn = function ([locator, $XPath]) {
2978-
eval($XPath) // eslint-disable-line no-eval
2977+
eval($XPath)
29792978
return $XPath(null, locator).length === 0
29802979
}
29812980
waiter = context.waitForFunction(visibleFn, [locator.value, $XPath.toString()], { timeout: waitTimeout })
@@ -3214,7 +3213,6 @@ class Playwright extends Helper {
32143213
}
32153214

32163215
for (const i in this.requests) {
3217-
// eslint-disable-next-line no-prototype-builtins
32183216
if (this.requests.hasOwnProperty(i)) {
32193217
const request = this.requests[i]
32203218

lib/helper/Protractor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ class Protractor extends Helper {
10541054
const stream = fs.createWriteStream(outputFile)
10551055
stream.write(Buffer.from(png, 'base64'))
10561056
stream.end()
1057-
return new Promise(resolve => stream.on('finish', resolve)) // eslint-disable-line no-promise-executor-return
1057+
return new Promise(resolve => stream.on('finish', resolve))
10581058
}
10591059

10601060
const res = await this._locate(locator)
@@ -1077,7 +1077,7 @@ class Protractor extends Helper {
10771077
const stream = fs.createWriteStream(outputFile)
10781078
stream.write(Buffer.from(png, 'base64'))
10791079
stream.end()
1080-
return new Promise(resolve => stream.on('finish', resolve)) // eslint-disable-line no-promise-executor-return
1080+
return new Promise(resolve => stream.on('finish', resolve))
10811081
}
10821082

10831083
if (!fullPage) {

0 commit comments

Comments
 (0)