diff --git a/src/commands/test.ts b/src/commands/test.ts index 6d023bc..dad29cc 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -1,12 +1,19 @@ import * as path from 'path'; import { spawn } from 'child_process'; import { binPath } from '../utils'; +import { checkFileExists } from '../utils/checkFileExists'; const defaultArgs = ['--watch']; export const test = async (args: string[] = defaultArgs) => { const jestBin = binPath('jest'); - const configPath = path.resolve(__dirname, '../../jest.config.js'); + + const upperJestPath = '../../../../jest.config.js'; + const defaultJestPath = '../../jest.config.js'; + const pathString = checkFileExists(upperJestPath) + ? upperJestPath + : defaultJestPath; + const configPath = path.resolve(__dirname, pathString); try { const subprocess = spawn(jestBin, ['-c', configPath, ...args], { diff --git a/src/utils/checkFileExists.ts b/src/utils/checkFileExists.ts new file mode 100644 index 0000000..7a02be0 --- /dev/null +++ b/src/utils/checkFileExists.ts @@ -0,0 +1,9 @@ +import { existsSync } from "fs"; +import path from 'path'; + +export const checkFileExists = (resolutionPath: string) => { + if (existsSync(path.resolve(__dirname, resolutionPath))) { + return true; + } + return false; +};