( pathToResolve: string, cwd: string, skipMultipleConfigError = false, )
| 23 | const getConfigFilename = (ext: string) => JEST_CONFIG_BASE_NAME + ext; |
| 24 | |
| 25 | export default function resolveConfigPath( |
| 26 | pathToResolve: string, |
| 27 | cwd: string, |
| 28 | skipMultipleConfigError = false, |
| 29 | ): string { |
| 30 | if (!path.isAbsolute(cwd)) { |
| 31 | throw new Error(`"cwd" must be an absolute path. cwd: ${cwd}`); |
| 32 | } |
| 33 | const absolutePath = path.isAbsolute(pathToResolve) |
| 34 | ? pathToResolve |
| 35 | : path.resolve(cwd, pathToResolve); |
| 36 | |
| 37 | if (isFile(absolutePath)) { |
| 38 | return absolutePath; |
| 39 | } |
| 40 | |
| 41 | // This is a guard against passing non existing path as a project/config, |
| 42 | // that will otherwise result in a very confusing situation. |
| 43 | // e.g. |
| 44 | // With a directory structure like this: |
| 45 | // my_project/ |
| 46 | // package.json |
| 47 | // |
| 48 | // Passing a `my_project/some_directory_that_doesnt_exist` as a project |
| 49 | // name will resolve into a (possibly empty) `my_project/package.json` and |
| 50 | // try to run all tests it finds under `my_project` directory. |
| 51 | if (!fs.existsSync(absolutePath)) { |
| 52 | throw new Error( |
| 53 | "Can't find a root directory while resolving a config file path.\n" + |
| 54 | `Provided path to resolve: ${pathToResolve}\n` + |
| 55 | `cwd: ${cwd}`, |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | return resolveConfigPathByTraversing( |
| 60 | absolutePath, |
| 61 | pathToResolve, |
| 62 | cwd, |
| 63 | skipMultipleConfigError, |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | const resolveConfigPathByTraversing = ( |
| 68 | pathToResolve: string, |
no test coverage detected