@@ -71,41 +71,40 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger*/) =>
7171 }
7272 }
7373 // ensure we are using a preset
74- presetName = presetName || JestPresetNames . default
74+ presetName = presetName ?? JestPresetNames . default
7575 preset = allPresets [ presetName ]
7676 footNotes . push (
7777 `Detected preset '${ preset . label } ' as the best matching preset for your configuration.
7878Visit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.
7979` ,
8080 )
81- } else if ( migratedConfig . preset && migratedConfig . preset . startsWith ( 'ts-jest' ) ) {
81+ } else if ( migratedConfig . preset ? .startsWith ( 'ts-jest' ) ) {
8282 if ( args . jestPreset === false ) {
8383 delete migratedConfig . preset
8484 } else {
8585 // eslint-disable-next-line @typescript-eslint/no-explicit-any
86- preset = ( allPresets as any ) [ migratedConfig . preset ] || defaults
86+ preset = ( allPresets as any ) [ migratedConfig . preset ] ?? defaults
8787 }
8888 }
8989
9090 // enforce the correct name
9191 if ( preset ) migratedConfig . preset = preset . name
9292
9393 // check the extensions
94- if ( migratedConfig . moduleFileExtensions && migratedConfig . moduleFileExtensions . length && preset ) {
95- const presetValue = dedupSort ( preset . value . moduleFileExtensions || [ ] ) . join ( '::' )
94+ if ( migratedConfig . moduleFileExtensions ? .length && preset ) {
95+ const presetValue = dedupSort ( preset . value . moduleFileExtensions ?? [ ] ) . join ( '::' )
9696 const migratedValue = dedupSort ( migratedConfig . moduleFileExtensions ) . join ( '::' )
9797 if ( presetValue === migratedValue ) {
9898 delete migratedConfig . moduleFileExtensions
9999 }
100100 }
101101 // there is a testRegex, remove our testMatch
102- if ( migratedConfig . testRegex && preset ) {
103- // eslint-disable-next-line @typescript-eslint/no-explicit-any
104- migratedConfig . testMatch = null as any
102+ if ( ( typeof migratedConfig . testRegex === 'string' || migratedConfig . testRegex ?. length ) && preset ) {
103+ delete migratedConfig . testMatch
105104 }
106105 // check the testMatch
107- else if ( migratedConfig . testMatch && migratedConfig . testMatch . length && preset ) {
108- const presetValue = dedupSort ( preset . value . testMatch || [ ] ) . join ( '::' )
106+ else if ( migratedConfig . testMatch ? .length && preset ) {
107+ const presetValue = dedupSort ( preset . value . testMatch ?? [ ] ) . join ( '::' )
109108 const migratedValue = dedupSort ( migratedConfig . testMatch ) . join ( '::' )
110109 if ( presetValue === migratedValue ) {
111110 delete migratedConfig . testMatch
@@ -190,20 +189,20 @@ function cleanupConfig(config: Config.InitialOptions): void {
190189 // eslint-disable-next-line @typescript-eslint/no-explicit-any
191190 delete ( config as any ) . globals [ 'ts-jest' ]
192191 }
193- if ( Object . keys ( config . globals ) . length === 0 ) {
192+ if ( ! Object . keys ( config . globals ) . length ) {
194193 delete config . globals
195194 }
196195 }
197- if ( config . transform && Object . keys ( config . transform ) . length === 0 ) {
196+ if ( config . transform && ! Object . keys ( config . transform ) . length ) {
198197 delete config . transform
199198 }
200199 if ( config . moduleFileExtensions ) {
201200 config . moduleFileExtensions = dedupSort ( config . moduleFileExtensions )
202- if ( config . moduleFileExtensions . length === 0 ) delete config . moduleFileExtensions
201+ if ( ! config . moduleFileExtensions . length ) delete config . moduleFileExtensions
203202 }
204203 if ( config . testMatch ) {
205204 config . testMatch = dedupSort ( config . testMatch )
206- if ( config . testMatch . length === 0 ) delete config . testMatch
205+ if ( ! config . testMatch . length ) delete config . testMatch
207206 }
208207 if ( config . preset === JestPresetNames . default ) config . preset = defaults . name
209208}
0 commit comments