From 912cc6d295f38a0db9529c7930f23b2cdc4d04d3 Mon Sep 17 00:00:00 2001 From: Adil Bhayani Date: Tue, 23 Mar 2021 23:59:29 +1100 Subject: [PATCH] Allow for using consumers jest config --- src/commands/test.ts | 9 ++++++++- src/utils/checkFileExists.ts | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/utils/checkFileExists.ts 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; +};