diff --git a/packages/jest-changed-files/src/git.ts b/packages/jest-changed-files/src/git.ts index 972e8497e1d5..c868e9fa002e 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -34,15 +34,13 @@ const findChangedFilesUsingCommand = async ( const adapter: SCMAdapter = { findChangedFiles: async (cwd, options) => { - const changedSince: string | undefined = - options && (options.withAncestor ? 'HEAD^' : options.changedSince); + const changedSince = options.withAncestor ? 'HEAD^' : options.changedSince; - const includePaths: Array = ( - (options && options.includePaths) || - [] - ).map(absoluteRoot => path.normalize(path.relative(cwd, absoluteRoot))); + const includePaths = (options.includePaths ?? []).map(absoluteRoot => + path.normalize(path.relative(cwd, absoluteRoot)), + ); - if (options && options.lastCommit) { + if (options.lastCommit) { return findChangedFilesUsingCommand( ['show', '--name-only', '--pretty=format:', 'HEAD', '--'].concat( includePaths, diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index f92cf0bf4f6e..02f1ea6099cd 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -8,22 +8,20 @@ import * as path from 'path'; import execa = require('execa'); -import type {Config} from '@jest/types'; import type {SCMAdapter} from './types'; const env = {...process.env, HGPLAIN: '1'}; const adapter: SCMAdapter = { findChangedFiles: async (cwd, options) => { - const includePaths: Array = - (options && options.includePaths) || []; + const includePaths = options.includePaths ?? []; const args = ['status', '-amnu']; - if (options && options.withAncestor) { + if (options.withAncestor) { args.push('--rev', 'min((!public() & ::.)+.)^'); - } else if (options && options.changedSince) { + } else if (options.changedSince) { args.push('--rev', `ancestor(., ${options.changedSince})`); - } else if (options && options.lastCommit === true) { + } else if (options.lastCommit === true) { args.push('--change', '.'); } args.push(...includePaths);