@@ -802,18 +802,7 @@ describe('readTsConfig', () => {
802
802
803
803
describe ( 'mismatch nodejs version and typescript target' , ( ) => {
804
804
const logTarget = logTargetMock ( )
805
-
806
- beforeEach ( ( ) => {
807
- logTarget . clear ( )
808
- cs = createConfigSet ( { jestConfig : { rootDir : '/root' , cwd : '/cwd' } as any } )
809
- findConfig . mockImplementation ( ( p : string ) => `${ p } /tsconfig.json` )
810
- } )
811
-
812
- afterEach ( ( ) => {
813
- findConfig . mockClear ( )
814
- } )
815
-
816
- function mismatchTestCaseContent ( tsTarget : string , scriptTarget : ts . ScriptTarget ) {
805
+ function mismatchTestCaseContent ( rawTarget : string | undefined , scriptTarget : ts . ScriptTarget ) {
817
806
parseConfig . mockImplementation ( ( conf : any ) => ( {
818
807
options : {
819
808
...conf ,
@@ -822,35 +811,101 @@ describe('readTsConfig', () => {
822
811
fileNames : [ ] ,
823
812
errors : [ ] ,
824
813
} ) )
825
- readConfig . mockImplementation ( ( p ) => ( { config : { path : p , compilerOptions : { target : tsTarget } } } ) )
814
+ readConfig . mockImplementation ( ( p ) => ( { config : { path : p , compilerOptions : { target : rawTarget } } } ) )
826
815
827
816
cs . readTsConfig ( )
828
-
829
- // expect.toEqual gives weird result here so toContain is workaround for it.
830
- expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toContain (
831
- '[level:40] There is a mismatch between your ' +
832
- `NodeJs version ${ process . version } and your TypeScript target ${ tsTarget } . This might lead to some unexpected errors ` +
833
- 'when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping' ,
834
- )
835
-
836
- parseConfig . mockClear ( )
837
- readConfig . mockClear ( )
838
817
}
839
818
840
- /**
841
- * It seems like not possible to mock process.version so the condition here is needed
842
- */
843
- if ( process . version . startsWith ( 'v10' ) ) {
844
- // eslint-disable-next-line jest/expect-expect
845
- it ( 'should show warning message when nodejs version is 10 and typescript target is higher than es2018' , ( ) => {
846
- mismatchTestCaseContent ( 'es2019' , ts . ScriptTarget . ES2019 )
819
+ describe . each ( [
820
+ { jestConfig : { rootDir : '/root' , cwd : '/cwd' } as any , tsJestConfig : { babelConfig : true } } ,
821
+ { jestConfig : { rootDir : '/root' , cwd : '/cwd' } as any } ,
822
+ ] ) ( 'toggle warning message for users who are using ts-jest with babel or without babel' , ( config ) => {
823
+ const shouldAction = config . tsJestConfig ?. babelConfig ? `shouldn't` : 'should'
824
+ beforeEach ( ( ) => {
825
+ logTarget . clear ( )
826
+ cs = createConfigSet ( config )
827
+ findConfig . mockImplementation ( ( p : string ) => `${ p } /tsconfig.json` )
847
828
} )
848
- } else {
849
- // eslint-disable-next-line jest/expect-expect
850
- it ( 'should show warning message when nodejs version is 12 and typescript target is higher than es2019' , ( ) => {
851
- mismatchTestCaseContent ( 'es2020' , ts . ScriptTarget . ES2020 )
829
+
830
+ afterEach ( ( ) => {
831
+ findConfig . mockClear ( )
832
+ parseConfig . mockClear ( )
833
+ readConfig . mockClear ( )
852
834
} )
853
- }
835
+
836
+ /**
837
+ * It seems like not possible to mock process.version so the condition here is needed
838
+ */
839
+ if ( process . version . startsWith ( 'v10' ) ) {
840
+ it (
841
+ `${ shouldAction } show warning message when nodejs version is 10 and typescript target is higher than es2018` +
842
+ ` with tsconfig contains target` ,
843
+ ( ) => {
844
+ mismatchTestCaseContent ( 'es2019' , ts . ScriptTarget . ES2019 )
845
+ // eslint-disable-next-line
846
+ config . tsJestConfig ?. babelConfig
847
+ ? expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toBeUndefined ( )
848
+ : // expect.toEqual gives weird result here so toContain is workaround for it.
849
+ expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toContain (
850
+ '[level:40] There is a mismatch between your ' +
851
+ `NodeJs version ${ process . version } and your TypeScript target es2019. This might lead to some unexpected errors ` +
852
+ 'when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping' ,
853
+ )
854
+ } ,
855
+ )
856
+
857
+ it (
858
+ `${ shouldAction } show warning message when nodejs version is 10 and typescript target is higher than es2018` +
859
+ ` with tsconfig doesn't contain target` ,
860
+ ( ) => {
861
+ mismatchTestCaseContent ( undefined , ts . ScriptTarget . ES2019 )
862
+ // eslint-disable-next-line
863
+ config . tsJestConfig ?. babelConfig
864
+ ? expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toBeUndefined ( )
865
+ : // expect.toEqual gives weird result here so toContain is workaround for it.
866
+ expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toContain (
867
+ '[level:40] There is a mismatch between your ' +
868
+ `NodeJs version ${ process . version } and your TypeScript target es2019. This might lead to some unexpected errors ` +
869
+ 'when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping' ,
870
+ )
871
+ } ,
872
+ )
873
+ } else {
874
+ it (
875
+ `${ shouldAction } show warning message when nodejs version is 12 and typescript target is higher than es2019` +
876
+ ` with tsconfig contains target` ,
877
+ ( ) => {
878
+ mismatchTestCaseContent ( 'es2020' , ts . ScriptTarget . ES2020 )
879
+ // eslint-disable-next-line
880
+ config . tsJestConfig ?. babelConfig
881
+ ? expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toBeUndefined ( )
882
+ : // expect.toEqual gives weird result here so toContain is workaround for it.
883
+ expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toContain (
884
+ '[level:40] There is a mismatch between your ' +
885
+ `NodeJs version ${ process . version } and your TypeScript target es2020. This might lead to some unexpected errors ` +
886
+ 'when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping' ,
887
+ )
888
+ } ,
889
+ )
890
+
891
+ it (
892
+ `${ shouldAction } show warning message when nodejs version is 12 and typescript target is higher than es2019` +
893
+ ` with tsconfig doesn't target` ,
894
+ ( ) => {
895
+ mismatchTestCaseContent ( undefined , ts . ScriptTarget . ES2020 )
896
+ // eslint-disable-next-line
897
+ config . tsJestConfig ?. babelConfig
898
+ ? expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toBeUndefined ( )
899
+ : // expect.toEqual gives weird result here so toContain is workaround for it.
900
+ expect ( logTarget . filteredLines ( LogLevels . warn , Infinity ) [ 0 ] ) . toContain (
901
+ '[level:40] There is a mismatch between your ' +
902
+ `NodeJs version ${ process . version } and your TypeScript target es2020. This might lead to some unexpected errors ` +
903
+ 'when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping' ,
904
+ )
905
+ } ,
906
+ )
907
+ }
908
+ } )
854
909
} )
855
910
} ) // readTsConfig
856
911
0 commit comments