@@ -794,4 +794,110 @@ test.group('Compiler', (group) => {
794
794
795
795
assert . deepEqual ( hasFiles , [ true , true , false ] )
796
796
} ) . timeout ( 0 )
797
+
798
+ test ( 'typecheck and report typescript errors' , async ( assert ) => {
799
+ await fs . add (
800
+ '.adonisrc.json' ,
801
+ JSON . stringify ( {
802
+ typescript : true ,
803
+ metaFiles : [ 'public/**/*.(js|css)' ] ,
804
+ } )
805
+ )
806
+
807
+ await fs . add (
808
+ 'tsconfig.json' ,
809
+ JSON . stringify ( {
810
+ include : [ '**/*' ] ,
811
+ exclude : [ 'build' ] ,
812
+ compilerOptions : {
813
+ rootDir : './' ,
814
+ outDir : 'build/dist' ,
815
+ } ,
816
+ } )
817
+ )
818
+
819
+ await fs . add ( 'ace' , '' )
820
+ await fs . add ( 'src/foo.ts' , "import path from 'path'" )
821
+ await fs . add ( 'public/styles/main.css' , '' )
822
+ await fs . add ( 'public/scripts/main.js' , '' )
823
+
824
+ const compiler = new Compiler ( fs . basePath , [ ] , false , ui . logger )
825
+ const isValid = await compiler . typeCheck ( )
826
+
827
+ assert . isFalse ( isValid )
828
+ const hasFiles = await Promise . all (
829
+ [
830
+ 'build/dist/.adonisrc.json' ,
831
+ 'build/dist/src/foo.js' ,
832
+ 'build/dist/public/styles/main.css' ,
833
+ 'build/dist/public/scripts/main.js' ,
834
+ ] . map ( ( file ) => fs . fsExtra . pathExists ( join ( fs . basePath , file ) ) )
835
+ )
836
+
837
+ assert . deepEqual ( hasFiles , [ false , false , false , false ] )
838
+
839
+ assert . deepEqual ( ui . testingRenderer . logs , [
840
+ {
841
+ message : `${ info } type checking typescript source files` ,
842
+ stream : 'stdout' ,
843
+ } ,
844
+ {
845
+ message : `${ error } typescript compiler errors` ,
846
+ stream : 'stderr' ,
847
+ } ,
848
+ ] )
849
+ } ) . timeout ( 0 )
850
+
851
+ test ( 'complete successfully when typechecking has no errors' , async ( assert ) => {
852
+ await fs . add (
853
+ '.adonisrc.json' ,
854
+ JSON . stringify ( {
855
+ typescript : true ,
856
+ metaFiles : [ 'public/**/*.(js|css)' ] ,
857
+ } )
858
+ )
859
+
860
+ await fs . add (
861
+ 'tsconfig.json' ,
862
+ JSON . stringify ( {
863
+ include : [ '**/*' ] ,
864
+ exclude : [ 'build' ] ,
865
+ compilerOptions : {
866
+ rootDir : './' ,
867
+ outDir : 'build/dist' ,
868
+ } ,
869
+ } )
870
+ )
871
+
872
+ await fs . add ( 'ace' , '' )
873
+ await fs . add ( 'src/foo.ts' , "import 'path'" )
874
+ await fs . add ( 'public/styles/main.css' , '' )
875
+ await fs . add ( 'public/scripts/main.js' , '' )
876
+
877
+ const compiler = new Compiler ( fs . basePath , [ ] , false , ui . logger )
878
+ const isValid = await compiler . typeCheck ( )
879
+
880
+ assert . isTrue ( isValid )
881
+ const hasFiles = await Promise . all (
882
+ [
883
+ 'build/dist/.adonisrc.json' ,
884
+ 'build/dist/src/foo.js' ,
885
+ 'build/dist/public/styles/main.css' ,
886
+ 'build/dist/public/scripts/main.js' ,
887
+ ] . map ( ( file ) => fs . fsExtra . pathExists ( join ( fs . basePath , file ) ) )
888
+ )
889
+
890
+ assert . deepEqual ( hasFiles , [ false , false , false , false ] )
891
+
892
+ assert . deepEqual ( ui . testingRenderer . logs , [
893
+ {
894
+ message : `${ info } type checking typescript source files` ,
895
+ stream : 'stdout' ,
896
+ } ,
897
+ {
898
+ message : `${ success } built successfully` ,
899
+ stream : 'stdout' ,
900
+ } ,
901
+ ] )
902
+ } ) . timeout ( 0 )
797
903
} )
0 commit comments