@salesforce/salesforcedx-vscode-test-tools
Version:
Test automation framework for Salesforce Extensions for VS Code
229 lines • 8.22 kB
JavaScript
"use strict";
/*
* Copyright (c) 2025, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvironmentSettings = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = require("path");
const constants_1 = require("./core/constants");
/**
* Singleton class to manage environment settings for Salesforce DX VSCode automation tests
*
* @remarks
* This class loads configuration from environment variables at initialization time
*/
class EnvironmentSettings {
static _instance;
/**
* VSCode version to use in tests
* @env VSCODE_VERSION - VSCode version identifier (vscode-extension-tester standard)
* @default 'latest'
*/
_codeVersion = 'latest';
/**
* Specific test spec files to run
* @env SPEC_FILES - Test spec filename(s) to run
* @default []
*/
_specFiles = [];
/**
* Path to directory containing VSIX files to install
* @env VSIX_TO_INSTALL - Path to directory with VSIX files
* @default undefined
*/
_vsixToInstallDir;
/**
* DevHub org alias name
* @env DEV_HUB_ALIAS_NAME - Alias for the DevHub org
* @default 'vscodeOrg'
*/
_devHubAliasName = 'vscodeOrg';
/**
* DevHub username
* @env DEV_HUB_USER_NAME - Username for the DevHub org
*/
_devHubUserName;
/**
* SFDX auth URL for authentication
* @env SFDX_AUTH_URL - URL for authenticating with Salesforce DX
* @default undefined
*/
_sfdxAuthUrl = process.env.SFDX_AUTH_URL;
/**
* Path to Salesforce DX VSCode extensions
* @env EXTENSIONS_FOLDER - Path to extensions directory (vscode-extension-tester standard)
* @default '[project_root]/extensions'
*/
_extensionsFolder = (0, path_1.join)(process.cwd(), 'extensions');
/**
* Path to the workspace folder where VS Code and test artifacts are stored
* @env TEST_RESOURCES - Path to workspace directory (vscode-extension-tester standard)
* @default '[project_root]/test-resources'
*/
_testResources = (0, path_1.join)(process.cwd(), 'test-resources');
/**
* Chrome driver arguments
* @env VSCODE_EXTENSION_TESTER_CHROMEDRIVER_ARGS - Arguments for Chrome driver
* @default undefined
*/
_chromeDriverArgs;
/**
* Test execution start time
* @default current time formatted as short time string
*/
_startTime = new Date(Date.now()).toLocaleTimeString([], { timeStyle: 'short' });
/**
* Factor to slow down test execution
* @env THROTTLE_FACTOR - Number to multiply timeouts by
* @default 1
*/
_throttleFactor = 1;
/**
* Java home directory path
* @env JAVA_HOME - Path to Java installation
* @default undefined
*/
_javaHome = process.env.JAVA_HOME;
/**
* Path to an existing project to use instead of creating a new one
* @env USE_EXISTING_PROJECT_PATH - Path to existing project directory
* @default undefined
*/
_useExistingProject;
/**
* Log level for test execution
* @env E2E_LOG_LEVEL - One of the valid log levels defined in LOG_LEVELS
* @default 'info'
*/
_logLevel = 'info';
/**
* Private constructor that loads all settings from environment variables
* Follows the Singleton pattern - use getInstance() to access
*/
constructor() {
// Use vscode-extension-tester standard environment variables
this._codeVersion = process.env.VSCODE_VERSION || this._codeVersion;
this._testResources = process.env.TEST_RESOURCES || this._testResources;
this._extensionsFolder = process.env.EXTENSIONS_FOLDER || this._extensionsFolder;
this._chromeDriverArgs = process.env.VSCODE_EXTENSION_TESTER_CHROMEDRIVER_ARGS;
// VSIXs to install directory - no default value
this._vsixToInstallDir = process.env.VSIX_TO_INSTALL;
// Custom project environment variables
this._devHubAliasName = process.env.DEV_HUB_ALIAS_NAME || this._devHubAliasName;
this._devHubUserName = process.env.DEV_HUB_USER_NAME;
this._throttleFactor = parseInt(process.env.THROTTLE_FACTOR ?? '0') || this._throttleFactor;
this._sfdxAuthUrl = process.env.SFDX_AUTH_URL || this._sfdxAuthUrl;
this._logLevel = constants_1.LOG_LEVELS.some(l => l === process.env.E2E_LOG_LEVEL)
? process.env.E2E_LOG_LEVEL
: this._logLevel;
this._javaHome = process.env.JAVA_HOME || this._javaHome;
this.useExistingProject = process.env.USE_EXISTING_PROJECT_PATH;
}
/**
* Returns the singleton instance of EnvironmentSettings
* Creates the instance if it doesn't exist
*/
static getInstance() {
if (!EnvironmentSettings._instance) {
EnvironmentSettings._instance = new EnvironmentSettings();
}
return EnvironmentSettings._instance;
}
/** Gets the VSCode version to use in tests */
get vscodeVersion() {
return this._codeVersion;
}
/** @deprecated Use vscodeVersion instead */
get codeVersion() {
return this._codeVersion;
}
/** Gets the spec files to run */
get specFiles() {
return this._specFiles;
}
/** Gets the DevHub org alias name */
get devHubAliasName() {
return this._devHubAliasName;
}
/** Gets the DevHub username */
get devHubUserName() {
return this._devHubUserName;
}
/** Gets the path to Salesforce DX VSCode extensions */
get extensionPath() {
return this._extensionsFolder;
}
/** Gets the path to Salesforce DX VSCode extensions (aligned with env var name) */
get extensionsFolder() {
return this._extensionsFolder;
}
/** Gets the throttle factor for slowing down test execution */
get throttleFactor() {
return this._throttleFactor;
}
/** Gets the test execution start time */
get startTime() {
return this._startTime;
}
/** Gets the SFDX auth URL for authentication */
get sfdxAuthUrl() {
return this._sfdxAuthUrl;
}
/** Gets the Java home directory path */
get javaHome() {
return this._javaHome;
}
/** Gets the path to an existing project */
get useExistingProject() {
return this._useExistingProject;
}
/**
* Sets the path to an existing project
* @param existingProject Path to the project directory
* @throws Error if the specified path does not exist
*/
set useExistingProject(existingProject) {
const projectPath = existingProject ?? process.env.USE_EXISTING_PROJECT_PATH;
if (!projectPath) {
this._useExistingProject = undefined;
return;
}
if (!fs_1.default.existsSync(projectPath)) {
throw new Error(`Project path for "${projectPath}" does not exist`);
}
this._useExistingProject = projectPath;
}
/** Gets the workspace path where VS Code and test artifacts are stored */
get workspacePath() {
return this._testResources;
}
/** Gets the test resources path (aligned with env var name) */
get testResources() {
return this._testResources;
}
/** Gets the log level for test execution */
get logLevel() {
return this._logLevel;
}
/** Gets the Chrome driver arguments */
get chromeDriverArgs() {
return this._chromeDriverArgs;
}
/** Gets the Chrome driver arguments (more explicit naming) */
get vscodeExtensionTesterChromeDriverArgs() {
return this._chromeDriverArgs;
}
/** Gets the directory containing VSIX files to install */
get vsixToInstallDir() {
return this._vsixToInstallDir;
}
}
exports.EnvironmentSettings = EnvironmentSettings;
//# sourceMappingURL=environmentSettings.js.map