File tree Expand file tree Collapse file tree 3 files changed +30
-18
lines changed Expand file tree Collapse file tree 3 files changed +30
-18
lines changed Original file line number Diff line number Diff line change 11import type { Config } from '@jest/types'
2+ import type { Logger } from 'bs-logger'
23import { resolve } from 'path'
34
45import { createCompilerInstance } from '../compiler/instance'
@@ -57,15 +58,17 @@ export const defaultResolve = (path: string): string => `resolved:${path}`
5758export function createConfigSet ( {
5859 jestConfig,
5960 tsJestConfig,
61+ logger, // don't change this key name, otherwise mock logging won't work
6062 resolve = defaultResolve ,
6163 ...others
6264} : {
6365 jestConfig ?: Partial < Config . ProjectConfig >
6466 tsJestConfig ?: TsJestGlobalOptions
67+ logger ?: Logger
6568 resolve ?: ( ( path : string ) => string ) | null
6669 [ key : string ] : any
6770} = { } ) : ConfigSet {
68- const cs = new ConfigSet ( getJestConfig ( jestConfig , tsJestConfig ) )
71+ const cs = new ConfigSet ( getJestConfig ( jestConfig , tsJestConfig ) , logger )
6972 if ( resolve ) {
7073 cs . resolvePath = resolve
7174 }
Original file line number Diff line number Diff line change 11/* eslint-disable jest/no-mocks-import */
22import type { Transformer } from '@jest/transform'
3- import { testing } from 'bs-logger'
3+ import { LogLevels , testing } from 'bs-logger'
44import { join , resolve } from 'path'
55import ts from 'typescript'
66
@@ -31,20 +31,23 @@ beforeEach(() => {
3131
3232describe ( 'packageJson' , ( ) => {
3333 it ( 'should not contain packageJson in final tsJest config' , ( ) => {
34- expect (
35- Object . keys (
36- createConfigSet ( {
37- jestConfig : {
38- globals : {
39- 'ts-jest' : {
40- packageJson : true ,
41- } ,
42- } ,
43- } as any ,
44- resolve : null ,
45- } ) ,
46- ) ,
47- ) . not . toContain ( 'packageJson' )
34+ const logger = testing . createLoggerMock ( )
35+ createConfigSet ( {
36+ jestConfig : {
37+ globals : {
38+ 'ts-jest' : {
39+ packageJson : true ,
40+ } ,
41+ } ,
42+ } as any ,
43+ resolve : null ,
44+ logger,
45+ } )
46+
47+ expect ( logger . target . filteredLines ( LogLevels . warn ) [ 0 ] ) . toMatchInlineSnapshot ( `
48+ "[level:40] The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\`
49+ "
50+ ` )
4851 } )
4952} ) // packageJson
5053
Original file line number Diff line number Diff line change @@ -145,8 +145,14 @@ export class ConfigSet {
145145 tsBuildInfoFile : undefined ,
146146 }
147147
148- constructor ( private readonly jestConfig : Config . ProjectConfig ) {
149- this . logger = rootLogger . child ( { [ LogContexts . namespace ] : 'config' } )
148+ constructor (
149+ private readonly jestConfig : Config . ProjectConfig ,
150+ // mainly for testing logging
151+ private readonly parentLogger ?: Logger ,
152+ ) {
153+ this . logger = this . parentLogger
154+ ? this . parentLogger . child ( { [ LogContexts . namespace ] : 'config' } )
155+ : rootLogger . child ( { namespace : 'config' } )
150156 this . _cwd = normalize ( this . jestConfig . cwd ?? process . cwd ( ) )
151157 this . _rootDir = normalize ( this . jestConfig . rootDir ?? this . _cwd )
152158 const tsJestCfg = this . jestConfig . globals && this . jestConfig . globals [ 'ts-jest' ]
You can’t perform that action at this time.
0 commit comments