|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +/* eslint-disable import/no-nodejs-modules */ |
| 9 | +import fs from 'fs'; |
| 10 | + |
| 11 | +// Discover all test files |
| 12 | +const allTestFiles = fs |
| 13 | + .readdirSync(__dirname, { recursive: true }) |
| 14 | + .filter((f) => f.endsWith('.test.ts')); |
| 15 | + |
| 16 | +/** |
| 17 | + * Distributes all field test files evenly using round-robin across available configs. |
| 18 | + */ |
| 19 | +function getTestsForConfig({ testsDirectory, groupNumber, totalGroups }) { |
| 20 | + const groupIndex = groupNumber - 1; |
| 21 | + |
| 22 | + const testFiles = allTestFiles.filter((file) => file.includes(testsDirectory)); |
| 23 | + const testFilesForConfig = testFiles.filter((file, index) => index % totalGroups === groupIndex); |
| 24 | + |
| 25 | + console.log( |
| 26 | + `Rule Upgrade - Fields integration tests. ${testsDirectory}, config_${groupNumber}: Running ${testFilesForConfig.length} test files:`, |
| 27 | + testFilesForConfig |
| 28 | + ); |
| 29 | + |
| 30 | + return testFilesForConfig; |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Base Jest configuration shared by all field test configs |
| 35 | + */ |
| 36 | +export function createFieldTestingConfig({ testsDirectory, groupNumber, totalGroups }) { |
| 37 | + const testFiles = getTestsForConfig({ |
| 38 | + testsDirectory, |
| 39 | + groupNumber, |
| 40 | + totalGroups, |
| 41 | + }); |
| 42 | + |
| 43 | + return { |
| 44 | + preset: '@kbn/test/jest_integration', |
| 45 | + rootDir: '../../../../../../../../../../../../../../../..', |
| 46 | + roots: [ |
| 47 | + '<rootDir>/x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management', |
| 48 | + ], |
| 49 | + testMatch: testFiles.map((file) => `**/${file}`), |
| 50 | + openHandlesTimeout: 0, |
| 51 | + forceExit: true, |
| 52 | + }; |
| 53 | +} |
0 commit comments