From 1a7375e4260527ce26706c2740f4ca3e7c385e75 Mon Sep 17 00:00:00 2001 From: Nick Partridge Date: Fri, 10 Jan 2025 17:27:05 -0600 Subject: [PATCH] [kbn-test] Jest run script should use `testPathPattern` to lookup config (#206341) Adds logic to support the jest vscode extension by reading the `--testPathPattern` arg for the purpose of config lookup. This enables running tests easily in the vscode jest extension. (cherry picked from commit 481b8037d609e2d7a994e7696e2fa23f7b44f2b9) --- packages/kbn-test/src/jest/run.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/kbn-test/src/jest/run.ts b/packages/kbn-test/src/jest/run.ts index e82a34a2fe82a..992b1600ec6e2 100644 --- a/packages/kbn-test/src/jest/run.ts +++ b/packages/kbn-test/src/jest/run.ts @@ -79,6 +79,11 @@ export function runJest(configName = 'jest.config.js') { if (!argv.config) { testFiles = argv._.map((p) => resolve(cwd, p.toString())); + + if (argv.testPathPattern) { + testFiles.push(argv.testPathPattern); + } + const commonTestFiles = commonBasePath(testFiles); const testFilesProvided = testFiles.length > 0; @@ -123,7 +128,7 @@ export function runJest(configName = 'jest.config.js') { ); } else { log.error( - `we no longer ship a root config file so you either need to pass a path to a test file, a folder where tests can be found, or a --config argument pointing to one of the many ${configName} files in the repository` + `we no longer ship a root config file so you either need to pass a path to a test file, a folder where tests can be found, a --testPathPattern argument pointing to a file/directory or a --config argument pointing to one of the many ${configName} files in the repository` ); }