@@ -125,24 +125,44 @@ const toDiagnosticCodeList = (items: (string | number)[], into: number[] = []):
125125}
126126
127127export class ConfigSet {
128+ readonly logger : Logger
128129 /**
129130 * @internal
130131 */
131- @Memoize ( )
132- private get jest ( ) : Config . ProjectConfig {
132+ private readonly _cwd : string
133+ /**
134+ * @internal
135+ */
136+ private readonly _rootDir : string
137+ /**
138+ * @internal
139+ */
140+ private _jestCfg ! : Config . ProjectConfig
141+
142+ constructor ( private readonly jestConfig : Config . ProjectConfig ) {
143+ this . logger = rootLogger . child ( { [ LogContexts . namespace ] : 'config' } )
144+ this . _cwd = normalize ( this . jestConfig . cwd ?? process . cwd ( ) )
145+ this . _rootDir = normalize ( this . jestConfig . rootDir ?? this . _cwd )
146+ this . _backportJestCfg ( )
147+ }
148+
149+ /**
150+ * @internal
151+ */
152+ private _backportJestCfg ( ) : void {
133153 const config = backportJestConfig ( this . logger , this . jestConfig )
134154
135155 this . logger . debug ( { jestConfig : config } , 'normalized jest config' )
136156
137- return config
157+ this . _jestCfg = config
138158 }
139159
140160 /**
141161 * @internal
142162 */
143163 @Memoize ( )
144164 get isTestFile ( ) : ( fileName : string ) => boolean {
145- const matchablePatterns = [ ...this . jest . testMatch , ...this . jest . testRegex ] . filter (
165+ const matchablePatterns = [ ...this . _jestCfg . testMatch , ...this . _jestCfg . testRegex ] . filter (
146166 ( pattern ) =>
147167 /**
148168 * jest config testRegex doesn't always deliver the correct RegExp object
@@ -165,7 +185,7 @@ export class ConfigSet {
165185 */
166186 @Memoize ( )
167187 get tsJest ( ) : TsJestConfig {
168- const parsedConfig = this . jest
188+ const parsedConfig = this . _jestCfg
169189 const { globals = { } } = parsedConfig as any
170190 const options : TsJestGlobalOptions = { ...globals [ 'ts-jest' ] }
171191
@@ -601,7 +621,7 @@ export class ConfigSet {
601621 */
602622 @Memoize ( )
603623 get tsCacheDir ( ) : string | undefined {
604- if ( ! this . jest . cache ) {
624+ if ( ! this . _jestCfg . cache ) {
605625 this . logger . debug ( 'file caching disabled' )
606626
607627 return undefined
@@ -616,7 +636,7 @@ export class ConfigSet {
616636 diagnostics : this . tsJest . diagnostics ,
617637 } ) ,
618638 )
619- const res = join ( this . jest . cacheDirectory , 'ts-jest' , cacheSuffix . substr ( 0 , 2 ) , cacheSuffix . substr ( 2 ) )
639+ const res = join ( this . _jestCfg . cacheDirectory , 'ts-jest' , cacheSuffix . substr ( 0 , 2 ) , cacheSuffix . substr ( 2 ) )
620640
621641 this . logger . debug ( { cacheDirectory : res } , 'will use file caching' )
622642
@@ -657,17 +677,6 @@ export class ConfigSet {
657677 return options
658678 }
659679
660- /**
661- * @internal
662- */
663- @Memoize ( )
664- get rootDir ( ) : string {
665- return normalize ( this . jest . rootDir || this . cwd )
666- }
667-
668- /**
669- * @internal
670- */
671680 get cwd ( ) : string {
672681 return this . _cwd
673682 }
@@ -681,14 +690,6 @@ export class ConfigSet {
681690 return MY_DIGEST
682691 }
683692
684- readonly logger : Logger
685- private readonly _cwd : string
686-
687- constructor ( private readonly jestConfig : Config . ProjectConfig ) {
688- this . logger = rootLogger . child ( { [ LogContexts . namespace ] : 'config' } )
689- this . _cwd = normalize ( this . jestConfig . cwd ?? process . cwd ( ) )
690- }
691-
692693 /**
693694 * @internal
694695 */
@@ -742,15 +743,15 @@ export class ConfigSet {
742743 noProject ?: boolean | null ,
743744 ) : ParsedCommandLine {
744745 let config = { compilerOptions : Object . create ( null ) }
745- let basePath = normalizeSlashes ( this . rootDir )
746+ let basePath = normalizeSlashes ( this . _rootDir )
746747 let configFileName : string | undefined
747748 const ts = this . compilerModule
748749
749750 if ( ! noProject ) {
750751 // Read project configuration when available.
751752 configFileName = resolvedConfigFile
752753 ? normalizeSlashes ( resolvedConfigFile )
753- : ts . findConfigFile ( normalizeSlashes ( this . rootDir ) , ts . sys . fileExists )
754+ : ts . findConfigFile ( normalizeSlashes ( this . _rootDir ) , ts . sys . fileExists )
754755
755756 if ( configFileName ) {
756757 this . logger . debug ( { tsConfigFileName : configFileName } , 'readTsConfig(): reading' , configFileName )
@@ -841,17 +842,14 @@ export class ConfigSet {
841842 return result
842843 }
843844
844- /**
845- * @internal
846- */
847845 resolvePath (
848846 inputPath : string ,
849847 { throwIfMissing = true , nodeResolve = false } : { throwIfMissing ?: boolean ; nodeResolve ?: boolean } = { } ,
850848 ) : string {
851849 let path : string = inputPath
852850 let nodeResolved = false
853851 if ( path . startsWith ( '<rootDir>' ) ) {
854- path = resolve ( join ( this . rootDir , path . substr ( 9 ) ) )
852+ path = resolve ( join ( this . _rootDir , path . substr ( 9 ) ) )
855853 } else if ( ! isAbsolute ( path ) ) {
856854 if ( ! path . startsWith ( '.' ) && nodeResolve ) {
857855 try {
0 commit comments