@@ -4,9 +4,11 @@ jest.mock('path');
4
4
import * as ts from 'typescript' ;
5
5
import getTSConfig from '../../dist/utils/get-ts-config' ;
6
6
import * as path from 'path' ;
7
- import jestConfig from '../__helpers__/jest-config' ;
7
+ import mockJestConfig from '../__helpers__/mock- jest-config' ;
8
8
import getTSJestConfig from '../../dist/utils/get-ts-jest-config' ;
9
9
10
+ const TEST_CASE = 'tsconfig-test' ;
11
+
10
12
describe ( 'get default ts config' , ( ) => {
11
13
beforeEach ( ( ) => {
12
14
// Set up some mocked out file info before each test
@@ -19,44 +21,46 @@ describe('get default ts config', () => {
19
21
// there is no tsconfig file in that test module
20
22
( ( path as any ) as MockedPath ) . __setBaseDir ( './tests/jestconfig-test' ) ;
21
23
22
- expect ( ( ) => getTSConfig ( jestConfig . jestconfigTest ( null ) ) ) . toThrowError (
24
+ expect ( ( ) => getTSConfig ( mockJestConfig ( 'jestconfig-test' ) ) ) . toThrowError (
23
25
/ u n a b l e t o f i n d t s c o n f i g u r a t i o n f i l e / i,
24
26
) ;
25
27
} ) ;
26
28
27
29
it ( 'should correctly read tsconfig.json' , ( ) => {
28
- const result = getTSConfig ( jestConfig . tsconfigTest ( null ) ) ;
30
+ const result = getTSConfig ( mockJestConfig ( TEST_CASE ) ) ;
29
31
30
32
expect ( result ) . toMatchSnapshot ( ) ;
31
33
} ) ;
32
34
33
35
describe ( 'new behavior (tsConfigFile & tsConfig)' , ( ) => {
34
36
it ( 'should be same results for null/undefined/etc.' , ( ) => {
35
- const result = getTSConfig ( jestConfig . tsconfigTest ( null ) ) ;
36
- const resultEmptyParam = getTSConfig ( jestConfig . tsconfigTest ( { } ) ) ;
37
+ const resultWithoutTsJestSection = getTSConfig (
38
+ mockJestConfig ( TEST_CASE , null ) ,
39
+ ) ;
40
+ const resultEmptyParam = getTSConfig ( mockJestConfig ( TEST_CASE , { } ) ) ;
37
41
const resultUndefinedContentFile = getTSConfig (
38
- jestConfig . tsconfigTest ( { tsConfigFile : undefined } ) ,
42
+ mockJestConfig ( TEST_CASE , { tsConfigFile : undefined } ) ,
39
43
) ;
40
44
const resultNullContentFile = getTSConfig (
41
- jestConfig . tsconfigTest ( { tsConfigFile : null } ) ,
45
+ mockJestConfig ( TEST_CASE , { tsConfigFile : null } ) ,
42
46
) ;
43
47
44
- expect ( result ) . toEqual ( resultEmptyParam ) ;
45
- expect ( result ) . toEqual ( resultUndefinedContentFile ) ;
46
- expect ( result ) . toEqual ( resultNullContentFile ) ;
48
+ expect ( resultEmptyParam ) . toEqual ( resultWithoutTsJestSection ) ;
49
+ expect ( resultUndefinedContentFile ) . toEqual ( resultWithoutTsJestSection ) ;
50
+ expect ( resultNullContentFile ) . toEqual ( resultWithoutTsJestSection ) ;
47
51
} ) ;
48
52
49
53
it ( 'should be different results for different rootDir with same jest config.' , ( ) => {
50
- const rootConfig = getTSConfig ( jestConfig . tsconfigTest ( ) ) ;
54
+ const rootConfig = getTSConfig ( mockJestConfig ( TEST_CASE ) ) ;
51
55
const subConfig = getTSConfig (
52
- jestConfig ( 'tsconfig-test /tsconfig-module' ) ,
56
+ mockJestConfig ( ` ${ TEST_CASE } /tsconfig-module` ) ,
53
57
) ;
54
58
expect ( rootConfig ) . not . toEqual ( subConfig ) ;
55
59
} ) ;
56
60
57
61
it ( 'should not change the module if it is loaded from a non-default config file' , ( ) => {
58
62
const config = getTSConfig (
59
- jestConfig . tsconfigTest ( {
63
+ mockJestConfig ( TEST_CASE , {
60
64
tsConfigFile : 'tsconfig-module/custom-config.json' ,
61
65
} ) ,
62
66
) ;
@@ -73,7 +77,9 @@ describe('get default ts config', () => {
73
77
'./tests/tsconfig-test/tsconfig-module' ,
74
78
) ;
75
79
76
- const config = getTSConfig ( jestConfig ( 'tsconfig-test/tsconfig-module' ) ) ;
80
+ const config = getTSConfig (
81
+ mockJestConfig ( `${ TEST_CASE } /tsconfig-module` ) ,
82
+ ) ;
77
83
78
84
expect ( config . module ) . toBe ( ts . ModuleKind . CommonJS ) ;
79
85
} ) ;
0 commit comments