From ffcd737ee746076cb81455a6cd3ab6f04fb95c56 Mon Sep 17 00:00:00 2001 From: Archish Date: Thu, 18 May 2023 20:39:49 +0530 Subject: [PATCH 01/10] :sparkle: added timezone capability support --- bin/commands/runs.js | 3 + bin/helpers/constants.js | 2 + bin/helpers/timezone.json | 1714 ++++++++++++++++++++++++++++++++ bin/helpers/utils.js | 37 + test/unit/bin/helpers/utils.js | 101 ++ 5 files changed, 1857 insertions(+) create mode 100644 bin/helpers/timezone.json diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 7c72c703..f74a3384 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -69,6 +69,9 @@ module.exports = function run(args, rawArgs) { // set cypress geo location utils.setGeolocation(bsConfig, args); + // set timezone + utils.setTimezone(bsConfig, args); + // set spec timeout utils.setSpecTimeout(bsConfig, args); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 3657e667..ef4cb8f1 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -85,6 +85,8 @@ const userMessages = { "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", LOCAL_STOP_FAILED: "Local Binary stop failed.", + INVALID_TIMEZONE: + 'The timezone specified is invalid. Refer to our documentation page (doc link) for the supported time zones.', INVALID_LOCAL_MODE_WARNING: 'Invalid value specified for local_mode. local_mode: ("always-on" | "on-demand"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference', LOCAL_BINARY_ALREADY_RUNNING: diff --git a/bin/helpers/timezone.json b/bin/helpers/timezone.json new file mode 100644 index 00000000..572ddc44 --- /dev/null +++ b/bin/helpers/timezone.json @@ -0,0 +1,1714 @@ +{ + "Abidjan": [ + "Africa/Abidjan", + "Greenwich Standard Time" + ], + "Accra": [ + "Africa/Accra", + "Greenwich Standard Time" + ], + "Addis_Ababa": [ + "Africa/Addis_Ababa", + "E. Africa Standard Time" + ], + "Algiers": [ + "Africa/Algiers", + "W. Central Africa Standard Time" + ], + "Asmara": [ + "Africa/Asmara", + null + ], + "Bamako": [ + "Africa/Bamako", + "Greenwich Standard Time" + ], + "Bangui": [ + "Africa/Bangui", + "W. Central Africa Standard Time" + ], + "Banjul": [ + "Africa/Banjul", + "Greenwich Standard Time" + ], + "Bissau": [ + "Africa/Bissau", + "Greenwich Standard Time" + ], + "Blantyre": [ + "Africa/Blantyre", + "South Africa Standard Time" + ], + "Brazzaville": [ + "Africa/Brazzaville", + "W. Central Africa Standard Time" + ], + "Bujumbura": [ + "Africa/Bujumbura", + "South Africa Standard Time" + ], + "Cairo": [ + "Africa/Cairo", + "Egypt Standard Time" + ], + "Casablanca": [ + "Africa/Casablanca", + "Morocco Standard Time" + ], + "Ceuta": [ + "Africa/Ceuta", + "Romance Standard Time" + ], + "Conakry": [ + "Africa/Conakry", + "Greenwich Standard Time" + ], + "Dakar": [ + "Africa/Dakar", + "Greenwich Standard Time" + ], + "Dar_es_Salaam": [ + "Africa/Dar_es_Salaam", + "E. Africa Standard Time" + ], + "Djibouti": [ + "Africa/Djibouti", + "E. Africa Standard Time" + ], + "Douala": [ + "Africa/Douala", + "W. Central Africa Standard Time" + ], + "El_Aaiun": [ + "Africa/El_Aaiun", + "Morocco Standard Time" + ], + "Freetown": [ + "Africa/Freetown", + "Greenwich Standard Time" + ], + "Gaborone": [ + "Africa/Gaborone", + "South Africa Standard Time" + ], + "Harare": [ + "Africa/Harare", + "South Africa Standard Time" + ], + "Johannesburg": [ + "Africa/Johannesburg", + "South Africa Standard Time" + ], + "Juba": [ + "Africa/Juba", + "E. Africa Standard Time" + ], + "Kampala": [ + "Africa/Kampala", + "E. Africa Standard Time" + ], + "Khartoum": [ + "Africa/Khartoum", + "E. Africa Standard Time" + ], + "Kigali": [ + "Africa/Kigali", + "South Africa Standard Time" + ], + "Kinshasa": [ + "Africa/Kinshasa", + "W. Central Africa Standard Time" + ], + "Lagos": [ + "Africa/Lagos", + "W. Central Africa Standard Time" + ], + "Libreville": [ + "Africa/Libreville", + "W. Central Africa Standard Time" + ], + "Lome": [ + "Africa/Lome", + "Greenwich Standard Time" + ], + "Luanda": [ + "Africa/Luanda", + "W. Central Africa Standard Time" + ], + "Lubumbashi": [ + "Africa/Lubumbashi", + "South Africa Standard Time" + ], + "Lusaka": [ + "Africa/Lusaka", + "South Africa Standard Time" + ], + "Malabo": [ + "Africa/Malabo", + "W. Central Africa Standard Time" + ], + "Maputo": [ + "Africa/Maputo", + "South Africa Standard Time" + ], + "Maseru": [ + "Africa/Maseru", + "South Africa Standard Time" + ], + "Mbabane": [ + "Africa/Mbabane", + "South Africa Standard Time" + ], + "Mogadishu": [ + "Africa/Mogadishu", + "E. Africa Standard Time" + ], + "Monrovia": [ + "Africa/Monrovia", + "Greenwich Standard Time" + ], + "Nairobi": [ + "Africa/Nairobi", + "E. Africa Standard Time" + ], + "Ndjamena": [ + "Africa/Ndjamena", + "W. Central Africa Standard Time" + ], + "Niamey": [ + "Africa/Niamey", + "W. Central Africa Standard Time" + ], + "Nouakchott": [ + "Africa/Nouakchott", + "Greenwich Standard Time" + ], + "Ouagadougou": [ + "Africa/Ouagadougou", + "Greenwich Standard Time" + ], + "Porto-Novo": [ + "Africa/Porto-Novo", + "W. Central Africa Standard Time" + ], + "Sao_Tome": [ + "Africa/Sao_Tome", + "Greenwich Standard Time" + ], + "Tripoli": [ + "Africa/Tripoli", + "Libya Standard Time" + ], + "Tunis": [ + "Africa/Tunis", + "W. Central Africa Standard Time" + ], + "Windhoek": [ + "Africa/Windhoek", + "Namibia Standard Time" + ], + "Adak": [ + "America/Adak", + null + ], + "Anchorage": [ + "America/Anchorage", + "Alaskan Standard Time" + ], + "Anguilla": [ + "America/Anguilla", + "SA Western Standard Time" + ], + "Antigua": [ + "America/Antigua", + "SA Western Standard Time" + ], + "Araguaina": [ + "America/Araguaina", + "SA Eastern Standard Time" + ], + "Buenos_Aires": [ + "America/Argentina/Buenos_Aires", + null + ], + "Catamarca": [ + "America/Argentina/Catamarca", + null + ], + "Cordoba": [ + "America/Argentina/Cordoba", + null + ], + "Jujuy": [ + "America/Argentina/Jujuy", + null + ], + "La_Rioja": [ + "America/Argentina/La_Rioja", + "Argentina Standard Time" + ], + "Mendoza": [ + "America/Argentina/Mendoza", + null + ], + "Rio_Gallegos": [ + "America/Argentina/Rio_Gallegos", + "Argentina Standard Time" + ], + "Salta": [ + "America/Argentina/Salta", + "Argentina Standard Time" + ], + "San_Juan": [ + "America/Argentina/San_Juan", + "Argentina Standard Time" + ], + "San_Luis": [ + "America/Argentina/San_Luis", + "Argentina Standard Time" + ], + "Tucuman": [ + "America/Argentina/Tucuman", + "Argentina Standard Time" + ], + "Ushuaia": [ + "America/Argentina/Ushuaia", + "Argentina Standard Time" + ], + "Aruba": [ + "America/Aruba", + "SA Western Standard Time" + ], + "Asuncion": [ + "America/Asuncion", + "Paraguay Standard Time" + ], + "Atikokan": [ + "America/Atikokan", + null + ], + "Bahia": [ + "America/Bahia", + "Bahia Standard Time" + ], + "Bahia_Banderas": [ + "America/Bahia_Banderas", + "Central Standard Time (Mexico)" + ], + "Barbados": [ + "America/Barbados", + "SA Western Standard Time" + ], + "Belem": [ + "America/Belem", + "SA Eastern Standard Time" + ], + "Belize": [ + "America/Belize", + "Central America Standard Time" + ], + "Blanc-Sablon": [ + "America/Blanc-Sablon", + "SA Western Standard Time" + ], + "Boa_Vista": [ + "America/Boa_Vista", + "SA Western Standard Time" + ], + "Bogota": [ + "America/Bogota", + "SA Pacific Standard Time" + ], + "Boise": [ + "America/Boise", + "Mountain Standard Time" + ], + "Cambridge_Bay": [ + "America/Cambridge_Bay", + "Mountain Standard Time" + ], + "Campo_Grande": [ + "America/Campo_Grande", + "Central Brazilian Standard Time" + ], + "Cancun": [ + "America/Cancun", + "Eastern Standard Time (Mexico)" + ], + "Caracas": [ + "America/Caracas", + "Venezuela Standard Time" + ], + "Cayenne": [ + "America/Cayenne", + "SA Eastern Standard Time" + ], + "Cayman": [ + "America/Cayman", + "SA Pacific Standard Time" + ], + "Chicago": [ + "America/Chicago", + "Central Standard Time" + ], + "Chihuahua": [ + "America/Chihuahua", + "Mountain Standard Time (Mexico)" + ], + "Costa_Rica": [ + "America/Costa_Rica", + "Central America Standard Time" + ], + "Creston": [ + "America/Creston", + "US Mountain Standard Time" + ], + "Cuiaba": [ + "America/Cuiaba", + "Central Brazilian Standard Time" + ], + "Curacao": [ + "America/Curacao", + "SA Western Standard Time" + ], + "Danmarkshavn": [ + "America/Danmarkshavn", + "UTC" + ], + "Dawson": [ + "America/Dawson", + "Pacific Standard Time" + ], + "Dawson_Creek": [ + "America/Dawson_Creek", + "US Mountain Standard Time" + ], + "Denver": [ + "America/Denver", + "Mountain Standard Time" + ], + "Detroit": [ + "America/Detroit", + "Eastern Standard Time" + ], + "Dominica": [ + "America/Dominica", + "SA Western Standard Time" + ], + "Edmonton": [ + "America/Edmonton", + "Mountain Standard Time" + ], + "Eirunepe": [ + "America/Eirunepe", + "SA Pacific Standard Time" + ], + "El_Salvador": [ + "America/El_Salvador", + "Central America Standard Time" + ], + "Fortaleza": [ + "America/Fortaleza", + "SA Eastern Standard Time" + ], + "Glace_Bay": [ + "America/Glace_Bay", + "Atlantic Standard Time" + ], + "Godthab": [ + "America/Godthab", + "Greenland Standard Time" + ], + "Goose_Bay": [ + "America/Goose_Bay", + "Atlantic Standard Time" + ], + "Grand_Turk": [ + "America/Grand_Turk", + "SA Western Standard Time" + ], + "Grenada": [ + "America/Grenada", + "SA Western Standard Time" + ], + "Guadeloupe": [ + "America/Guadeloupe", + "SA Western Standard Time" + ], + "Guatemala": [ + "America/Guatemala", + "Central America Standard Time" + ], + "Guayaquil": [ + "America/Guayaquil", + "SA Pacific Standard Time" + ], + "Guyana": [ + "America/Guyana", + "SA Western Standard Time" + ], + "Halifax": [ + "America/Halifax", + "Atlantic Standard Time" + ], + "Havana": [ + "America/Havana", + "Eastern Standard Time" + ], + "Hermosillo": [ + "America/Hermosillo", + "US Mountain Standard Time" + ], + "Indianapolis": [ + "America/Indiana/Indianapolis", + null + ], + "Knox": [ + "America/Indiana/Knox", + "Central Standard Time" + ], + "Marengo": [ + "America/Indiana/Marengo", + "US Eastern Standard Time" + ], + "Petersburg": [ + "America/Indiana/Petersburg", + "Eastern Standard Time" + ], + "Tell_City": [ + "America/Indiana/Tell_City", + "Central Standard Time" + ], + "Vevay": [ + "America/Indiana/Vevay", + "US Eastern Standard Time" + ], + "Vincennes": [ + "America/Indiana/Vincennes", + "Eastern Standard Time" + ], + "Winamac": [ + "America/Indiana/Winamac", + "Eastern Standard Time" + ], + "Inuvik": [ + "America/Inuvik", + "Mountain Standard Time" + ], + "Iqaluit": [ + "America/Iqaluit", + "Eastern Standard Time" + ], + "Jamaica": [ + "America/Jamaica", + "SA Pacific Standard Time" + ], + "Juneau": [ + "America/Juneau", + "Alaskan Standard Time" + ], + "Louisville": [ + "America/Kentucky/Louisville", + null + ], + "Monticello": [ + "America/Kentucky/Monticello", + "Eastern Standard Time" + ], + "Kralendijk": [ + "America/Kralendijk", + "SA Western Standard Time" + ], + "La_Paz": [ + "America/La_Paz", + "SA Western Standard Time" + ], + "Lima": [ + "America/Lima", + "SA Pacific Standard Time" + ], + "Los_Angeles": [ + "America/Los_Angeles", + "Pacific Standard Time" + ], + "Lower_Princes": [ + "America/Lower_Princes", + "SA Western Standard Time" + ], + "Maceio": [ + "America/Maceio", + "SA Eastern Standard Time" + ], + "Managua": [ + "America/Managua", + "Central America Standard Time" + ], + "Manaus": [ + "America/Manaus", + "SA Western Standard Time" + ], + "Marigot": [ + "America/Marigot", + "SA Western Standard Time" + ], + "Martinique": [ + "America/Martinique", + "SA Western Standard Time" + ], + "Matamoros": [ + "America/Matamoros", + "Central Standard Time" + ], + "Mazatlan": [ + "America/Mazatlan", + "Mountain Standard Time (Mexico)" + ], + "Menominee": [ + "America/Menominee", + "Central Standard Time" + ], + "Merida": [ + "America/Merida", + "Central Standard Time (Mexico)" + ], + "Metlakatla": [ + "America/Metlakatla", + null + ], + "Mexico_City": [ + "America/Mexico_City", + "Central Standard Time (Mexico)" + ], + "Miquelon": [ + "America/Miquelon", + null + ], + "Moncton": [ + "America/Moncton", + "Atlantic Standard Time" + ], + "Monterrey": [ + "America/Monterrey", + "Central Standard Time (Mexico)" + ], + "Montevideo": [ + "America/Montevideo", + "Montevideo Standard Time" + ], + "Montreal": [ + "America/Montreal", + "Eastern Standard Time" + ], + "Montserrat": [ + "America/Montserrat", + "SA Western Standard Time" + ], + "Nassau": [ + "America/Nassau", + "Eastern Standard Time" + ], + "New_York": [ + "America/New_York", + "Eastern Standard Time" + ], + "Nipigon": [ + "America/Nipigon", + "Eastern Standard Time" + ], + "Nome": [ + "America/Nome", + "Alaskan Standard Time" + ], + "Noronha": [ + "America/Noronha", + "UTC-02" + ], + "Beulah": [ + "America/North_Dakota/Beulah", + "Central Standard Time" + ], + "Center": [ + "America/North_Dakota/Center", + "Central Standard Time" + ], + "New_Salem": [ + "America/North_Dakota/New_Salem", + "Central Standard Time" + ], + "Ojinaga": [ + "America/Ojinaga", + "Mountain Standard Time" + ], + "Panama": [ + "America/Panama", + "SA Pacific Standard Time" + ], + "Pangnirtung": [ + "America/Pangnirtung", + "Eastern Standard Time" + ], + "Paramaribo": [ + "America/Paramaribo", + "SA Eastern Standard Time" + ], + "Phoenix": [ + "America/Phoenix", + "US Mountain Standard Time" + ], + "Port-au-Prince": [ + "America/Port-au-Prince", + "Eastern Standard Time" + ], + "Port_of_Spain": [ + "America/Port_of_Spain", + "SA Western Standard Time" + ], + "Porto_Velho": [ + "America/Porto_Velho", + "SA Western Standard Time" + ], + "Puerto_Rico": [ + "America/Puerto_Rico", + "SA Western Standard Time" + ], + "Rainy_River": [ + "America/Rainy_River", + "Central Standard Time" + ], + "Rankin_Inlet": [ + "America/Rankin_Inlet", + "Central Standard Time" + ], + "Recife": [ + "America/Recife", + "SA Eastern Standard Time" + ], + "Regina": [ + "America/Regina", + "Canada Central Standard Time" + ], + "Resolute": [ + "America/Resolute", + "Central Standard Time" + ], + "Rio_Branco": [ + "America/Rio_Branco", + "SA Pacific Standard Time" + ], + "Santa_Isabel": [ + "America/Santa_Isabel", + "Pacific Standard Time (Mexico)" + ], + "Santarem": [ + "America/Santarem", + "SA Eastern Standard Time" + ], + "Santiago": [ + "America/Santiago", + "Pacific SA Standard Time" + ], + "Santo_Domingo": [ + "America/Santo_Domingo", + "SA Western Standard Time" + ], + "Sao_Paulo": [ + "America/Sao_Paulo", + "E. South America Standard Time" + ], + "Scoresbysund": [ + "America/Scoresbysund", + "Azores Standard Time" + ], + "Shiprock": [ + "America/Shiprock", + null + ], + "Sitka": [ + "America/Sitka", + "Alaskan Standard Time" + ], + "St_Barthelemy": [ + "America/St_Barthelemy", + "SA Western Standard Time" + ], + "St_Johns": [ + "America/St_Johns", + "Newfoundland Standard Time" + ], + "St_Kitts": [ + "America/St_Kitts", + "SA Western Standard Time" + ], + "St_Lucia": [ + "America/St_Lucia", + "SA Western Standard Time" + ], + "St_Thomas": [ + "America/St_Thomas", + "SA Western Standard Time" + ], + "St_Vincent": [ + "America/St_Vincent", + "SA Western Standard Time" + ], + "Swift_Current": [ + "America/Swift_Current", + "Canada Central Standard Time" + ], + "Tegucigalpa": [ + "America/Tegucigalpa", + "Central America Standard Time" + ], + "Thule": [ + "America/Thule", + "Atlantic Standard Time" + ], + "Thunder_Bay": [ + "America/Thunder_Bay", + "Eastern Standard Time" + ], + "Tijuana": [ + "America/Tijuana", + "Pacific Standard Time" + ], + "Toronto": [ + "America/Toronto", + "Eastern Standard Time" + ], + "Tortola": [ + "America/Tortola", + "SA Western Standard Time" + ], + "Vancouver": [ + "America/Vancouver", + "Pacific Standard Time" + ], + "Whitehorse": [ + "America/Whitehorse", + "Pacific Standard Time" + ], + "Winnipeg": [ + "America/Winnipeg", + "Central Standard Time" + ], + "Yakutat": [ + "America/Yakutat", + "Alaskan Standard Time" + ], + "Yellowknife": [ + "America/Yellowknife", + "Mountain Standard Time" + ], + "Casey": [ + "Antarctica/Casey", + "W. Australia Standard Time" + ], + "Davis": [ + "Antarctica/Davis", + "SE Asia Standard Time" + ], + "DumontDUrville": [ + "Antarctica/DumontDUrville", + "West Pacific Standard Time" + ], + "Macquarie": [ + "Antarctica/Macquarie", + "Central Pacific Standard Time" + ], + "Mawson": [ + "Antarctica/Mawson", + "West Asia Standard Time" + ], + "McMurdo": [ + "Antarctica/McMurdo", + "New Zealand Standard Time" + ], + "Palmer": [ + "Antarctica/Palmer", + "Pacific SA Standard Time" + ], + "Rothera": [ + "Antarctica/Rothera", + "SA Eastern Standard Time" + ], + "South_Pole": [ + "Antarctica/South_Pole", + null + ], + "Syowa": [ + "Antarctica/Syowa", + "E. Africa Standard Time" + ], + "Troll": [ + "Antarctica/Troll", + null + ], + "Vostok": [ + "Antarctica/Vostok", + "Central Asia Standard Time" + ], + "Longyearbyen": [ + "Arctic/Longyearbyen", + "W. Europe Standard Time" + ], + "Aden": [ + "Asia/Aden", + "Arab Standard Time" + ], + "Almaty": [ + "Asia/Almaty", + "Central Asia Standard Time" + ], + "Amman": [ + "Asia/Amman", + "Jordan Standard Time" + ], + "Anadyr": [ + "Asia/Anadyr", + "Russia Time Zone 11" + ], + "Aqtau": [ + "Asia/Aqtau", + "West Asia Standard Time" + ], + "Aqtobe": [ + "Asia/Aqtobe", + "West Asia Standard Time" + ], + "Ashgabat": [ + "Asia/Ashgabat", + "West Asia Standard Time" + ], + "Baghdad": [ + "Asia/Baghdad", + "Arabic Standard Time" + ], + "Bahrain": [ + "Asia/Bahrain", + "Arab Standard Time" + ], + "Baku": [ + "Asia/Baku", + "Azerbaijan Standard Time" + ], + "Bangkok": [ + "Asia/Bangkok", + "SE Asia Standard Time" + ], + "Beirut": [ + "Asia/Beirut", + "Middle East Standard Time" + ], + "Bishkek": [ + "Asia/Bishkek", + "Central Asia Standard Time" + ], + "Brunei": [ + "Asia/Brunei", + "Singapore Standard Time" + ], + "Chita": [ + "Asia/Chita", + "North Asia East Standard Time" + ], + "Choibalsan": [ + "Asia/Choibalsan", + "Ulaanbaatar Standard Time" + ], + "Chongqing": [ + "Asia/Chongqing", + null + ], + "Colombo": [ + "Asia/Colombo", + "Sri Lanka Standard Time" + ], + "Damascus": [ + "Asia/Damascus", + "Syria Standard Time" + ], + "Dhaka": [ + "Asia/Dhaka", + "Bangladesh Standard Time" + ], + "Dili": [ + "Asia/Dili", + "Tokyo Standard Time" + ], + "Dubai": [ + "Asia/Dubai", + "Arabian Standard Time" + ], + "Dushanbe": [ + "Asia/Dushanbe", + "West Asia Standard Time" + ], + "Gaza": [ + "Asia/Gaza", + null + ], + "Harbin": [ + "Asia/Harbin", + null + ], + "Hebron": [ + "Asia/Hebron", + null + ], + "Ho_Chi_Minh": [ + "Asia/Ho_Chi_Minh", + null + ], + "Hong_Kong": [ + "Asia/Hong_Kong", + "China Standard Time" + ], + "Hovd": [ + "Asia/Hovd", + "SE Asia Standard Time" + ], + "Irkutsk": [ + "Asia/Irkutsk", + "North Asia East Standard Time" + ], + "Jakarta": [ + "Asia/Jakarta", + "SE Asia Standard Time" + ], + "Jayapura": [ + "Asia/Jayapura", + "Tokyo Standard Time" + ], + "Jerusalem": [ + "Asia/Jerusalem", + "Israel Standard Time" + ], + "Kabul": [ + "Asia/Kabul", + "Afghanistan Standard Time" + ], + "Kamchatka": [ + "Asia/Kamchatka", + "Russia Time Zone 11" + ], + "Karachi": [ + "Asia/Karachi", + "Pakistan Standard Time" + ], + "Kashgar": [ + "Asia/Kashgar", + null + ], + "Kathmandu": [ + "Asia/Kathmandu", + null + ], + "Katmandu": [ + "Asia/Katmandu", + "Nepal Standard Time" + ], + "Khandyga": [ + "Asia/Khandyga", + "Yakutsk Standard Time" + ], + "Kolkata": [ + "Asia/Kolkata", + "India Standard Time" + ], + "Krasnoyarsk": [ + "Asia/Krasnoyarsk", + "North Asia Standard Time" + ], + "Kuala_Lumpur": [ + "Asia/Kuala_Lumpur", + "Singapore Standard Time" + ], + "Kuching": [ + "Asia/Kuching", + "Singapore Standard Time" + ], + "Kuwait": [ + "Asia/Kuwait", + "Arab Standard Time" + ], + "Macau": [ + "Asia/Macau", + "China Standard Time" + ], + "Magadan": [ + "Asia/Magadan", + "Magadan Standard Time" + ], + "Makassar": [ + "Asia/Makassar", + "Singapore Standard Time" + ], + "Manila": [ + "Asia/Manila", + "Singapore Standard Time" + ], + "Muscat": [ + "Asia/Muscat", + "Arabian Standard Time" + ], + "Nicosia": [ + "Asia/Nicosia", + "GTB Standard Time" + ], + "Novokuznetsk": [ + "Asia/Novokuznetsk", + "North Asia Standard Time" + ], + "Novosibirsk": [ + "Asia/Novosibirsk", + "N. Central Asia Standard Time" + ], + "Omsk": [ + "Asia/Omsk", + "N. Central Asia Standard Time" + ], + "Oral": [ + "Asia/Oral", + "West Asia Standard Time" + ], + "Phnom_Penh": [ + "Asia/Phnom_Penh", + "SE Asia Standard Time" + ], + "Pontianak": [ + "Asia/Pontianak", + "SE Asia Standard Time" + ], + "Pyongyang": [ + "Asia/Pyongyang", + null + ], + "Qatar": [ + "Asia/Qatar", + "Arab Standard Time" + ], + "Qyzylorda": [ + "Asia/Qyzylorda", + "Central Asia Standard Time" + ], + "Rangoon": [ + "Asia/Rangoon", + "Myanmar Standard Time" + ], + "Riyadh": [ + "Asia/Riyadh", + "Arab Standard Time" + ], + "Sakhalin": [ + "Asia/Sakhalin", + "Vladivostok Standard Time" + ], + "Samarkand": [ + "Asia/Samarkand", + "West Asia Standard Time" + ], + "Seoul": [ + "Asia/Seoul", + "Korea Standard Time" + ], + "Shanghai": [ + "Asia/Shanghai", + "China Standard Time" + ], + "Singapore": [ + "Asia/Singapore", + "Singapore Standard Time" + ], + "Srednekolymsk": [ + "Asia/Srednekolymsk", + "Russia Time Zone 10" + ], + "Taipei": [ + "Asia/Taipei", + "Taipei Standard Time" + ], + "Tashkent": [ + "Asia/Tashkent", + "West Asia Standard Time" + ], + "Tbilisi": [ + "Asia/Tbilisi", + "Georgian Standard Time" + ], + "Tehran": [ + "Asia/Tehran", + "Iran Standard Time" + ], + "Thimphu": [ + "Asia/Thimphu", + "Bangladesh Standard Time" + ], + "Tokyo": [ + "Asia/Tokyo", + "Tokyo Standard Time" + ], + "Ulaanbaatar": [ + "Asia/Ulaanbaatar", + "Ulaanbaatar Standard Time" + ], + "Urumqi": [ + "Asia/Urumqi", + "Central Asia Standard Time" + ], + "Ust-Nera": [ + "Asia/Ust-Nera", + "Vladivostok Standard Time" + ], + "Vientiane": [ + "Asia/Vientiane", + "SE Asia Standard Time" + ], + "Vladivostok": [ + "Asia/Vladivostok", + "Vladivostok Standard Time" + ], + "Yakutsk": [ + "Asia/Yakutsk", + "Yakutsk Standard Time" + ], + "Yekaterinburg": [ + "Asia/Yekaterinburg", + "Ekaterinburg Standard Time" + ], + "Yerevan": [ + "Asia/Yerevan", + "Caucasus Standard Time" + ], + "Azores": [ + "Atlantic/Azores", + "Azores Standard Time" + ], + "Bermuda": [ + "Atlantic/Bermuda", + "Atlantic Standard Time" + ], + "Canary": [ + "Atlantic/Canary", + "GMT Standard Time" + ], + "Cape_Verde": [ + "Atlantic/Cape_Verde", + "Cape Verde Standard Time" + ], + "Faroe": [ + "Atlantic/Faroe", + null + ], + "Madeira": [ + "Atlantic/Madeira", + "GMT Standard Time" + ], + "Reykjavik": [ + "Atlantic/Reykjavik", + "Greenwich Standard Time" + ], + "South_Georgia": [ + "Atlantic/South_Georgia", + "UTC-02" + ], + "St_Helena": [ + "Atlantic/St_Helena", + "Greenwich Standard Time" + ], + "Stanley": [ + "Atlantic/Stanley", + "SA Eastern Standard Time" + ], + "Adelaide": [ + "Australia/Adelaide", + "Cen. Australia Standard Time" + ], + "Brisbane": [ + "Australia/Brisbane", + "E. Australia Standard Time" + ], + "Broken_Hill": [ + "Australia/Broken_Hill", + "Cen. Australia Standard Time" + ], + "Currie": [ + "Australia/Currie", + "Tasmania Standard Time" + ], + "Darwin": [ + "Australia/Darwin", + "AUS Central Standard Time" + ], + "Eucla": [ + "Australia/Eucla", + null + ], + "Hobart": [ + "Australia/Hobart", + "Tasmania Standard Time" + ], + "Lindeman": [ + "Australia/Lindeman", + "E. Australia Standard Time" + ], + "Lord_Howe": [ + "Australia/Lord_Howe", + null + ], + "Melbourne": [ + "Australia/Melbourne", + "AUS Eastern Standard Time" + ], + "Perth": [ + "Australia/Perth", + "W. Australia Standard Time" + ], + "Sydney": [ + "Australia/Sydney", + "AUS Eastern Standard Time" + ], + "Amsterdam": [ + "Europe/Amsterdam", + "W. Europe Standard Time" + ], + "Andorra": [ + "Europe/Andorra", + "W. Europe Standard Time" + ], + "Athens": [ + "Europe/Athens", + "GTB Standard Time" + ], + "Belgrade": [ + "Europe/Belgrade", + "Central Europe Standard Time" + ], + "Berlin": [ + "Europe/Berlin", + "W. Europe Standard Time" + ], + "Bratislava": [ + "Europe/Bratislava", + "Central Europe Standard Time" + ], + "Brussels": [ + "Europe/Brussels", + "Romance Standard Time" + ], + "Bucharest": [ + "Europe/Bucharest", + "GTB Standard Time" + ], + "Budapest": [ + "Europe/Budapest", + "Central Europe Standard Time" + ], + "Busingen": [ + "Europe/Busingen", + "W. Europe Standard Time" + ], + "Chisinau": [ + "Europe/Chisinau", + "GTB Standard Time" + ], + "Copenhagen": [ + "Europe/Copenhagen", + "Romance Standard Time" + ], + "Dublin": [ + "Europe/Dublin", + "GMT Standard Time" + ], + "Gibraltar": [ + "Europe/Gibraltar", + "W. Europe Standard Time" + ], + "Guernsey": [ + "Europe/Guernsey", + "GMT Standard Time" + ], + "Helsinki": [ + "Europe/Helsinki", + "FLE Standard Time" + ], + "Isle_of_Man": [ + "Europe/Isle_of_Man", + "GMT Standard Time" + ], + "Istanbul": [ + "Europe/Istanbul", + "Turkey Standard Time" + ], + "Jersey": [ + "Europe/Jersey", + "GMT Standard Time" + ], + "Kaliningrad": [ + "Europe/Kaliningrad", + "Kaliningrad Standard Time" + ], + "Kiev": [ + "Europe/Kiev", + "FLE Standard Time" + ], + "Kyiv": [ + "Europe/Kyiv", + "FLE Standard Time" + ], + "Lisbon": [ + "Europe/Lisbon", + "GMT Standard Time" + ], + "Ljubljana": [ + "Europe/Ljubljana", + "Central Europe Standard Time" + ], + "London": [ + "Europe/London", + "GMT Standard Time" + ], + "Luxembourg": [ + "Europe/Luxembourg", + "W. Europe Standard Time" + ], + "Madrid": [ + "Europe/Madrid", + "Romance Standard Time" + ], + "Malta": [ + "Europe/Malta", + "W. Europe Standard Time" + ], + "Mariehamn": [ + "Europe/Mariehamn", + "FLE Standard Time" + ], + "Minsk": [ + "Europe/Minsk", + "Belarus Standard Time" + ], + "Monaco": [ + "Europe/Monaco", + "W. Europe Standard Time" + ], + "Moscow": [ + "Europe/Moscow", + "Russian Standard Time" + ], + "Oslo": [ + "Europe/Oslo", + "W. Europe Standard Time" + ], + "Paris": [ + "Europe/Paris", + "Romance Standard Time" + ], + "Podgorica": [ + "Europe/Podgorica", + "Central Europe Standard Time" + ], + "Prague": [ + "Europe/Prague", + "Central Europe Standard Time" + ], + "Riga": [ + "Europe/Riga", + "FLE Standard Time" + ], + "Rome": [ + "Europe/Rome", + "W. Europe Standard Time" + ], + "Samara": [ + "Europe/Samara", + "Russia Time Zone 3" + ], + "San_Marino": [ + "Europe/San_Marino", + "W. Europe Standard Time" + ], + "Sarajevo": [ + "Europe/Sarajevo", + "Central European Standard Time" + ], + "Simferopol": [ + "Europe/Simferopol", + "Russian Standard Time" + ], + "Skopje": [ + "Europe/Skopje", + "Central European Standard Time" + ], + "Sofia": [ + "Europe/Sofia", + "FLE Standard Time" + ], + "Stockholm": [ + "Europe/Stockholm", + "W. Europe Standard Time" + ], + "Tallinn": [ + "Europe/Tallinn", + "FLE Standard Time" + ], + "Tirane": [ + "Europe/Tirane", + "Central Europe Standard Time" + ], + "Uzhgorod": [ + "Europe/Uzhgorod", + "FLE Standard Time" + ], + "Vaduz": [ + "Europe/Vaduz", + "W. Europe Standard Time" + ], + "Vatican": [ + "Europe/Vatican", + "W. Europe Standard Time" + ], + "Vienna": [ + "Europe/Vienna", + "W. Europe Standard Time" + ], + "Vilnius": [ + "Europe/Vilnius", + "FLE Standard Time" + ], + "Volgograd": [ + "Europe/Volgograd", + "Russian Standard Time" + ], + "Warsaw": [ + "Europe/Warsaw", + "Central European Standard Time" + ], + "Zagreb": [ + "Europe/Zagreb", + "Central European Standard Time" + ], + "Zaporozhye": [ + "Europe/Zaporozhye", + "FLE Standard Time" + ], + "Zurich": [ + "Europe/Zurich", + "W. Europe Standard Time" + ], + "GMT": [ + "GMT", + "GMT Standard Time" + ], + "UTC": [ + "GMT", + "GMT Standard Time" + ], + "Antananarivo": [ + "Indian/Antananarivo", + "E. Africa Standard Time" + ], + "Chagos": [ + "Indian/Chagos", + "Central Asia Standard Time" + ], + "Christmas": [ + "Indian/Christmas", + "SE Asia Standard Time" + ], + "Cocos": [ + "Indian/Cocos", + "Myanmar Standard Time" + ], + "Comoro": [ + "Indian/Comoro", + "E. Africa Standard Time" + ], + "Kerguelen": [ + "Indian/Kerguelen", + "West Asia Standard Time" + ], + "Mahe": [ + "Indian/Mahe", + "Mauritius Standard Time" + ], + "Maldives": [ + "Indian/Maldives", + "West Asia Standard Time" + ], + "Mauritius": [ + "Indian/Mauritius", + "Mauritius Standard Time" + ], + "Mayotte": [ + "Indian/Mayotte", + "E. Africa Standard Time" + ], + "Reunion": [ + "Indian/Reunion", + "Mauritius Standard Time" + ], + "Apia": [ + "Pacific/Apia", + "Samoa Standard Time" + ], + "Auckland": [ + "Pacific/Auckland", + "New Zealand Standard Time" + ], + "Bougainville": [ + "Pacific/Bougainville", + "Central Pacific Standard Time" + ], + "Chatham": [ + "Pacific/Chatham", + null + ], + "Chuuk": [ + "Pacific/Chuuk", + null + ], + "Easter": [ + "Pacific/Easter", + null + ], + "Efate": [ + "Pacific/Efate", + "Central Pacific Standard Time" + ], + "Enderbury": [ + "Pacific/Enderbury", + "Tonga Standard Time" + ], + "Fakaofo": [ + "Pacific/Fakaofo", + "Tonga Standard Time" + ], + "Fiji": [ + "Pacific/Fiji", + "Fiji Standard Time" + ], + "Funafuti": [ + "Pacific/Funafuti", + "UTC+12" + ], + "Galapagos": [ + "Pacific/Galapagos", + "Central America Standard Time" + ], + "Gambier": [ + "Pacific/Gambier", + null + ], + "Guadalcanal": [ + "Pacific/Guadalcanal", + "Central Pacific Standard Time" + ], + "Guam": [ + "Pacific/Guam", + "West Pacific Standard Time" + ], + "Honolulu": [ + "Pacific/Honolulu", + "Hawaiian Standard Time" + ], + "Johnston": [ + "Pacific/Johnston", + "Hawaiian Standard Time" + ], + "Kiritimati": [ + "Pacific/Kiritimati", + "Line Islands Standard Time" + ], + "Kosrae": [ + "Pacific/Kosrae", + "Central Pacific Standard Time" + ], + "Kwajalein": [ + "Pacific/Kwajalein", + "UTC+12" + ], + "Majuro": [ + "Pacific/Majuro", + "UTC+12" + ], + "Marquesas": [ + "Pacific/Marquesas", + null + ], + "Midway": [ + "Pacific/Midway", + "UTC-11" + ], + "Nauru": [ + "Pacific/Nauru", + "UTC+12" + ], + "Niue": [ + "Pacific/Niue", + "UTC-11" + ], + "Norfolk": [ + "Pacific/Norfolk", + null + ], + "Noumea": [ + "Pacific/Noumea", + "Central Pacific Standard Time" + ], + "Pago_Pago": [ + "Pacific/Pago_Pago", + "UTC-11" + ], + "Palau": [ + "Pacific/Palau", + "Tokyo Standard Time" + ], + "Pitcairn": [ + "Pacific/Pitcairn", + null + ], + "Pohnpei": [ + "Pacific/Pohnpei", + null + ], + "Ponape": [ + "Pacific/Ponape", + "Central Pacific Standard Time" + ], + "Port_Moresby": [ + "Pacific/Port_Moresby", + "West Pacific Standard Time" + ], + "Rarotonga": [ + "Pacific/Rarotonga", + "Hawaiian Standard Time" + ], + "Saipan": [ + "Pacific/Saipan", + "West Pacific Standard Time" + ], + "Tahiti": [ + "Pacific/Tahiti", + "Hawaiian Standard Time" + ], + "Tarawa": [ + "Pacific/Tarawa", + "UTC+12" + ], + "Tongatapu": [ + "Pacific/Tongatapu", + "Tonga Standard Time" + ], + "Truk": [ + "Pacific/Truk", + "West Pacific Standard Time" + ], + "Wake": [ + "Pacific/Wake", + "UTC+12" + ], + "Wallis": [ + "Pacific/Wallis", + "UTC+12" + ] +} \ No newline at end of file diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 08f0326b..8b628cc0 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -11,6 +11,7 @@ const util = require('util'); const { promisify } = require('util'); const readdir = promisify(fs.readdir); const stat = promisify(fs.stat); +const TIMEZONE = require("../helpers/timezone.json"); const usageReporting = require("./usageReporting"), logger = require("./logger").winstonLogger, @@ -389,6 +390,42 @@ exports.setSpecTimeout = (bsConfig, args) => { logger.debug(`Setting spec timeout = ${specTimeout}`); } +exports.isTimezoneArgPassed = () => { + return this.searchForOption('--timezone'); +} + +exports.isValidTimezone = (timezone) => { + if(!this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone])) { + return true; + } + return false; +} + +exports.setTimezone = (bsConfig, args) => { + let timezone = undefined; + if(this.isTimezoneArgPassed()) { + if(!this.isUndefined(args.timezone)) { + if(this.isValidTimezone(args.timezone)){ + timezone = args.timezone; + } else { + logger.error(`Invalid timezone = ${args.timezone}`); + syncCliLogger.info(Constants.userMessages.INVALID_TIMEZONE); + process.exit(1); + } + } + } else if (!this.isUndefined(bsConfig.run_settings.timezone)) { + if(this.isValidTimezone(bsConfig.run_settings.timezone)){ + timezone = bsConfig.run_settings.timezone; + } else { + logger.error(`Invalid timezone = ${bsConfig.run_settings.timezone}`); + syncCliLogger.info(Constants.userMessages.INVALID_TIMEZONE); + process.exit(1); + } + } + bsConfig.run_settings.timezone = timezone; + logger.debug(`Setting timezone = ${timezone}`); +} + exports.setRecordFlag = (bsConfig, args) => { if(!this.isUndefined(args["record"])) { return true; diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 04c74aa9..e07b5945 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -24,6 +24,7 @@ const utils = require('../../../../bin/helpers/utils'), Contants = require('../../../../bin/helpers/constants'); const browserstack = require('browserstack-local'); const { CYPRESS_V10_AND_ABOVE_TYPE, CYPRESS_V9_AND_OLDER_TYPE } = require('../../../../bin/helpers/constants'); +const { winstonLogger, syncCliLogger } = require('../../../../bin/helpers/logger'); chai.use(chaiAsPromised); logger.transports['console.info'].silent = true; @@ -3709,6 +3710,106 @@ describe('utils', () => { }); }); + describe("setTimezone", () => { + let isTimezoneArgPassed; + let processStub; + let loggerStub; + let syncCliLoggerStub; + beforeEach(() => { + isTimezoneArgPassed = sinon.stub(utils, 'isTimezoneArgPassed'); + processStub = sinon.stub(process, 'exit'); + loggerStub = sinon.stub(winstonLogger, 'error'); + syncCliLoggerStub = sinon.stub(syncCliLogger, 'info'); + }); + + afterEach(() => { + isTimezoneArgPassed.restore(); + processStub.restore(); + loggerStub.restore(); + syncCliLoggerStub.restore(); + }); + it('sets timezone value passed in args', () => { + let bsConfig = { + run_settings: { + timezone: "London" + } + } + let args = { + timezone: "New_York" + }; + isTimezoneArgPassed.returns(true); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq("New_York"); + }); + + it('sets timezone to null if no value passed in args', () => { + let bsConfig = { + run_settings: { + timezone: "abc" + } + } + let args = {}; + isTimezoneArgPassed.returns(true); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq(undefined); + }); + + it('sets timezone to null if invalid value passed in args', () => { + let bsConfig = { + run_settings: { + timezone: "abc" + } + } + let args = { + timezone: "xyz" + }; + isTimezoneArgPassed.returns(true); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq(undefined); + sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = xyz"); + sinon.assert.calledOnce(syncCliLoggerStub); + sinon.assert.calledOnceWithExactly(processStub, 1); + }); + + it('sets timezone to null if invalid value passed in bsConfig', () => { + let bsConfig = { + run_settings: { + timezone: "abc" + } + } + let args = {}; + isTimezoneArgPassed.returns(false); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq(undefined); + sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = abc"); + sinon.assert.calledOnce(syncCliLoggerStub); + sinon.assert.calledOnceWithExactly(processStub, 1); + }); + + it('sets timezone to value in bsConfig and not in args', () => { + let bsConfig = { + run_settings: { + timezone: "London" + } + } + let args = {}; + isTimezoneArgPassed.returns(false); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq("London"); + }); + + it('sets timezone to null if no value passed in args or bsConfig', () => { + let bsConfig = { + run_settings: {} + } + let args = {}; + isTimezoneArgPassed.returns(false); + utils.setTimezone(bsConfig, args); + expect(bsConfig.run_settings.timezone).to.eq(undefined); + }); + }); + + describe('#isInteger', () => { it('returns true if positive integer', () => { expect(utils.isInteger(123)).to.eq(true); From e17014f68b1e579d3189d16c96724e889a78c9a5 Mon Sep 17 00:00:00 2001 From: Archish Date: Thu, 18 May 2023 20:43:47 +0530 Subject: [PATCH 02/10] :sparkle: added color to timezone message --- bin/helpers/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 8b628cc0..9f3dd54f 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -409,7 +409,7 @@ exports.setTimezone = (bsConfig, args) => { timezone = args.timezone; } else { logger.error(`Invalid timezone = ${args.timezone}`); - syncCliLogger.info(Constants.userMessages.INVALID_TIMEZONE); + syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); process.exit(1); } } @@ -418,7 +418,7 @@ exports.setTimezone = (bsConfig, args) => { timezone = bsConfig.run_settings.timezone; } else { logger.error(`Invalid timezone = ${bsConfig.run_settings.timezone}`); - syncCliLogger.info(Constants.userMessages.INVALID_TIMEZONE); + syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); process.exit(1); } } From 99847555ddc2318835b9ea7393c96ef383704e00 Mon Sep 17 00:00:00 2001 From: Archish Date: Thu, 18 May 2023 20:45:31 +0530 Subject: [PATCH 03/10] :sparkle: added timezone link in message --- bin/helpers/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index ef4cb8f1..4639415b 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -86,7 +86,7 @@ const userMessages = { LOCAL_START_FAILED: "Local Testing setup failed.", LOCAL_STOP_FAILED: "Local Binary stop failed.", INVALID_TIMEZONE: - 'The timezone specified is invalid. Refer to our documentation page (doc link) for the supported time zones.', + 'The timezone specified is invalid. Refer to our documentation page https://www.browserstack.com/docs/automate/cypress/configure-timezones for the supported time zones.', INVALID_LOCAL_MODE_WARNING: 'Invalid value specified for local_mode. local_mode: ("always-on" | "on-demand"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference', LOCAL_BINARY_ALREADY_RUNNING: From 0d298fa195160743e76debc3a69f7c0fa43ab5cc Mon Sep 17 00:00:00 2001 From: Archish Date: Tue, 13 Jun 2023 13:32:59 +0530 Subject: [PATCH 04/10] :art: added isNotUndefined check for timezone --- bin/helpers/utils.js | 6 ++++-- test/unit/bin/helpers/utils.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 9f3dd54f..f753919c 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -404,7 +404,7 @@ exports.isValidTimezone = (timezone) => { exports.setTimezone = (bsConfig, args) => { let timezone = undefined; if(this.isTimezoneArgPassed()) { - if(!this.isUndefined(args.timezone)) { + if(this.isNotUndefined(args.timezone)) { if(this.isValidTimezone(args.timezone)){ timezone = args.timezone; } else { @@ -413,7 +413,7 @@ exports.setTimezone = (bsConfig, args) => { process.exit(1); } } - } else if (!this.isUndefined(bsConfig.run_settings.timezone)) { + } else if (this.isNotUndefined(bsConfig.run_settings.timezone)) { if(this.isValidTimezone(bsConfig.run_settings.timezone)){ timezone = bsConfig.run_settings.timezone; } else { @@ -591,6 +591,8 @@ exports.fixCommaSeparatedString = (string) => { exports.isUndefined = value => (value === undefined || value === null); +exports.isNotUndefined = value => !this.isUndefined(value); + exports.isPositiveInteger = (str) => { if (typeof str !== 'string') { return false; diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index e07b5945..a1e0fd06 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -192,6 +192,20 @@ describe('utils', () => { }); }); + describe('isNotUndefined', () => { + it('should return false for a undefined value', () => { + expect(utils.isNotUndefined(undefined)).to.be.equal(false); + expect(utils.isNotUndefined(null)).to.be.equal(false); + }); + + it('should return true for a defined value', () => { + expect(utils.isNotUndefined(1.234)).to.be.equal(true); + expect(utils.isNotUndefined('1.234')).to.be.equal(true); + expect(utils.isNotUndefined(100)).to.be.equal(true); + expect(utils.isNotUndefined(-1)).to.be.equal(true); + }); + }); + describe('setParallels', () => { var sandbox; beforeEach(() => { From 86daff6ba40e5e142e4f7b75086074867629be48 Mon Sep 17 00:00:00 2001 From: Archish Date: Wed, 14 Jun 2023 14:54:20 +0530 Subject: [PATCH 05/10] :art: removed duplicate code --- bin/helpers/utils.js | 35 ++++++++++------------------------ test/unit/bin/helpers/utils.js | 9 --------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index f753919c..2773723e 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -390,10 +390,6 @@ exports.setSpecTimeout = (bsConfig, args) => { logger.debug(`Setting spec timeout = ${specTimeout}`); } -exports.isTimezoneArgPassed = () => { - return this.searchForOption('--timezone'); -} - exports.isValidTimezone = (timezone) => { if(!this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone])) { return true; @@ -402,28 +398,17 @@ exports.isValidTimezone = (timezone) => { } exports.setTimezone = (bsConfig, args) => { - let timezone = undefined; - if(this.isTimezoneArgPassed()) { - if(this.isNotUndefined(args.timezone)) { - if(this.isValidTimezone(args.timezone)){ - timezone = args.timezone; - } else { - logger.error(`Invalid timezone = ${args.timezone}`); - syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); - process.exit(1); - } - } - } else if (this.isNotUndefined(bsConfig.run_settings.timezone)) { - if(this.isValidTimezone(bsConfig.run_settings.timezone)){ - timezone = bsConfig.run_settings.timezone; - } else { - logger.error(`Invalid timezone = ${bsConfig.run_settings.timezone}`); - syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); - process.exit(1); - } + let timezone = args.timezone || bsConfig.run_settings.timezone; + let newTimezone; + if(this.isNotUndefined(timezone) && this.isValidTimezone(timezone)){ + newTimezone = timezone; + } else { + logger.error(`Invalid timezone = ${timezone}`); + syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); + process.exit(1); } - bsConfig.run_settings.timezone = timezone; - logger.debug(`Setting timezone = ${timezone}`); + bsConfig.run_settings.timezone = newTimezone; + logger.debug(`Setting timezone = ${newTimezone}`); } exports.setRecordFlag = (bsConfig, args) => { diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index a1e0fd06..719a286a 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -3725,19 +3725,16 @@ describe('utils', () => { }); describe("setTimezone", () => { - let isTimezoneArgPassed; let processStub; let loggerStub; let syncCliLoggerStub; beforeEach(() => { - isTimezoneArgPassed = sinon.stub(utils, 'isTimezoneArgPassed'); processStub = sinon.stub(process, 'exit'); loggerStub = sinon.stub(winstonLogger, 'error'); syncCliLoggerStub = sinon.stub(syncCliLogger, 'info'); }); afterEach(() => { - isTimezoneArgPassed.restore(); processStub.restore(); loggerStub.restore(); syncCliLoggerStub.restore(); @@ -3751,7 +3748,6 @@ describe('utils', () => { let args = { timezone: "New_York" }; - isTimezoneArgPassed.returns(true); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq("New_York"); }); @@ -3763,7 +3759,6 @@ describe('utils', () => { } } let args = {}; - isTimezoneArgPassed.returns(true); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq(undefined); }); @@ -3777,7 +3772,6 @@ describe('utils', () => { let args = { timezone: "xyz" }; - isTimezoneArgPassed.returns(true); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq(undefined); sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = xyz"); @@ -3792,7 +3786,6 @@ describe('utils', () => { } } let args = {}; - isTimezoneArgPassed.returns(false); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq(undefined); sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = abc"); @@ -3807,7 +3800,6 @@ describe('utils', () => { } } let args = {}; - isTimezoneArgPassed.returns(false); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq("London"); }); @@ -3817,7 +3809,6 @@ describe('utils', () => { run_settings: {} } let args = {}; - isTimezoneArgPassed.returns(false); utils.setTimezone(bsConfig, args); expect(bsConfig.run_settings.timezone).to.eq(undefined); }); From 0a8bc60432d6325e8e4f52084eb46508f0516de6 Mon Sep 17 00:00:00 2001 From: Archish Date: Wed, 14 Jun 2023 14:56:38 +0530 Subject: [PATCH 06/10] :art: removed duplicate code --- bin/helpers/timezone.json | 2 +- bin/helpers/utils.js | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bin/helpers/timezone.json b/bin/helpers/timezone.json index 572ddc44..c325a65c 100644 --- a/bin/helpers/timezone.json +++ b/bin/helpers/timezone.json @@ -1711,4 +1711,4 @@ "Pacific/Wallis", "UTC+12" ] -} \ No newline at end of file +} diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 2773723e..0eb08ebc 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -399,16 +399,13 @@ exports.isValidTimezone = (timezone) => { exports.setTimezone = (bsConfig, args) => { let timezone = args.timezone || bsConfig.run_settings.timezone; - let newTimezone; - if(this.isNotUndefined(timezone) && this.isValidTimezone(timezone)){ - newTimezone = timezone; - } else { + if(this.isUndefined(timezone) && !this.isValidTimezone(timezone)){ logger.error(`Invalid timezone = ${timezone}`); syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); process.exit(1); } - bsConfig.run_settings.timezone = newTimezone; - logger.debug(`Setting timezone = ${newTimezone}`); + bsConfig.run_settings.timezone = timezone; + logger.debug(`Setting timezone = ${timezone}`); } exports.setRecordFlag = (bsConfig, args) => { From 8f8d5af28121f09decd349ac1e7724071a13988c Mon Sep 17 00:00:00 2001 From: Archish Date: Wed, 14 Jun 2023 14:57:00 +0530 Subject: [PATCH 07/10] :art: removed duplicate code --- bin/helpers/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 0eb08ebc..f6b08a47 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -399,7 +399,7 @@ exports.isValidTimezone = (timezone) => { exports.setTimezone = (bsConfig, args) => { let timezone = args.timezone || bsConfig.run_settings.timezone; - if(this.isUndefined(timezone) && !this.isValidTimezone(timezone)){ + if(this.isUndefined(timezone) || !this.isValidTimezone(timezone)){ logger.error(`Invalid timezone = ${timezone}`); syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); process.exit(1); From eb0533581da09374ac1951ad983071c21481143f Mon Sep 17 00:00:00 2001 From: Archish Date: Wed, 14 Jun 2023 14:59:32 +0530 Subject: [PATCH 08/10] :art: removed duplicate code --- bin/helpers/utils.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index f6b08a47..d9eee7f6 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -390,12 +390,7 @@ exports.setSpecTimeout = (bsConfig, args) => { logger.debug(`Setting spec timeout = ${specTimeout}`); } -exports.isValidTimezone = (timezone) => { - if(!this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone])) { - return true; - } - return false; -} +exports.isValidTimezone = (timezone) => !this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone]) exports.setTimezone = (bsConfig, args) => { let timezone = args.timezone || bsConfig.run_settings.timezone; From 1847cf305b0b46cb3754d76eef52630e6f7d9616 Mon Sep 17 00:00:00 2001 From: Archish Date: Wed, 14 Jun 2023 15:05:06 +0530 Subject: [PATCH 09/10] :art: removed duplicate code --- bin/helpers/utils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index d9eee7f6..9dcf0037 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -390,17 +390,20 @@ exports.setSpecTimeout = (bsConfig, args) => { logger.debug(`Setting spec timeout = ${specTimeout}`); } -exports.isValidTimezone = (timezone) => !this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone]) +exports.isValidTimezone = (timezone) => this.isNotUndefined(timezone) && this.isNotUndefined(TIMEZONE[timezone]) exports.setTimezone = (bsConfig, args) => { let timezone = args.timezone || bsConfig.run_settings.timezone; - if(this.isUndefined(timezone) || !this.isValidTimezone(timezone)){ + let newTimezone; + if(this.isValidTimezone(timezone)){ + newTimezone = timezone; + } else { logger.error(`Invalid timezone = ${timezone}`); syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); process.exit(1); } - bsConfig.run_settings.timezone = timezone; - logger.debug(`Setting timezone = ${timezone}`); + bsConfig.run_settings.timezone = newTimezone; + logger.debug(`Setting timezone = ${newTimezone}`); } exports.setRecordFlag = (bsConfig, args) => { From 3cc787138dd666958e5ccedbe705700904e5e2fe Mon Sep 17 00:00:00 2001 From: Archish Date: Fri, 16 Jun 2023 12:13:45 +0530 Subject: [PATCH 10/10] :bug: fix when timezone caps is not passed --- bin/helpers/utils.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 9dcf0037..5a65bac2 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -395,12 +395,14 @@ exports.isValidTimezone = (timezone) => this.isNotUndefined(timezone) && this.is exports.setTimezone = (bsConfig, args) => { let timezone = args.timezone || bsConfig.run_settings.timezone; let newTimezone; - if(this.isValidTimezone(timezone)){ - newTimezone = timezone; - } else { - logger.error(`Invalid timezone = ${timezone}`); - syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); - process.exit(1); + if(this.isNotUndefined(timezone)) { + if(this.isValidTimezone(timezone)){ + newTimezone = timezone; + } else { + logger.error(`Invalid timezone = ${timezone}`); + syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE)); + process.exit(1); + } } bsConfig.run_settings.timezone = newTimezone; logger.debug(`Setting timezone = ${newTimezone}`);