From 5ce5329a18498f2ee5964e4a0eb5c3da7f260086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Wed, 11 Aug 2021 11:57:42 +0100 Subject: [PATCH] feat(cli): add jestConfig option to test script --- cli/src/commands/test.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cli/src/commands/test.js b/cli/src/commands/test.js index d2c70309f..e45801244 100644 --- a/cli/src/commands/test.js +++ b/cli/src/commands/test.js @@ -1,3 +1,4 @@ +const path = require('path') const { reporter } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') const { runCLI } = require('jest-cli') @@ -5,6 +6,16 @@ const exitOnCatch = require('../lib/exitOnCatch') const loadEnvFiles = require('../lib/loadEnvFiles') const makePaths = require('../lib/paths') +const getAppJestConfig = ({ jestConfigPath, paths }) => { + if (jestConfigPath) { + return require(path.resolve(paths.base, jestConfigPath)) + } else if (fs.existsSync(paths.jestConfig)) { + return require(paths.jestConfig) + } else { + return {} + } +} + const handler = async ({ verbose, cwd, @@ -13,6 +24,7 @@ const handler = async ({ coverage, watch, watchAll, + jestConfig: jestConfigPath, }) => { const paths = makePaths(cwd) @@ -24,9 +36,10 @@ const handler = async ({ await exitOnCatch( async () => { const defaultJestConfig = require(paths.jestConfigDefaults) - const appJestConfig = fs.existsSync(paths.jestConfig) - ? require(paths.jestConfig) - : {} + const appJestConfig = getAppJestConfig({ + jestConfigPath, + paths, + }) const pkgJestConfig = require(paths.package).jest const jestConfig = { @@ -96,6 +109,9 @@ const command = { desc: 'Watch all source files for changes', default: false, }, + jestConfig: { + desc: 'Path to a jest config file', + }, }, handler, }