11const fs = require ( 'fs' ) ;
22const { isSelenium4 } = require ( './isSelenium4' ) ;
33
4+ /**
5+ * @readonly
6+ * @enum {number}
7+ */
48const PROCESS_TYPES = {
59 STANDALONE : 0 ,
610 GRID_HUB : 1 ,
711 GRID_NODE : 2 ,
812 DISTRIBUTOR_NODE : 3 ,
913} ;
1014
15+ /**
16+ * @param {string | undefined } role
17+ * @returns {PROCESS_TYPES }
18+ */
1119const parseRole = ( role ) => {
1220 if ( ! role || role === 'standalone' ) return PROCESS_TYPES . STANDALONE ;
1321 if ( role === 'hub' ) return PROCESS_TYPES . GRID_HUB ;
1422 if ( role === 'node' ) return PROCESS_TYPES . GRID_NODE ;
1523 if ( role === 'distributor' ) return PROCESS_TYPES . DISTRIBUTOR_NODE ;
1624} ;
1725
26+ /**
27+ * @param {PROCESS_TYPES } processType
28+ */
1829const getDefaultPort = ( processType ) => {
1930 switch ( processType ) {
2031 case PROCESS_TYPES . STANDALONE :
@@ -25,6 +36,10 @@ const getDefaultPort = (processType) => {
2536 }
2637} ;
2738
39+ /**
40+ * @param {string[] } seleniumArgs
41+ * @returns {PROCESS_TYPES }
42+ */
2843const getRunningProcessType = ( seleniumArgs ) => {
2944 const roleArg = Math . max (
3045 seleniumArgs . indexOf ( 'hub' ) ,
@@ -38,20 +53,20 @@ const getRunningProcessType = (seleniumArgs) => {
3853} ;
3954
4055/**
41- * @param {string[] } seleniumArgs
42- * @param {object } opts
56+ * @param {string[] } seleniumArgs - Command line arguments
57+ * @param {{ version?: string } } opts
4358 * @returns {URL }
59+ *
60+ * @throws {Error } The args use the `distributor` process type.
4461 */
4562const getSeleniumStatusUrl = ( seleniumArgs , opts ) => {
4663 const nodeConfigArg = seleniumArgs . indexOf ( '-nodeConfig' ) ;
4764
48- // args prefix differs for selenium3 and selenium4
65+ // The CLI args prefix is "-" for Selenium v3 and "--" for v4.
4966 let argsPrefix = '-' ;
5067 if ( isSelenium4 ( opts . version ) ) {
5168 argsPrefix = '--' ;
5269 }
53- const portArg = seleniumArgs . indexOf ( `${ argsPrefix } port` ) ;
54- const hostArg = seleniumArgs . indexOf ( `${ argsPrefix } host` ) ;
5570
5671 let host = 'localhost' ;
5772 let port ;
@@ -77,10 +92,13 @@ const getSeleniumStatusUrl = (seleniumArgs, opts) => {
7792 }
7893 }
7994
80- // Overrode port and host if they were specified
95+ // Override the port and host if they were specified
96+ const portArg = seleniumArgs . indexOf ( `${ argsPrefix } port` ) ;
8197 if ( portArg !== - 1 ) {
8298 port = seleniumArgs [ portArg + 1 ] ;
8399 }
100+
101+ const hostArg = seleniumArgs . indexOf ( `${ argsPrefix } host` ) ;
84102 if ( hostArg !== - 1 ) {
85103 host = seleniumArgs [ hostArg + 1 ] ;
86104 }
0 commit comments