@@ -766,4 +766,183 @@ describe('detect-node-support', () => {
766
766
} ) ;
767
767
} ) ;
768
768
} ) ;
769
+
770
+ describe ( 'autoDetect()' , ( ) => {
771
+
772
+ it ( 'returns node versions from `.travis.yml` at the path' , async ( ) => {
773
+
774
+ const path = Path . join ( __dirname , '..' ) ;
775
+
776
+ const result = await NodeSupport . autoDetect ( path ) ;
777
+
778
+ internals . assertCommit ( result ) ;
779
+
780
+ expect ( result ) . to . equal ( {
781
+ name : 'detect-node-support' ,
782
+ version : '0.0.0-development' ,
783
+ timestamp : 1580673602000 ,
784
+ travis : {
785
+ raw : [ '10' , '12' , '13' ] ,
786
+ resolved : {
787
+ '10' : '10.19.0' ,
788
+ '12' : '12.15.0' ,
789
+ '13' : '13.8.0'
790
+ }
791
+ } ,
792
+ engines : '>=10'
793
+ } ) ;
794
+ } ) ;
795
+
796
+ it ( 'returns node versions from `.travis.yml` in the repository (url case)' , async ( ) => {
797
+
798
+ listRemoteStub
799
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
800
+
801
+ Nock ( 'https://raw.githubusercontent.com' )
802
+ . get ( '/pkgjs/detect-node-support/HEAD/package.json' )
803
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) )
804
+ . get ( '/pkgjs/detect-node-support/HEAD/.travis.yml' )
805
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
806
+
807
+ const result = await NodeSupport . autoDetect ( 'git+https://github.com/pkgjs/detect-node-support.git' ) ;
808
+
809
+ expect ( listRemoteStub . callCount ) . to . equal ( 1 ) ;
810
+ expect ( listRemoteStub . args [ 0 ] ) . to . equal ( [ [ 'http://github.com/pkgjs/detect-node-support.git' , 'HEAD' ] ] ) ;
811
+
812
+ expect ( result ) . to . equal ( {
813
+ name : 'detect-node-support' ,
814
+ version : '0.0.0-development' ,
815
+ commit : '9cef39d21ad229dea4b10295f55b0d9a83800b23' ,
816
+ timestamp : 1580673602000 ,
817
+ travis : {
818
+ raw : [ '10' , '12' , '13' ] ,
819
+ resolved : {
820
+ '10' : '10.19.0' ,
821
+ '12' : '12.15.0' ,
822
+ '13' : '13.8.0'
823
+ }
824
+ } ,
825
+ engines : '>=10'
826
+ } ) ;
827
+ } ) ;
828
+
829
+ it ( 'returns node versions from `.travis.yml` in the repository ("org/repo" case)' , async ( ) => {
830
+
831
+ listRemoteStub
832
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
833
+
834
+ Nock ( 'https://raw.githubusercontent.com' )
835
+ . get ( '/pkgjs/detect-node-support/HEAD/package.json' )
836
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) )
837
+ . get ( '/pkgjs/detect-node-support/HEAD/.travis.yml' )
838
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
839
+
840
+ const result = await NodeSupport . autoDetect ( 'pkgjs/detect-node-support' ) ;
841
+
842
+ expect ( listRemoteStub . callCount ) . to . equal ( 1 ) ;
843
+ expect ( listRemoteStub . args [ 0 ] ) . to . equal ( [ [ 'http://github.com/pkgjs/detect-node-support' , 'HEAD' ] ] ) ;
844
+
845
+ expect ( result ) . to . equal ( {
846
+ name : 'detect-node-support' ,
847
+ version : '0.0.0-development' ,
848
+ commit : '9cef39d21ad229dea4b10295f55b0d9a83800b23' ,
849
+ timestamp : 1580673602000 ,
850
+ travis : {
851
+ raw : [ '10' , '12' , '13' ] ,
852
+ resolved : {
853
+ '10' : '10.19.0' ,
854
+ '12' : '12.15.0' ,
855
+ '13' : '13.8.0'
856
+ }
857
+ } ,
858
+ engines : '>=10'
859
+ } ) ;
860
+ } ) ;
861
+
862
+ it ( 'returns node versions from `.travis.yml` in the package repository' , async ( ) => {
863
+
864
+ listRemoteStub
865
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
866
+
867
+ Nock ( 'https://raw.githubusercontent.com' )
868
+ . get ( '/pkgjs/detect-node-support/HEAD/package.json' )
869
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) )
870
+ . get ( '/pkgjs/detect-node-support/HEAD/.travis.yml' )
871
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
872
+
873
+ Nock ( 'https://registry.npmjs.org' )
874
+ . get ( '/detect-node-support' )
875
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) ) ;
876
+
877
+ const result = await NodeSupport . autoDetect ( 'detect-node-support' ) ;
878
+
879
+ expect ( listRemoteStub . callCount ) . to . equal ( 1 ) ;
880
+ expect ( listRemoteStub . args [ 0 ] ) . to . equal ( [ [ 'http://github.com/pkgjs/detect-node-support.git' , 'HEAD' ] ] ) ;
881
+
882
+ expect ( result ) . to . equal ( {
883
+ name : 'detect-node-support' ,
884
+ version : '0.0.0-development' ,
885
+ commit : '9cef39d21ad229dea4b10295f55b0d9a83800b23' ,
886
+ timestamp : 1580673602000 ,
887
+ travis : {
888
+ raw : [ '10' , '12' , '13' ] ,
889
+ resolved : {
890
+ '10' : '10.19.0' ,
891
+ '12' : '12.15.0' ,
892
+ '13' : '13.8.0'
893
+ }
894
+ } ,
895
+ engines : '>=10'
896
+ } ) ;
897
+ } ) ;
898
+
899
+ it ( 'returns node versions from `.travis.yml` in the package repository (scoped)' , async ( ) => {
900
+
901
+ listRemoteStub
902
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
903
+
904
+ Nock ( 'https://raw.githubusercontent.com' )
905
+ . get ( '/hapijs/hapi/HEAD/package.json' )
906
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , 'fixtures' , 'hapi-package.json' ) ) )
907
+ . get ( '/hapijs/hapi/HEAD/.travis.yml' )
908
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
909
+
910
+ Nock ( 'https://registry.npmjs.org' )
911
+ . get ( '/@hapi%2fhapi' )
912
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , 'fixtures' , 'hapi-package.json' ) ) ) ;
913
+
914
+ const result = await NodeSupport . autoDetect ( '@hapi/hapi' ) ;
915
+
916
+ expect ( listRemoteStub . callCount ) . to . equal ( 1 ) ;
917
+ expect ( listRemoteStub . args [ 0 ] ) . to . equal ( [ [ 'http://github.com/hapijs/hapi.git' , 'HEAD' ] ] ) ;
918
+
919
+ expect ( result ) . to . equal ( {
920
+ name : '@hapi/hapi' ,
921
+ version : '0.0.0-development' ,
922
+ commit : '9cef39d21ad229dea4b10295f55b0d9a83800b23' ,
923
+ timestamp : 1580673602000 ,
924
+ travis : {
925
+ raw : [ '10' , '12' , '13' ] ,
926
+ resolved : {
927
+ '10' : '10.19.0' ,
928
+ '12' : '12.15.0' ,
929
+ '13' : '13.8.0'
930
+ }
931
+ }
932
+ } ) ;
933
+ } ) ;
934
+
935
+ it ( 'rethrows URL parser errors' , async ( ) => {
936
+
937
+ const badUrl = {
938
+ toString : ( ) => {
939
+
940
+ // dirty way to avoid getting an ERR_INVALID_URL from new Url()
941
+ throw new Error ( 'Bad URL' ) ;
942
+ }
943
+ } ;
944
+
945
+ await expect ( NodeSupport . autoDetect ( badUrl ) ) . to . reject ( 'Bad URL' ) ;
946
+ } ) ;
947
+ } ) ;
769
948
} ) ;
0 commit comments