From 4547f287dcfb012f1509b596b434a11fef457dbb Mon Sep 17 00:00:00 2001 From: Keaton Sentak <54916859+ksentak@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:24:33 -0500 Subject: [PATCH] Dynamic Imports of SDK Modules (#260) * Save approach 1 while working on approach 2 * Almost have module loader working * Dynamic load for all except discovery * Complete dynamic imports of sdk modules * code clean up * update jsdoc * update discoveryContext dynamically * create generateDefaultSdkConstants * Organize class logic * remove logs and refine logic * test versions < 0.11 * fix for versions less than 0.11 * fix pascalcase issue * fix unit tests * Add constants * update year on cp * Update to refresh old test * fix unit tests --- package.json | 1 - src/FireboltExampleInvoker.js | 96 +++------- src/FireboltTransportInvoker.js | 1 + src/constant.js | 57 +++--- src/utils/FireboltSdkManager.js | 294 +++++++++++++++++++++++++++++++ test/jest.config.js | 8 +- test/jest.setup.js | 167 ++++++++++++++++++ test/unit/MethodFilters.test.js | 11 -- test/unit/RunTestHandler.test.js | 2 +- webpack.dev.js | 3 + webpack.prod.js | 3 + 11 files changed, 530 insertions(+), 113 deletions(-) create mode 100644 src/utils/FireboltSdkManager.js create mode 100644 test/jest.setup.js diff --git a/package.json b/package.json index e07fc766..73553a32 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "build-dev": "webpack --config webpack.dev.js", "test": "jest --config test/jest.config.js", "testCoverage": "NODE_ENV=test jest --config test/jest.config.js", - "postinstall": "npm update @firebolt-js/manage-sdk", "format": "prettier --write \"**/*.js\"", "lint": "eslint ." }, diff --git a/src/FireboltExampleInvoker.js b/src/FireboltExampleInvoker.js index 4f7ce0e3..2ccfdd31 100644 --- a/src/FireboltExampleInvoker.js +++ b/src/FireboltExampleInvoker.js @@ -16,27 +16,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { Accessibility, Account, Advertising, Authentication, Capabilities, Device, Discovery, Keyboard, Lifecycle, Localization, Metrics, Profile, Parameters, SecondScreen, SecureStorage } from '@firebolt-js/sdk'; -import { - Advertising as ManageAdvertising, - AcknowledgeChallenge, - Device as ManageDevice, - Wifi, - Account as ManageAccount, - ClosedCaptions, - Keyboard as ManageKeyboard, - Localization as ManageLocalization, - PinChallenge, - Privacy, - VoiceGuidance, - UserGrants, - Metrics as ManageMetrics, - SecureStorage as ManageSecureStorage, - Discovery as ManageDiscovery, - AudioDescriptions, - HDMIInput, -} from '@firebolt-js/manage-sdk'; -import { Content } from '@firebolt-js/discovery-sdk'; +import * as CoreSDK from '@firebolt-js/sdk'; +import * as ManageSDK from '@firebolt-js/manage-sdk'; +import FireboltSdkManager from './utils/FireboltSdkManager'; import DiscoveryInvoker from './invokers/DiscoveryInvoker'; const discoveryInvoker = new DiscoveryInvoker(); const logger = require('./utils/Logger')('FireboltExampleInvoker.js'); @@ -44,6 +26,30 @@ import { removeSetInMethodName } from './utils/Utils'; import { eventEmitter } from './Toast'; import { CONSTANTS } from './constant'; +/** + * Dynamically check if the Discovery SDK is available as a dependency. + * If available, require it. Otherwise, log a warning. + */ +const dependencies = DEPENDENCIES; // Injected by Webpack DefinePlugin +let DiscoverySDK; + +if (dependencies.hasOwnProperty('@firebolt-js/discovery-sdk')) { + try { + DiscoverySDK = require('@firebolt-js/discovery-sdk'); + } catch (error) { + console.warn('DiscoverySDK is not available:', error); + } +} + +// Initialize the Firebolt SDK Module Loader +const sdkManager = new FireboltSdkManager(CoreSDK, ManageSDK, DiscoverySDK, dependencies); + +// Dynamically generate the module map based on the imported SDKs +const moduleMap = sdkManager.generateModuleMap(); + +// Export the dynamically created module map +export const MODULE_MAP = moduleMap; + // Commenting the below APIs as they have been deprecated from discovery sdk , can be uncommented when added as ripple-rpc APIs in future ticket const MAP = { 'discovery.purchasedContent': discoveryInvoker.purchasedContent.bind(discoveryInvoker), @@ -52,54 +58,6 @@ const MAP = { // 'content.entity': discoveryInvoker.getEntityInfo.bind(discoveryInvoker), }; -const CORE_MODULE_MAP = { - accessibility: Accessibility, - account: Account, - advertising: Advertising, - authentication: Authentication, - capabilities: Capabilities, - device: Device, - discovery: Discovery, - keyboard: Keyboard, - lifecycle: Lifecycle, - localization: Localization, - metrics: Metrics, - profile: Profile, - parameters: Parameters, - secondscreen: SecondScreen, - securestorage: SecureStorage, -}; - -const MANAGE_MODULE_MAP = { - advertising: ManageAdvertising, - acknowledgechallenge: AcknowledgeChallenge, - device: ManageDevice, - wifi: Wifi, - account: ManageAccount, - closedcaptions: ClosedCaptions, - keyboard: ManageKeyboard, - pinchallenge: PinChallenge, - privacy: Privacy, - voiceguidance: VoiceGuidance, - localization: ManageLocalization, - usergrants: UserGrants, - metrics: ManageMetrics, - securestorage: ManageSecureStorage, - discovery: ManageDiscovery, - audiodescriptions: AudioDescriptions, - hdmiinput: HDMIInput, -}; - -const DISCOVERY_MODULE_MAP = { - content: Content, -}; - -export const MODULE_MAP = { - core: CORE_MODULE_MAP, - manage: MANAGE_MODULE_MAP, - discovery: DISCOVERY_MODULE_MAP, -}; - // importing additional invoker which has external sdk's being exported and adding those modules in the MODULE_MAP try { const additionalInvoker = require('../plugins/FireboltExtensionInvoker').default; diff --git a/src/FireboltTransportInvoker.js b/src/FireboltTransportInvoker.js index 3001200d..1c926ce4 100644 --- a/src/FireboltTransportInvoker.js +++ b/src/FireboltTransportInvoker.js @@ -18,6 +18,7 @@ import Transport from '@firebolt-js/sdk/dist/lib/Transport'; import { CONSTANTS } from './constant'; +const logger = require('./utils/Logger')('FireboltTransportInvoker.js'); let invokeManager, invokeProvider; try { diff --git a/src/constant.js b/src/constant.js index cb048896..6293b105 100644 --- a/src/constant.js +++ b/src/constant.js @@ -17,9 +17,30 @@ */ import CONFIG_CONSTANTS from 'config'; -import CORE_OPEN_RPC from '@firebolt-js/sdk/dist/firebolt-core-open-rpc'; -import MANAGE_OPEN_RPC from '@firebolt-js/manage-sdk/dist/firebolt-manage-open-rpc'; -import DISCOVERY_OPEN_RPC from '@firebolt-js/discovery-sdk/dist/firebolt-discovery-open-rpc'; +import * as CoreSDK from '@firebolt-js/sdk'; +import * as ManageSDK from '@firebolt-js/manage-sdk'; +import FireboltSdkManager from './utils/FireboltSdkManager'; + +/** + * Dynamically check if the Discovery SDK is available as a dependency. + * If available, require it. Otherwise, log a warning. + */ +const dependencies = DEPENDENCIES; // Injected by Webpack DefinePlugin +let DiscoverySDK; + +if (dependencies.hasOwnProperty('@firebolt-js/discovery-sdk')) { + try { + DiscoverySDK = require('@firebolt-js/discovery-sdk'); + } catch (error) { + console.warn('DiscoverySDK is not available:', error); + } +} + +// Initialize the Firebolt SDK Module Loader +const sdkManager = new FireboltSdkManager(CoreSDK, ManageSDK, DiscoverySDK, dependencies); + +const defaultSdks = sdkManager.generateDefaultSdkConstants(); + export const CONSTANTS = { ALL_SDKS: 'ALL SDKS', SDK: 'SDK', @@ -142,37 +163,13 @@ export const CONSTANTS = { EXCLUDED_METHODS_FOR_SDK: [], EXCLUDED_METHODS_FOR_TRANSPORT: [], REGISTERPROVIDER: 'registerprovider', + defaultSDKs: defaultSdks, INVOKEPROVIDER: 'invokeProvider', INVOKEMANAGER: 'invokeManager', - defaultSDKs: [ - { - name: 'Core', - openRpc: CORE_OPEN_RPC, - validation: function () { - return !(process.env.MF_VALUE && !process.env.MOCKOS); - }, - unavailableMessage: 'MockOs is not running', - }, - { - name: 'Manage', - openRpc: MANAGE_OPEN_RPC, - validation: function () { - return !(process.env.MF_VALUE && !process.env.MOCKOS); - }, - unavailableMessage: 'MockOs is not running', - }, - { - name: 'Discovery', - openRpc: DISCOVERY_OPEN_RPC, - validation: function () { - return !(process.env.MF_VALUE && !process.env.MOCKOS); - }, - unavailableMessage: 'MockOs is not running', - }, - ], - additionalSDKs: [], EXCLUDED_METHODS_FOR_MFOS: [], + PASCAL_CASED_MODULES: ['SecondScreen', 'SecureStorage', 'ClosedCaptions', 'AcknowledgeChallenge', 'DeveloperTools', 'LifecycleManagement', 'PinChallenge', 'UserGrants', 'VoiceGuidance'], + X_MODULE_DESCRIPTIONS: 'x-module-descriptions', ...CONFIG_CONSTANTS, VERSIONS: 'Versions', NO_RESULT_OR_ERROR_MESSAGE: 'No result or error in response. eg: {jsonrpc: "2.0", id: x }', diff --git a/src/utils/FireboltSdkManager.js b/src/utils/FireboltSdkManager.js new file mode 100644 index 00000000..7b485a1b --- /dev/null +++ b/src/utils/FireboltSdkManager.js @@ -0,0 +1,294 @@ +/** + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Firebolt SDK Manager + * A utility to dynamically load, manage, and map Firebolt SDK modules + * based on installed dependencies and OpenRPC JSON definitions. + */ +import { CONSTANTS } from '../constant'; + +// Contexts for dynamically importing OpenRPC JSON files +const coreRpcContext = require.context('@firebolt-js/sdk/dist', true, /-open-rpc\.json$/); +const manageRpcContext = require.context('@firebolt-js/manage-sdk/dist', true, /firebolt-manage-open-rpc\.json$/); +let discoveryRpcContext; + +try { + discoveryRpcContext = require.context('@firebolt-js/discovery-sdk/dist', true, /firebolt-discovery-open-rpc\.json$/); +} catch (error) { + console.warn('Discovery SDK context is not available:', error); + discoveryRpcContext = null; +} + +const capitalizeFirstLetter = (string) => { + return string.charAt(0).toUpperCase() + string.slice(1); +}; + +/** + * Extracts unique module names from a list of method definitions. + * Splits method names at the '.' character, assuming the format 'Module.methodName'. + * + * @param {Array} methods - An array of method objects, each containing a `name` property. + * @returns {Array} An array of unique module names. + * + * @example + * const methods = [ + * { name: 'Content.requestUserInterest' }, + * { name: 'Discovery.someOtherMethod' }, + * { name: 'Content.onUserInterest' } + * ]; + * const uniqueModules = extractUniqueModules(methods); + * // Output: ['Content', 'Discovery'] + */ +const extractUniqueModules = (methods) => { + const modulesSet = new Set(); + + methods.forEach((method) => { + const moduleName = method.name.split('.')[0]; + const capitalizedModuleName = capitalizeFirstLetter(moduleName); + modulesSet.add(capitalizedModuleName); + }); + + return Array.from(modulesSet); +}; + +// ---------------------------------------- +// 1. SDK Path Resolver +// ---------------------------------------- + +/** + * Resolves the paths to OpenRPC JSON files for Firebolt SDKs based on dependencies. + */ +class SdkPathResolver { + /** + * Generates a map of SDK paths based on installed dependencies. + * @param {Object} dependencies - An object containing installed dependencies. + * @returns {Object} A map of SDK paths. + */ + static resolvePaths(dependencies) { + const sdkPaths = {}; + for (const [dependency, version] of Object.entries(dependencies)) { + if (dependency.startsWith('@firebolt-js/')) { + const sdkType = dependency.split('/')[1].replace('-sdk', ''); + const sdkKey = sdkType === 'sdk' ? 'core' : sdkType; + + let fileName; + if (sdkKey === 'core') { + fileName = SdkPathResolver.getCoreFileName(version); + } else { + fileName = `firebolt-${sdkKey}-open-rpc.json`; + } + + sdkPaths[sdkKey] = `${dependency}/dist/${fileName}`; + } + } + return sdkPaths; + } + + /** + * Determines the file name for the core SDK based on version. + * @param {string} version - The version of the core SDK. + * @returns {string} The file name for the core SDK. + */ + static getCoreFileName(version) { + if (SdkPathResolver.isVersionLessThan(version, '0.11.0')) { + return 'firebolt-open-rpc.json'; + } + return 'firebolt-core-open-rpc.json'; + } + + /** + * Compares two semantic versions to check if the first is less than the second. + * @param {string} versionA - The version to compare. + * @param {string} versionB - The version to compare against. + * @returns {boolean} True if versionA is less than versionB, false otherwise. + */ + static isVersionLessThan(versionA, versionB) { + const parseVersion = (version) => version.split('.').map(Number); + const [majorA, minorA, patchA] = parseVersion(versionA); + const [majorB, minorB, patchB] = parseVersion(versionB); + + if (majorA !== majorB) { + return majorA < majorB; + } + if (minorA !== minorB) { + return minorA < minorB; + } + return patchA < patchB; + } +} + +// ---------------------------------------- +// 2. SDK JSON Loader +// ---------------------------------------- + +/** + * Dynamically loads SDK JSON definitions from OpenRPC files. + */ +class SdkJsonLoader { + /** + * Initializes the loader with context for each SDK type. + * @param {Object} sdkContexts - Contexts for dynamically loading OpenRPC JSON files. + */ + constructor(sdkContexts) { + this.sdkContexts = sdkContexts; + } + + /** + * Loads the JSON definitions for SDKs. + * @param {Object} sdkPaths - A map of SDK paths. + * @returns {Object} A map of loaded JSON definitions. + */ + loadJson(sdkPaths) { + const sdkJson = {}; + for (const [sdkType, sdkPath] of Object.entries(sdkPaths)) { + try { + const sdkModule = this.sdkContexts[sdkType](`./${sdkPath.split('/').pop()}`); + sdkJson[sdkType] = sdkModule; + } catch (error) { + console.warn(`Failed to import module for SDK type '${sdkType}': ${error.message}`); + } + } + return sdkJson; + } +} + +// ---------------------------------------- +// 3. SDK Module Mapper +// ---------------------------------------- + +/** + * Maps SDK module names to their corresponding JSON definitions. + */ +class SdkModuleMapper { + /** + * Maps modules to SDK types. + * @param {Object} sdkJson - A map of loaded JSON definitions. + * @param {Object} sdkImports - The imported SDK modules. + * @returns {Object} A map of SDK modules categorized by type. + */ + static mapModules(sdkJson, sdkImports) { + const sdkModules = {}; + const sdkModulesMap = {}; + + // Set of PascalCase module names + const pascalCaseModules = new Set(['SecondScreen', 'SecureStorage', 'ClosedCaptions', 'AcknowledgeChallenge', 'DeveloperTools', 'LifecycleManagement', 'PinChallenge', 'UserGrants', 'VoiceGuidance']); + + for (const [sdkType, json] of Object.entries(sdkJson)) { + // Check if 'x-module-descriptions' exists and has keys, otherwise use extractUniqueModules + const moduleNames = + json.info && json.info[CONSTANTS.X_MODULE_DESCRIPTIONS] && Object.keys(json.info['x-module-descriptions']).length > 0 ? Object.keys(json.info['x-module-descriptions']) : extractUniqueModules(json.methods); + + sdkModules[sdkType] = moduleNames; + sdkModulesMap[sdkType] = moduleNames.reduce((acc, module) => { + // Find a matching PascalCase module + const matchingPascalModule = CONSTANTS.PASCAL_CASED_MODULES.find((pascalModule) => pascalModule.toLowerCase() === module.toLowerCase()); + + // Use the PascalCase module if there's a match; otherwise, use the original module + const moduleKey = matchingPascalModule || module; + + // Add to the accumulator + acc[module.toLowerCase()] = sdkImports[sdkType][moduleKey]; + return acc; + }, {}); + } + + return { sdkModules, sdkModulesMap }; + } +} + +// ---------------------------------------- +// 4. SDK Constant Generator +// ---------------------------------------- + +/** + * Generates default SDK constants based on loaded JSON definitions. + */ +class SdkConstantGenerator { + /** + * Creates default SDK constants. + * @param {Object} sdkJson - A map of loaded JSON definitions. + * @returns {Array} An array of default SDK constants. + */ + static generateConstants(sdkJson) { + // Define the desired order of SDKs + const desiredOrder = ['core', 'manage', 'discovery']; + + // Sort the keys of sdkJson based on the desired order, placing others at the end + const sortedKeys = Object.keys(sdkJson).sort((a, b) => { + const indexA = desiredOrder.indexOf(a); + const indexB = desiredOrder.indexOf(b); + if (indexA === -1) return 1; // a is not in desiredOrder, place it at the end + if (indexB === -1) return -1; // b is not in desiredOrder, place it at the end + return indexA - indexB; + }); + + // Generate the constants in the desired order + return sortedKeys.map((sdkType) => ({ + name: sdkType.charAt(0).toUpperCase() + sdkType.slice(1), // Capitalize the first letter + openRpc: sdkJson[sdkType], + validation: () => !(process.env.MF_VALUE && !process.env.MOCKOS), + unavailableMessage: 'MockOs is not running', + })); + } +} + +// ---------------------------------------- +// 5. Firebolt SDK Manager (Main Class) +// ---------------------------------------- + +/** + * Firebolt SDK Manager + * Combines utilities for dynamic module loading, mapping, and constant generation. + */ +class FireboltSdkManager { + /** + * Initializes the manager with SDK imports and dependencies. + * @param {Object} coreSdk - Core SDK object imported from '@firebolt-js/sdk'. + * @param {Object} manageSdk - Manage SDK object imported from '@firebolt-js/manage-sdk'. + * @param {Object|null} discoverySdk - Discovery SDK object, or null if not available. + * @param {Object} dependencies - An object containing installed dependencies. + */ + constructor(coreSdk, manageSdk, discoverySdk, dependencies) { + this.dependencies = dependencies; + this.sdkImports = { core: coreSdk, manage: manageSdk, discovery: discoverySdk }; + this.sdkContexts = { core: coreRpcContext, manage: manageRpcContext, discovery: discoveryRpcContext }; + } + + /** + * Generates a module map for all SDKs. + * @returns {Object} The module map. + */ + generateModuleMap() { + const sdkPaths = SdkPathResolver.resolvePaths(this.dependencies); + const sdkJson = new SdkJsonLoader(this.sdkContexts).loadJson(sdkPaths); + return SdkModuleMapper.mapModules(sdkJson, this.sdkImports).sdkModulesMap; + } + + /** + * Generates default SDK constants. + * @returns {Array} The default SDK constants. + */ + generateDefaultSdkConstants() { + const sdkPaths = SdkPathResolver.resolvePaths(this.dependencies); + const sdkJson = new SdkJsonLoader(this.sdkContexts).loadJson(sdkPaths); + return SdkConstantGenerator.generateConstants(sdkJson); + } +} + +export default FireboltSdkManager; diff --git a/test/jest.config.js b/test/jest.config.js index b6e49c41..89d1d76b 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -36,6 +36,12 @@ module.exports = { '^CensorData$': '/../src/source/censorData.json', '^RunTestHandler$': '/../src/pubsub/handlers/RunTestHandler.js', }, + transform: { + '^.+\\.[tj]s$': 'babel-jest', + '^.+\\.mjs$': 'babel-jest', + }, + transformIgnorePatterns: ['node_modules/(?!(fca-validation-modules|@firebolt-js/sdk|@firebolt-js/manage-sdk|@firebolt-js/discovery-sdk))'], + modulePathIgnorePatterns: ['/src/utils/FireboltSdkManager.js'], collectCoverage: true, coverageThreshold: { global: { @@ -46,5 +52,5 @@ module.exports = { }, }, coverageDirectory: 'coverage', - transformIgnorePatterns: ['node_modules/(?!(fca-validation-modules))'], + setupFilesAfterEnv: ['/jest.setup.js'], }; diff --git a/test/jest.setup.js b/test/jest.setup.js new file mode 100644 index 00000000..d574f34d --- /dev/null +++ b/test/jest.setup.js @@ -0,0 +1,167 @@ +// jest.setup.js + +// Mock constants module so webpack issues with FirenboltSdkManager.js are resolved +jest.mock('../src/constant', () => { + const CONSTANTS = { + ALL_SDKS: 'ALL SDKS', + SDK: 'SDK', + LIFECYLCE_VALIDTION_METHOD: 'Lifecycle.validation', + PASS: 'PASS', + FAIL: 'FAIL', + NO_LISTENER_ID: 'No listener id received', + FAILED: 'Failed', + PASSED: 'Passed', + PENDING: 'Pending', + MESSENGER: 'Messenger', + NOTPERFORMED: 'Invalid mode passed to test runner. Pass valid modes.', + NO_ERROR_FOUND: 'No error found', + EXIT_MODAL_TITLE: 'Do you want to Exit ?', + INTENT_RECEIVED: 'Intent received: ', + INTENT_ERR: 'Task failed: Intent error', + TASK_COMPL: 'Task completed: ', + COMPL_COLOR: 0xff008c00, + ERR_COLOR: 0xffff0000, + NOTIFICATION_DURATION: 5000, + TOAST_STATE: 'ToastState', + TOAST_STATE_COMPL: 'ToastStateCompl', + TOAST_REF: 'Toast', + TOAST_REF_COMPL: 'ToastCompl', + YES: 'Yes', + NO: 'No', + APP_NAVIGATION_UI: 'UI', + APP_NAVIGATION_MESSENGER: 'MESSENGER', + SCROLL_MENU_MESSAGE: "Scroll down through the menu's to view the result", + LIFECYCLE_METHOD_LIST: [ + 'Lifecycle.ready', + 'Lifecycle.state', + 'Lifecycle.close', + 'Lifecycle.finished', + 'Lifecycle.history', + 'Lifecycle.onInactive', + 'Lifecycle.onForeground', + 'Lifecycle.onBackground', + 'Lifecycle.finished', + 'Lifecycle.schema', + 'Lifecycle.background', + 'Lifecycle.suspend', + 'Lifecycle.unsuspend', + ], + CONTENT_ERROR: 'Content Error', + RDK_SERVICES: 'org.rdk.', + API_TITLE: 'API TITLE: ', + API_RESPONSE: 'Response: ', + INVOKE_TEST_MESSAGE: '**** Click Invoke to run tests ****', + VALIDATION_MESSAGE: '***** Validation Started ******', + VALIDATION_SCROLLMESSAGE: "Scroll down through the menu's to view the result", + SCHEMA_VALIDATION_STATUSMESSAGE: 'Schema Validation: ', + CONTENT_VALIDATION_STATUSMESSAGE: 'Content Validation: ', + VALIDATION: 'Validation: ', + SCHEMA_CONTENT_SKIPPED: 'Skipped', + ERROR_MESSAGE: 'Error Message: ', + UNDEFINED_RESPONSE_MESSAGE: 'Received response as undefined', + TOKEN_UNAVAILABLE: 'Token is empty, provide a valid token', + LENGTHY_DATA_WARNING: 'WARNING: Data too long for container. \nRefer mochawesome report for complete response.', + REPORT_QUEUE_SIZE: 10, + DEFAULT: 'default', + NO_PLATFORM: 'NO_PLATFORM', + PLATFORM_ERROR_MESSAGE: 'Unsupported target used.', + PLATFORM_TARGET: 'Please use any of the supported targets-[XCLASS, etc].', + FIREBOLT_COMMAND: 'fireboltCommand', + FIREBOLT_METHOD: 'fireboltMethod', + FIREBOLT_PARAMS: 'fireboltParams', + RESPONSE_TOPIC: 'responseTopic', + PARAMS: 'params', + HEALTH_CHECK: 'healthCheck', + ERROR_LIST: ['Method not found', 'Method Not Implemented'], + TRANSPORT: 'Transport', + STATUS_CODE: [0, 1, 2, 3], + SCHEMA_VALIDATION_STATUS_CODE: ['PASS', 'FAIL', 'SKIPPED', 'PENDING'], + SET: 'Set', + CALL_METHOD: 'callMethod', + TOKEN_EXPIRE_TIME: 84000, + ACCOUNT_SESSION: 'Account.session', + AUTHENTICATION_TOKEN: 'Authentication.token', + AUTHENTICATION_ROOT: 'Authentication.root', + DEVICE: 'device', + PLATFORM: 'platform', + NOT_PROVISIONED_ERROR: 'Custom error: Failed to fetch token from distribution platform', + SKIPPED_MESSAGE: 'Method Skipped by Certification Suite', + EXCEPTION_METHODS: [], + CORE: 'CORE', + MANAGE: 'MANAGE', + DISCOVERY: 'DISCOVERY', + FIREBOLT_ALL: 'FIREBOLT-ALL', + ERROR_MESSAGE_WRONG_METHOD_NAME: { code: -32601, message: 'Wrong Method Name' }, + INVALID_REQUEST_TYPE: 'Error: Invalid requestType', + LOGGER_LEVEL: 'debug', + EXCLUDED_VALUES: [null, undefined], + FIREBOLT_CONST: 'firebolt', + CERTIFICATION: false, + METHODS_T0_IGNORE_WHICH_HAS_SET: ['privacy.settings', 'securestorage.setForApp'], + ERROR_MESSAGEREGEX: new RegExp('((-)[0-9]{5}): ([A-Za-z ]*)'), + LOCK_TIME: 20000, + MAX_FAILURES: 3, + PINS: { purchase: '1111' }, + MOCKOS_PORT: 'ws://localhost:9998', + MOCKOS_UNAVAILABLE: 'MockOs is not running', + PLATFORM_MOCKOS: 'mock-firebolt-os', + DISABLE_VOICE_ANNOUNCEMENT: false, + ENABLE_VOICE_ANNOUNCEMENT: true, + TARGET_TO_BE_EXCLUDED: ['SOMETARGET'], + METHODS_TO_BE_EXCLUDED: [], + METHODS_TO_BE_EXCLUDED_ONLY_DEVICES: ['mockmodule.mockmethod'], + PUBSUB_ACK: { pubSubStatus: 'Connection successful' }, + SUBSCRIBE: 'Subscribe', + ADDITIONAL_SUBSCRIBE: 'Subscribing additional method', + PROVIDER_REGISTRATION: 'provider registered successfully', + PROVIDER_REGISTRATION_FAILED: 'Provider registeration failed', + NO_PROVIDER_SPECIFIED: 'No provider has been specified', + LIFECYCLE_RECORDING_STARTED: 'Lifecycle History Recording has been started for ', + APPID_DOESNOT_MATCH: ' passed does not match launched app ', + INVALID_LIFECYCLE_RECORD: 'Invalid lifecycle record request', + WRONG_ERROR_MESSAGE_FORMAT: 'Expected error response. Actual result does not conform to the standard error format', + WRONG_RESPONSE_MESSAGE_FORMAT: 'Unexpected error encountered in the response', + EXCLUDED_METHODS_FOR_SDK: [], + EXCLUDED_METHODS_FOR_TRANSPORT: [], + REGISTERPROVIDER: 'registerprovider', + defaultSDKs: [ + { + name: 'Core', + openRpc: {}, + validation: function () { + return !(process.env.MF_VALUE && !process.env.MOCKOS); + }, + unavailableMessage: 'MockOs is not running', + }, + { + name: 'Manage', + openRpc: {}, + validation: function () { + return !(process.env.MF_VALUE && !process.env.MOCKOS); + }, + unavailableMessage: 'MockOs is not running', + }, + { + name: 'Discovery', + openRpc: {}, + validation: function () { + return !(process.env.MF_VALUE && !process.env.MOCKOS); + }, + unavailableMessage: 'MockOs is not running', + }, + ], + INVOKEPROVIDER: 'invokeProvider', + INVOKEMANAGER: 'invokeManager', + additionalSDKs: [], + EXCLUDED_METHODS_FOR_MFOS: [], + PASCAL_CASED_MODULES: ['SecondScreen', 'SecureStorage', 'ClosedCaptions', 'AcknowledgeChallenge', 'DeveloperTools', 'LifecycleManagement', 'PinChallenge', 'UserGrants', 'VoiceGuidance'], + X_MODULE_DESCRIPTIONS: 'x-module-descriptions', + // ...CONFIG_CONSTANTS, + VERSIONS: 'Versions', + NO_RESULT_OR_ERROR_MESSAGE: 'No result or error in response. eg: {jsonrpc: "2.0", id: x }', + SCHEMA_VALIDATION: 'Schema Validation', + PLATFORM_LIST: [], + }; + + return { CONSTANTS }; +}); diff --git a/test/unit/MethodFilters.test.js b/test/unit/MethodFilters.test.js index 0d18001d..ba53f649 100644 --- a/test/unit/MethodFilters.test.js +++ b/test/unit/MethodFilters.test.js @@ -19,17 +19,6 @@ import MethodFilters from '../../src/MethodFilters'; import { CONSTANTS } from '../../src/constant'; -jest.mock('../../src/constant', () => { - const mockConstants = jest.requireActual('../../src/constant'); - return { - CONSTANTS: { - ...mockConstants.CONSTANTS, - METHODS_TO_BE_EXCLUDED_ONLY_DEVICES: ['mockmodule.mockmethod'], - TARGET_TO_BE_EXCLUDED: ['SOMETARGET'], - }, - }; -}); - jest.mock('../../src/FireboltExampleInvoker', () => { return { get: () => { diff --git a/test/unit/RunTestHandler.test.js b/test/unit/RunTestHandler.test.js index 7d328d00..38130348 100644 --- a/test/unit/RunTestHandler.test.js +++ b/test/unit/RunTestHandler.test.js @@ -167,7 +167,7 @@ describe('RunTestHandler', () => { expect(process.env.FIREBOLT_SDK_VERSION).toBe(message.metadata.fireboltVersion); expect(process.env.TARGET_VERSION).toBe(message.metadata.targetVersion); expect(process.env.MODE).toBe(message.context.communicationMode); - expect(process.env.TARGET_PLATFORM).toBe('undefined'); + expect(process.env.TARGET_PLATFORM).toBe(undefined); }); /* test('should log error if there is an exception', () => { diff --git a/webpack.dev.js b/webpack.dev.js index 1cae4777..4a89f498 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -83,6 +83,9 @@ module.exports = { // SLOWS PERFORMANCE - DO NOT ENABLE IN PRODUCTION!! useInspector: true, }), + new webpack.DefinePlugin({ + DEPENDENCIES: JSON.stringify(require('./package.json').dependencies), + }), ], node: { fs: 'empty', diff --git a/webpack.prod.js b/webpack.prod.js index 4a58f527..d1892351 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -66,6 +66,9 @@ module.exports = { // Disabled for production useInspector: false, }), + new webpack.DefinePlugin({ + DEPENDENCIES: JSON.stringify(require('./package.json').dependencies), + }), ], node: { fs: 'empty',