Skip to content

Commit 5d49f1b

Browse files
[scout] re-org test directory (elastic#226411)
## Summary Since Scout will soon support `api` testing, we need to re-org scout test directory so that both ui and api playwright configs can be discovered and executed independently. Proposed structure: ``` - plugin |- test |- scout |- common // fixtures/constants to share across both 'ui' and 'api' tests |- ui |-tests |-parallel_tests |-playwright.config.ts |-playwright.parallel.config.ts |- api |-tests |-parallel_tests |-playwright.config.ts |-playwright.parallel.config.ts ``` This PR updates all the existing scout directories --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 2f8e961 commit 5d49f1b

File tree

77 files changed

+139
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+139
-114
lines changed

.eslintrc.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,9 @@ module.exports = {
15961596
'src/platform/packages/shared/kbn-scout/src/playwright/**/*.ts',
15971597
'x-pack/solutions/observability/packages/kbn-scout-oblt/src/playwright/**/*.ts',
15981598
'x-pack/solutions/security/packages/kbn-scout-security/src/playwright/**/*.ts',
1599-
'src/platform/plugins/**/ui_tests/**/*.ts',
1600-
'x-pack/platform/plugins/**/ui_tests/**/*.ts',
1601-
'x-pack/solutions/**/plugins/**/ui_tests/**/*.ts',
1599+
'src/platform/plugins/**/test/scout/**/*.ts',
1600+
'x-pack/platform/plugins/**/test/scout/**/*.ts',
1601+
'x-pack/solutions/**/plugins/**/test/scout/**/*.ts',
16021602
],
16031603
excludedFiles: ['src/platform/packages/shared/kbn-scout/src/playwright/**/*.test.ts'],
16041604
extends: ['plugin:playwright/recommended'],
@@ -2319,8 +2319,8 @@ module.exports = {
23192319
},
23202320
{
23212321
files: [
2322-
'src/platform/plugins/**/ui_tests/**/*.ts',
2323-
'x-pack/platform/**/plugins/**/ui_tests/**/*.ts',
2322+
'src/platform/plugins/**/test/scout/**/*.ts',
2323+
'x-pack/platform/**/plugins/**/test/scout/**/*.ts',
23242324
],
23252325
rules: {
23262326
'no-restricted-imports': [
@@ -2341,7 +2341,7 @@ module.exports = {
23412341
},
23422342
},
23432343
{
2344-
files: ['x-pack/solutions/observability/plugins/**/ui_tests/**/*.ts'],
2344+
files: ['x-pack/solutions/observability/plugins/**/test/scout/**/*.ts'],
23452345
rules: {
23462346
'no-restricted-imports': [
23472347
'error',
@@ -2368,7 +2368,7 @@ module.exports = {
23682368
},
23692369
},
23702370
{
2371-
files: ['x-pack/solutions/security/plugins/**/ui_tests/**/*.ts'],
2371+
files: ['x-pack/solutions/security/plugins/**/test/scout/**/*.ts'],
23722372
rules: {
23732373
'no-restricted-imports': [
23742374
'error',

.github/CODEOWNERS

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ x-pack/solutions/observability/plugins/observability/server/lib/esql_extensions
15841584
/src/platform/test/functional/apps/discover/observability/embeddable @elastic/obs-ux-logs-team
15851585
/src/platform/test/functional/apps/discover/observability/logs @elastic/obs-ux-logs-team
15861586
/x-pack/solutions/observability/plugins/observability/public/pages/landing @elastic/obs-ux-logs-team
1587-
/x-pack/solutions/observability/plugins/observability/ui_tests/tests/landing.spec.ts @elastic/obs-ux-logs-team
1587+
/x-pack/solutions/observability/plugins/observability/test/scout/ui/tests/landing.spec.ts @elastic/obs-ux-logs-team
15881588

15891589
# Observability-ui
15901590
/x-pack/test_serverless/api_integration/test_suites/observability/index.ts @elastic/observability-ui
@@ -1744,10 +1744,10 @@ x-pack/platform/plugins/shared/ml/server/models/data_recognizer/modules/security
17441744
/src/platform/packages/shared/kbn-es/src/serverless_resources/project_roles/security/roles.yml @elastic/appex-qa
17451745
/x-pack/platform/test/common/ftr_provider_context.ts @elastic/appex-qa
17461746
/x-pack/platform/test/common/lib/test_data_loader.ts @elastic/appex-qa # temporarily
1747-
/x-pack/platform/plugins/shared/maps/ui_tests @elastic/appex-qa # temporarily
1748-
/x-pack/platform/plugins/private/discover_enhanced/ui_tests/ @elastic/appex-qa # temporarily
1749-
/x-pack/platform/plugins/private/discover_enhanced/ui_tests/tests/discover_cdp_perf.spec.ts @elastic/kibana-data-discovery # test tracks bundle size limits
1750-
/x-pack/platform/plugins/private/painless_lab/ui_tests @elastic/appex-qa # temporarily
1747+
/x-pack/platform/plugins/shared/maps/test/scout @elastic/appex-qa # temporarily
1748+
/x-pack/platform/plugins/private/discover_enhanced/test/scout/ @elastic/appex-qa # temporarily
1749+
/x-pack/platform/plugins/private/discover_enhanced/test/scout/ui/tests/discover_cdp_perf.spec.ts @elastic/kibana-data-discovery # test tracks bundle size limits
1750+
/x-pack/platform/plugins/private/painless_lab/test/scout @elastic/appex-qa # temporarily
17511751
/x-pack/test/functional/fixtures/package_registry_config.yml @elastic/appex-qa # No usages found
17521752
/x-pack/test/functional/fixtures/kbn_archiver/packaging.json @elastic/appex-qa # No usages found
17531753
/x-pack/test/functional/es_archives/filebeat @elastic/appex-qa

packages/kbn-repo-source-classifier/src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ export const TEST_DIR = new Set([
5858
'storybook',
5959
'.storybook',
6060
'integration_tests',
61-
'ui_tests',
6261
...RANDOM_TEST_FILE_NAMES,
6362
]);

src/platform/packages/private/kbn-scout-reporting/src/helpers/plugin_manifest.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jest.mock('fs');
1616
describe('plugin_manifest', () => {
1717
describe('getManifestPath', () => {
1818
it('should resolve the manifest path correctly for a valid config path', () => {
19-
const configPath = '/plugins/my_plugin/ui_tests/playwright.config.ts';
19+
const configPath = '/plugins/my_plugin/test/scout/ui/playwright.config.ts';
2020
const expectedPath = path.resolve('/plugins/my_plugin/kibana.jsonc');
2121
expect(getManifestPath(configPath)).toBe(expectedPath);
2222
});
2323

24-
it(`should throw an error if 'ui_tests' is not in the path`, () => {
24+
it(`should throw an error if 'scout' is not in the path`, () => {
2525
const configPath = '/plugins/my_plugin/tests/playwright.config.ts';
2626
expect(() => getManifestPath(configPath)).toThrow(
27-
/Invalid path: "ui_tests" directory not found/
27+
/Invalid path: "scout" directory not found/
2828
);
2929
});
3030
});
@@ -90,7 +90,7 @@ describe('plugin_manifest', () => {
9090
});
9191

9292
describe('getPluginManifestData', () => {
93-
const configPath = '/plugins/my_plugin/ui_tests/playwright.config.ts';
93+
const configPath = '/plugins/my_plugin/test/scout/ui/playwright.config.ts';
9494
const manifestContent = `
9595
{
9696
"id": "my_plugin",

src/platform/packages/private/kbn-scout-reporting/src/helpers/plugin_manifest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ export interface PluginManifest {
2323
* Resolves the path to the `kibana.jsonc` manifest based on the Playwright configuration file path.
2424
* @param configPath - Absolute path to the Playwright configuration file.
2525
* @returns Absolute path to the `kibana.jsonc` file.
26-
* @throws Error if `ui_tests` is not found in the path.
26+
* @throws Error if `scout` is not found in the path.
2727
*/
2828
export const getManifestPath = (configPath: string): string => {
2929
const pathSegments = configPath.split(path.sep);
30-
const testDirIndex = pathSegments.indexOf('ui_tests');
30+
const testDirIndex = pathSegments.indexOf('scout');
3131

3232
if (testDirIndex === -1) {
3333
throw new Error(
34-
`Invalid path: "ui_tests" directory not found in ${configPath}.
35-
Ensure playwright configuration file is in the plugin directory: '/plugins/<plugin-name>/ui_tests/<config-file>'`
34+
`Invalid path: "scout" directory not found in ${configPath}.
35+
Ensure playwright configuration file is in the plugin directory: '/plugins/<plugin-name>/test/scout/ui/<config-file>'`
3636
);
3737
}
3838

39-
const manifestSegments = pathSegments.slice(0, testDirIndex).concat('kibana.jsonc');
39+
const manifestSegments = pathSegments.slice(0, testDirIndex - 1).concat('kibana.jsonc');
4040
return path.resolve('/', ...manifestSegments); // Ensure absolute path
4141
};
4242

src/platform/packages/shared/kbn-scout/README.md

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ import { createPlaywrightConfig } from '@kbn/scout';
8484

8585
// eslint-disable-next-line import/no-default-export
8686
export default createPlaywrightConfig({
87-
testDir: './tests',
88-
workers: 2,
87+
testDir: './tests',
88+
workers: 2,
8989
});
9090
```
9191

@@ -100,6 +100,7 @@ The `fixtures` directory contains core Scout capabilities required for testing t
100100
scoped to either `test` or `worker`. Scope decides when to init a new fixture instance: once per worker or for every test function. It is important to choose the correct scope to keep test execution optimally fast: if **a new instance is not needed for every test**, the fixture should be scoped to **worker**. Otherwise, it should be scoped to **test**.
101101

102102
**Core `worker` scoped fixtures:**
103+
103104
- `log`
104105
- `config`
105106
- `esClient`
@@ -108,20 +109,21 @@ scoped to either `test` or `worker`. Scope decides when to init a new fixture in
108109
- `samlAuth`
109110

110111
```ts
111-
test.beforeAll(async ({ kbnClient }) => {
112-
await kbnClient.importExport.load(testData.KBN_ARCHIVES.ECOMMERCE);
113-
});
112+
test.beforeAll(async ({ kbnClient }) => {
113+
await kbnClient.importExport.load(testData.KBN_ARCHIVES.ECOMMERCE);
114+
});
114115
```
115116

116117
**Core `test` scoped fixtures:**
118+
117119
- `browserAuth`
118120
- `pageObjects`
119121
- `page`
120122

121123
```ts
122-
test.beforeEach(async ({ browserAuth }) => {
123-
await browserAuth.loginAsViewer();
124-
});
124+
test.beforeEach(async ({ browserAuth }) => {
125+
await browserAuth.loginAsViewer();
126+
});
125127
```
126128

127129
If a new fixture depends on a fixture with a `test` scope, it must also be `test` scoped.
@@ -148,7 +150,7 @@ All registered Page Objects are available via the `pageObjects` fixture:
148150

149151
```ts
150152
test.beforeEach(async ({ pageObjects }) => {
151-
await pageObjects.discover.goto();
153+
await pageObjects.discover.goto();
152154
});
153155
```
154156

@@ -219,7 +221,7 @@ This command is useful for manual testing or running tests via an IDE.
219221
To start the servers locally and run tests in one step, use:
220222
221223
```bash
222-
node scripts/scout.js run-tests [--stateful|--serverless=[es|oblt|security]] --config <plugin-path>/ui_tests/playwright.config.ts
224+
node scripts/scout.js run-tests [--stateful|--serverless=[es|oblt|security]] --config <plugin-path>/test/scout/ui/playwright.config.ts
223225
```
224226
225227
- **`--stateful`** or **`--serverless`**: Specifies the deployment type.
@@ -235,7 +237,7 @@ If the servers are already running, you can execute tests independently using on
235237
2. **Command Line**: Use the following command:
236238
237239
```bash
238-
npx playwright test --config <plugin-path>/ui_tests/playwright.config.ts --project local
240+
npx playwright test --config <plugin-path>/test/scout/ui/playwright.config.ts --project local
239241
```
240242
241243
- **`--project`**: Specifies the test target as `local` ( `ech` or `mki` for Cloud targets, see below).
@@ -250,14 +252,14 @@ To run tests against a Cloud deployment, you can use either the Scout CLI or the
250252
node scripts/scout.js run-tests \
251253
--stateful \
252254
--testTarget=cloud \
253-
--config <plugin-path>/ui_tests/playwright.config.ts
255+
--config <plugin-path>/test/scout/ui/playwright.config.ts
254256
```
255257
256258
```bash
257259
node scripts/scout.js run-tests \
258260
--serverless=oblt \
259261
--testTarget=cloud \
260-
--config <plugin-path>/ui_tests/playwright.config.ts
262+
--config <plugin-path>/test/scout/ui/playwright.config.ts
261263
```
262264
263265
- **`--testTarget=cloud`**: Specifies that tests should run against a Cloud deployment.
@@ -268,14 +270,14 @@ node scripts/scout.js run-tests \
268270
npx playwright test \
269271
--project=ech \
270272
--grep=@ess \
271-
--config <plugin-path>/ui_tests/playwright.config.ts
273+
--config <plugin-path>/test/scout/ui/playwright.config.ts
272274
```
273275
274276
```bash
275277
npx playwright test \
276278
--project=mki \
277279
--grep=@svlOblt \
278-
--config <plugin-path>/ui_tests/playwright.config.ts
280+
--config <plugin-path>/test/scout/ui/playwright.config.ts
279281
```
280282
281283
- **`--project`**: Specifies the test target (`ech` for Stateful or `mki` for Serverless).
@@ -298,6 +300,7 @@ node scripts/jest --config src/platform/packages/shared/kbn-scout/jest.config.js
298300
Ensure you have the latest local copy of the Kibana repository.
299301
300302
Install dependencies by running the following commands:
303+
301304
- `yarn kbn bootstrap` to install dependencies.
302305
- `node scripts/build_kibana_platform_plugins.js` to build plugins.
303306
@@ -317,7 +320,9 @@ export class NewPage {
317320
// implementation
318321
}
319322
```
323+
320324
2. **Register the Page Object:** Update the index file to include the new Page Object:
325+
321326
```ts
322327
export function createCorePageObjects(page: ScoutPage): PageObjects {
323328
return {
@@ -326,6 +331,7 @@ export function createCorePageObjects(page: ScoutPage): PageObjects {
326331
};
327332
}
328333
```
334+
329335
#### Adding API service
330336
331337
1. **Create a New API service:** Add your service to the `src/playwright/fixtures/worker/apis` directory. For instance:
@@ -351,7 +357,9 @@ export const getFleetApiHelper = (log: ScoutLogger, kbnClient: KbnClient): Fleet
351357
};
352358
};
353359
```
360+
354361
2. **Register the API service:** Update the index file to include the new service:
362+
355363
```ts
356364
export const apiServicesFixture = coreWorkerFixtures.extend<
357365
{},
@@ -367,7 +375,9 @@ export const apiServicesFixture = coreWorkerFixtures.extend<
367375
],
368376
});
369377
```
378+
370379
#### Adding Fixture
380+
371381
1. **Determine Fixture Scope:** Decide if your fixture should apply to the `test` (per-test) or `worker` (per-worker) scope.
372382
373383
2. **Implement the Fixture:** Add the implementation to `src/playwright/fixtures/test` or `src/playwright/fixtures/worker`.
@@ -376,20 +386,20 @@ export const apiServicesFixture = coreWorkerFixtures.extend<
376386
export const newTestFixture = base.extend<ScoutTestFixtures, ScoutWorkerFixtures>({
377387
newFixture: async ({}, use) => {
378388
const myFn = // implementation
379-
await use(myFn);
389+
await use(myFn);
380390
// optionally, cleanup on test completion
381391
},
382392
});
383393
```
394+
384395
3. **Register the Fixture:** Add the fixture to the appropriate scope:
396+
385397
```ts
386-
export const scoutTestFixtures = mergeTests(
387-
...
388-
newTestFixture,
389-
);
398+
export const scoutTestFixtures = mergeTests(coreFixtures, newTestFixture);
390399
```
391400
392401
#### Best Practices
402+
393403
- **Reusable Code:** When creating Page Objects, API services or Fixtures that apply to more than one plugin, ensure they are added to the `kbn-scout` package.
394404
- **Adhere to Existing Structure:** Maintain consistency with the project's architecture.
395405
- **Keep the Scope of Components Clear** When designing test components, keep in naming conventions, scope, maintainability and performance.
@@ -399,30 +409,32 @@ export const scoutTestFixtures = mergeTests(
399409
- **Add Unit Tests:** Include tests for new logic where applicable, ensuring it works as expected.
400410
- **Playwright documentation:** [Official best practices](https://playwright.dev/docs/best-practices)
401411
402-
403412
### Running tests on CI
404413
405414
#### Enabling tests for execution
415+
406416
Scout is still in active development, which means frequent code changes may sometimes cause test failures. To maintain stability, we currently do not run Scout tests for every PR and encourage teams to limit the number of tests they add for now.
407417
408418
If a test is difficult to stabilize within a reasonable timeframe, we reserve the right to disable it or even all tests for particular plugin.
409419
410420
To manage Scout test execution, we use the `.buildkite/scout_ci_config.yml` file, where Kibana plugins with Scout tests are registered. If you're unsure about the stability of your tests, please add your plugin under the `disabled` section.
411421
412422
You can check whether your plugin is already registered by running:
423+
413424
```bash
414425
node scripts/scout discover-playwright-configs --validate
415426
```
427+
416428
On CI we run Scout tests only for `enabled` plugins:
417429
418430
For PRs, Scout tests run only if there are changes to registered plugins or Scout-related packages.
419431
On merge commits, Scout tests run in a non-blocking mode.
420432
421433
#### Scout exit codes
422434
423-
| Exit code | Description |
424-
|--------|--------|
425-
| 0 | All tests passed |
426-
| 1 | Missing configuration (e.g. SCOUT_CONFIG_GROUP_KEY and SCOUT_CONFIG_GROUP_TYPE environment variables not set) |
427-
| 2 | No tests in Playwright config |
428-
| 10| Tests failed |
435+
| Exit code | Description |
436+
| --------- | ------------------------------------------------------------------------------------------------------------- |
437+
| 0 | All tests passed |
438+
| 1 | Missing configuration (e.g. SCOUT_CONFIG_GROUP_KEY and SCOUT_CONFIG_GROUP_TYPE environment variables not set) |
439+
| 2 | No tests in Playwright config |
440+
| 10 | Tests failed |

src/platform/packages/shared/kbn-scout/src/config/discovery/search_configs.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,32 @@ describe('getScoutPlaywrightConfigs', () => {
3737

3838
it('should correctly extract plugin names and group config files', () => {
3939
(fastGlob.sync as jest.Mock).mockReturnValue([
40-
'x-pack/platform/plugins/private/plugin_a/ui_tests/playwright.config.ts',
41-
'x-pack/platform/plugins/private/plugin_a/ui_tests/parallel.playwright.config.ts',
42-
'x-pack/solutions/security/plugins/plugin_b/ui_tests/playwright.config.ts',
43-
'src/platform/plugins/shared/plugin_c/ui_tests/playwright.config.ts',
40+
'x-pack/platform/plugins/private/plugin_a/test/scout/ui/playwright.config.ts',
41+
'x-pack/platform/plugins/private/plugin_a/test/scout/ui/parallel.playwright.config.ts',
42+
'x-pack/solutions/security/plugins/plugin_b/test/scout/ui/playwright.config.ts',
43+
'src/platform/plugins/shared/plugin_c/test/scout/ui/playwright.config.ts',
4444
]);
4545

4646
const plugins = getScoutPlaywrightConfigs(['x-pack/', 'src/'], mockLog);
4747

4848
expect(plugins.size).toBe(3);
4949
expect(plugins.get('plugin_a')).toEqual({
5050
configs: [
51-
'x-pack/platform/plugins/private/plugin_a/ui_tests/playwright.config.ts',
52-
'x-pack/platform/plugins/private/plugin_a/ui_tests/parallel.playwright.config.ts',
51+
'x-pack/platform/plugins/private/plugin_a/test/scout/ui/playwright.config.ts',
52+
'x-pack/platform/plugins/private/plugin_a/test/scout/ui/parallel.playwright.config.ts',
5353
],
5454
usesParallelWorkers: true,
5555
group: 'platform',
5656
pluginPath: 'x-pack/platform/plugins/private/plugin_a',
5757
});
5858
expect(plugins.get('plugin_b')).toEqual({
59-
configs: ['x-pack/solutions/security/plugins/plugin_b/ui_tests/playwright.config.ts'],
59+
configs: ['x-pack/solutions/security/plugins/plugin_b/test/scout/ui/playwright.config.ts'],
6060
usesParallelWorkers: false,
6161
group: 'security',
6262
pluginPath: 'x-pack/solutions/security/plugins/plugin_b',
6363
});
6464
expect(plugins.get('plugin_c')).toEqual({
65-
configs: ['src/platform/plugins/shared/plugin_c/ui_tests/playwright.config.ts'],
65+
configs: ['src/platform/plugins/shared/plugin_c/test/scout/ui/playwright.config.ts'],
6666
usesParallelWorkers: false,
6767
group: 'platform',
6868
pluginPath: 'src/platform/plugins/shared/plugin_c',

0 commit comments

Comments
 (0)