Skip to content

Commit

Permalink
Merge pull request #1415 from redwoodjs/rc-jest-watch-fix
Browse files Browse the repository at this point in the history
Fix `rw test` watch logic
  • Loading branch information
peterp committed Nov 5, 2020
2 parents 5b5a8b5 + 567dc20 commit 8ac08bc
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions packages/cli/src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ export const builder = (yargs) => {
describe:
'Run tests related to changed files based on hg/git. Specify the name or path to a file to focus on a specific set of tests',
type: 'boolean',
default: false,
})
.option('watchAll', {
describe: 'Run all tests',
type: 'boolean',
default: false,
default: true,
})
.option('collectCoverage', {
describe:
Expand All @@ -63,35 +58,37 @@ export const builder = (yargs) => {

export const handler = async ({
side,
watch = false,
watchAll = false,
watch = true,
collectCoverage = false,
}) => {
const { cache: CACHE_DIR } = getPaths()
const sides = [].concat(side).filter(Boolean)
const args = [
'--passWithNoTests',
watch && '--watch',
collectCoverage && '--collectCoverage',
watchAll && '--watchAll',
].filter(Boolean)
// If you don't pass any arguments we enter "watch mode" as the default.
if (!process.env.CI && !watchAll && !collectCoverage) {
// https://github.com/facebook/create-react-app/issues/5210

// If the user wants to watch, set the proper watch flag based on what kind of repo this is
// because of https://github.com/facebook/create-react-app/issues/5210
if (watch && !process.env.CI && !collectCoverage) {
const hasSourceControl = isInGitRepository() || isInMercurialRepository()
args.push(hasSourceControl ? '--watch' : '--watchAll')
}

// if no sides declared with yargs, default to all sides
if (!sides.length) {
getProject().sides.forEach(side => sides.push(side))
}

args.push(
'--config',
require.resolve('@redwoodjs/core/config/jest.config.js')
)

if (sides.length > 0) {
args.push('--projects', ...sides)
}

try {
// Create a test database
if (sides.includes('api')) {
Expand Down

0 comments on commit 8ac08bc

Please sign in to comment.