Skip to content

Commit

Permalink
feat(cli): add jestConfig option to test script (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi committed Aug 12, 2021
1 parent b5afa3c commit 57d6407
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions cli/src/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
const path = require('path')
const { reporter } = require('@dhis2/cli-helpers-engine')
const fs = require('fs-extra')
const { runCLI } = require('jest-cli')
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,
Expand All @@ -13,6 +24,7 @@ const handler = async ({
coverage,
watch,
watchAll,
jestConfig: jestConfigPath,
}) => {
const paths = makePaths(cwd)

Expand All @@ -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 = {
Expand Down Expand Up @@ -96,6 +109,9 @@ const command = {
desc: 'Watch all source files for changes',
default: false,
},
jestConfig: {
desc: 'Path to a jest config file',
},
},
handler,
}
Expand Down

0 comments on commit 57d6407

Please sign in to comment.