@@ -13,6 +13,11 @@ import {
13
13
shouldOpenInExistingInstance ,
14
14
splitOnFirstEquals ,
15
15
toVsCodeArgs ,
16
+ optionDescriptions ,
17
+ options ,
18
+ Options ,
19
+ AuthType ,
20
+ OptionalString ,
16
21
} from "../../../src/node/cli"
17
22
import { shouldSpawnCliProcess } from "../../../src/node/main"
18
23
import { generatePassword , paths } from "../../../src/node/util"
@@ -753,3 +758,97 @@ describe("toVsCodeArgs", () => {
753
758
} )
754
759
} )
755
760
} )
761
+
762
+ describe ( "optionDescriptions" , ( ) => {
763
+ it ( "should return the descriptions of all the available options" , ( ) => {
764
+ const expectedOptionDescriptions = Object . entries ( options )
765
+ . flat ( )
766
+ . filter ( ( item : any ) => {
767
+ if ( item . description ) {
768
+ return item . description
769
+ }
770
+ } )
771
+ . map ( ( item : any ) => item . description )
772
+ const actualOptionDescriptions = optionDescriptions ( )
773
+ // We need both the expected and the actual
774
+ // Both of these are string[]
775
+ // We then loop through the expectedOptionDescriptions
776
+ // and check that this expectedDescription exists in the
777
+ // actualOptionDescriptions
778
+
779
+ // To do that we need to loop through actualOptionDescriptions
780
+ // and make sure we have a substring match
781
+ expectedOptionDescriptions . forEach ( ( expectedDescription ) => {
782
+ const exists = actualOptionDescriptions . find ( ( desc ) => {
783
+ if (
784
+ desc . replace ( / \n / g, " " ) . replace ( / / g, "" ) . includes ( expectedDescription . replace ( / \n / g, " " ) . replace ( / / g, "" ) )
785
+ ) {
786
+ return true
787
+ }
788
+ return false
789
+ } )
790
+ expect ( exists ) . toBeTruthy ( )
791
+ } )
792
+ } )
793
+ it ( "should visually align multiple options" , ( ) => {
794
+ const opts : Partial < Options < Required < UserProvidedArgs > > > = {
795
+ "cert-key" : { type : "string" , path : true , description : "Path to certificate key when using non-generated cert." } ,
796
+ "cert-host" : {
797
+ type : "string" ,
798
+ description : "Hostname to use when generating a self signed certificate." ,
799
+ } ,
800
+ "disable-update-check" : {
801
+ type : "boolean" ,
802
+ description :
803
+ "Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and \n" +
804
+ "then notifies you once every week that a new release is available." ,
805
+ } ,
806
+ }
807
+ expect ( optionDescriptions ( opts ) ) . toStrictEqual ( [
808
+ " --cert-key Path to certificate key when using non-generated cert." ,
809
+ " --cert-host Hostname to use when generating a self signed certificate." ,
810
+ ` --disable-update-check Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and
811
+ then notifies you once every week that a new release is available.` ,
812
+ ] )
813
+ } )
814
+ it ( "should add all valid options for enumerated types" , ( ) => {
815
+ const opts : Partial < Options < Required < UserProvidedArgs > > > = {
816
+ auth : { type : AuthType , description : "The type of authentication to use." } ,
817
+ }
818
+ expect ( optionDescriptions ( opts ) ) . toStrictEqual ( [ " --auth The type of authentication to use. [password, none]" ] )
819
+ } )
820
+
821
+ it ( "should show if an option is deprecated" , ( ) => {
822
+ const opts : Partial < Options < Required < UserProvidedArgs > > > = {
823
+ link : {
824
+ type : OptionalString ,
825
+ description : `
826
+ Securely bind code-server via our cloud service with the passed name. You'll get a URL like
827
+ https://hostname-username.coder.co at which you can easily access your code-server instance.
828
+ Authorization is done via GitHub.
829
+ ` ,
830
+ deprecated : true ,
831
+ } ,
832
+ }
833
+ expect ( optionDescriptions ( opts ) ) . toStrictEqual ( [
834
+ ` --link (deprecated) Securely bind code-server via our cloud service with the passed name. You'll get a URL like
835
+ https://hostname-username.coder.co at which you can easily access your code-server instance.
836
+ Authorization is done via GitHub.` ,
837
+ ] )
838
+ } )
839
+
840
+ it ( "should show newlines in description" , ( ) => {
841
+ const opts : Partial < Options < Required < UserProvidedArgs > > > = {
842
+ "install-extension" : {
843
+ type : "string[]" ,
844
+ description :
845
+ "Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.\n" +
846
+ "To install a specific version provide `@${version}`. For example: 'vscode.csharp@1.2.3'." ,
847
+ } ,
848
+ }
849
+ expect ( optionDescriptions ( opts ) ) . toStrictEqual ( [
850
+ ` --install-extension Install or update a VS Code extension by id or vsix. The identifier of an extension is \`\${publisher}.\${name}\`.
851
+ To install a specific version provide \`@\${version}\`. For example: 'vscode.csharp@1.2.3'.` ,
852
+ ] )
853
+ } )
854
+ } )
0 commit comments