mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[jest/cli] stop iterating up at the repo_root and error if no config found (#126853)
This commit is contained in:
parent
4cfe9d97f0
commit
f2150ebaf5
1 changed files with 34 additions and 9 deletions
|
@ -22,6 +22,7 @@ import { existsSync } from 'fs';
|
|||
import { run } from 'jest';
|
||||
import { buildArgv } from 'jest-cli/build/cli';
|
||||
import { ToolingLog, getTimeReporter } from '@kbn/dev-utils';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
import { map } from 'lodash';
|
||||
|
||||
// yarn test:jest src/core/server/saved_objects
|
||||
|
@ -67,23 +68,47 @@ export function runJest(configName = 'jest.config.js') {
|
|||
log.verbose('commonTestFiles:', commonTestFiles);
|
||||
|
||||
let configPath;
|
||||
let devConfigPath;
|
||||
|
||||
// sets the working directory to the cwd or the common
|
||||
// base directory of the provided test files
|
||||
let wd = testFilesProvided ? commonTestFiles : cwd;
|
||||
while (true) {
|
||||
const dev = resolve(wd, devConfigName);
|
||||
if (existsSync(dev)) {
|
||||
configPath = dev;
|
||||
break;
|
||||
}
|
||||
|
||||
devConfigPath = resolve(wd, devConfigName);
|
||||
configPath = resolve(wd, configName);
|
||||
const actual = resolve(wd, configName);
|
||||
if (existsSync(actual)) {
|
||||
configPath = actual;
|
||||
break;
|
||||
}
|
||||
|
||||
while (!existsSync(configPath) && !existsSync(devConfigPath)) {
|
||||
wd = resolve(wd, '..');
|
||||
devConfigPath = resolve(wd, devConfigName);
|
||||
configPath = resolve(wd, configName);
|
||||
if (wd === REPO_ROOT) {
|
||||
break;
|
||||
}
|
||||
|
||||
const parent = resolve(wd, '..');
|
||||
if (parent === wd) {
|
||||
break;
|
||||
}
|
||||
|
||||
wd = parent;
|
||||
}
|
||||
|
||||
if (existsSync(devConfigPath)) {
|
||||
configPath = devConfigPath;
|
||||
if (!configPath) {
|
||||
if (testFilesProvided) {
|
||||
log.error(
|
||||
`unable to find a ${configName} file in ${commonTestFiles} or any parent directory up to the root of the repo. This CLI can only run Jest tests which resolve to a single ${configName} file, and that file must exist in a parent directory of all the paths you pass.`
|
||||
);
|
||||
} 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`
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
log.verbose(`no config provided, found ${configPath}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue