@@ -71,41 +71,40 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger*/) =>
71
71
}
72
72
}
73
73
// ensure we are using a preset
74
- presetName = presetName || JestPresetNames . default
74
+ presetName = presetName ?? JestPresetNames . default
75
75
preset = allPresets [ presetName ]
76
76
footNotes . push (
77
77
`Detected preset '${ preset . label } ' as the best matching preset for your configuration.
78
78
Visit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.
79
79
` ,
80
80
)
81
- } else if ( migratedConfig . preset && migratedConfig . preset . startsWith ( 'ts-jest' ) ) {
81
+ } else if ( migratedConfig . preset ? .startsWith ( 'ts-jest' ) ) {
82
82
if ( args . jestPreset === false ) {
83
83
delete migratedConfig . preset
84
84
} else {
85
85
// 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
87
87
}
88
88
}
89
89
90
90
// enforce the correct name
91
91
if ( preset ) migratedConfig . preset = preset . name
92
92
93
93
// 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 ( '::' )
96
96
const migratedValue = dedupSort ( migratedConfig . moduleFileExtensions ) . join ( '::' )
97
97
if ( presetValue === migratedValue ) {
98
98
delete migratedConfig . moduleFileExtensions
99
99
}
100
100
}
101
101
// 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
105
104
}
106
105
// 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 ( '::' )
109
108
const migratedValue = dedupSort ( migratedConfig . testMatch ) . join ( '::' )
110
109
if ( presetValue === migratedValue ) {
111
110
delete migratedConfig . testMatch
@@ -190,20 +189,20 @@ function cleanupConfig(config: Config.InitialOptions): void {
190
189
// eslint-disable-next-line @typescript-eslint/no-explicit-any
191
190
delete ( config as any ) . globals [ 'ts-jest' ]
192
191
}
193
- if ( Object . keys ( config . globals ) . length === 0 ) {
192
+ if ( ! Object . keys ( config . globals ) . length ) {
194
193
delete config . globals
195
194
}
196
195
}
197
- if ( config . transform && Object . keys ( config . transform ) . length === 0 ) {
196
+ if ( config . transform && ! Object . keys ( config . transform ) . length ) {
198
197
delete config . transform
199
198
}
200
199
if ( config . moduleFileExtensions ) {
201
200
config . moduleFileExtensions = dedupSort ( config . moduleFileExtensions )
202
- if ( config . moduleFileExtensions . length === 0 ) delete config . moduleFileExtensions
201
+ if ( ! config . moduleFileExtensions . length ) delete config . moduleFileExtensions
203
202
}
204
203
if ( config . testMatch ) {
205
204
config . testMatch = dedupSort ( config . testMatch )
206
- if ( config . testMatch . length === 0 ) delete config . testMatch
205
+ if ( ! config . testMatch . length ) delete config . testMatch
207
206
}
208
207
if ( config . preset === JestPresetNames . default ) config . preset = defaults . name
209
208
}
0 commit comments