Skip to content

Commit 3d6fd08

Browse files
authored
Enforce standard Playwright config naming in scout_test_file_naming rule (elastic#255535)
## Summary ESLint rule update to validate playwright config names for Scout. Accepts either `parallel.playwright.config.ts` or `playwright.config.ts`
1 parent 36696d2 commit 3d6fd08

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

packages/kbn-eslint-plugin-eslint/rules/scout_test_file_naming.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ const isGlobalSetupFile = (filename) => {
4444
return path.basename(filename) === 'global.setup.ts';
4545
};
4646

47+
const ALLOWED_PLAYWRIGHT_CONFIG_NAMES = new Set([
48+
'playwright.config.ts',
49+
'parallel.playwright.config.ts',
50+
]);
51+
52+
/**
53+
* Checks if a file is a Playwright config with a non-standard name
54+
* @param {string} filename
55+
* @returns {boolean}
56+
*/
57+
const isNonStandardPlaywrightConfig = (filename) => {
58+
const basename = path.basename(filename);
59+
return (
60+
basename.includes('playwright.config.ts') && !ALLOWED_PLAYWRIGHT_CONFIG_NAMES.has(basename)
61+
);
62+
};
63+
4764
/**
4865
* Gets the file extension from a filename
4966
* @param {string} filename
@@ -76,6 +93,9 @@ module.exports = {
7693
'Scout test files must end with .spec.ts extension. Found: "{{actual}}", expected: "{{expected}}"',
7794
invalidPath:
7895
'Scout test files must be located in scout{_*}/{ui,api}/{parallel_,}tests/ directories.',
96+
invalidPlaywrightConfigName: `Scout Playwright config files must be named one of the following: ${[
97+
...ALLOWED_PLAYWRIGHT_CONFIG_NAMES,
98+
].join(', ')}. Found: "{{actual}}"`,
7999
},
80100
fixable: null,
81101
schema: [],
@@ -113,6 +133,20 @@ module.exports = {
113133
};
114134
}
115135
} else if (filename.includes('/test/scout') && filename.endsWith('.ts')) {
136+
if (isNonStandardPlaywrightConfig(filename)) {
137+
return {
138+
Program(node) {
139+
context.report({
140+
node,
141+
messageId: 'invalidPlaywrightConfigName',
142+
data: {
143+
actual: path.basename(filename),
144+
},
145+
});
146+
},
147+
};
148+
}
149+
116150
// File is in /test/scout but not in the correct subdirectory structure
117151
// Only report if it looks like a test file (has test/spec in name or is .ts)
118152
const basename = path.basename(filename, '.ts');

packages/kbn-eslint-plugin-eslint/rules/scout_test_file_naming.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ ruleTester.run('@kbn/eslint/scout_test_file_naming', rule, {
8080
filename:
8181
'x-pack/solutions/observability/plugins/my_plugin/test/scout/ui/playwright.config.ts',
8282
},
83+
// Valid: Scout parallel config file
84+
{
85+
code: '',
86+
filename:
87+
'x-pack/solutions/observability/plugins/my_plugin/test/scout/ui/parallel.playwright.config.ts',
88+
},
8389
// Valid: global.setup.ts in tests directory
8490
{
8591
code: '',
@@ -214,5 +220,33 @@ ruleTester.run('@kbn/eslint/scout_test_file_naming', rule, {
214220
},
215221
],
216222
},
223+
// Invalid: Non-standard Playwright config file with dot separator
224+
{
225+
code: '',
226+
filename:
227+
'src/platform/plugins/shared/discover/test/scout/ui/metrics_experience_parallel.playwright.config.ts',
228+
errors: [
229+
{
230+
messageId: 'invalidPlaywrightConfigName',
231+
data: {
232+
actual: 'metrics_experience_parallel.playwright.config.ts',
233+
},
234+
},
235+
],
236+
},
237+
// Invalid: Non-standard Playwright config file without dot separator
238+
{
239+
code: '',
240+
filename:
241+
'x-pack/solutions/observability/plugins/my_plugin/test/scout/ui/randomplaywright.config.ts',
242+
errors: [
243+
{
244+
messageId: 'invalidPlaywrightConfigName',
245+
data: {
246+
actual: 'randomplaywright.config.ts',
247+
},
248+
},
249+
],
250+
},
217251
],
218252
});

0 commit comments

Comments
 (0)