UNPKG

@salesforce/salesforcedx-vscode-test-tools

Version:
128 lines 7.35 kB
"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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateSpacer = exports.validateCommand = exports.runAndValidateCommand = void 0; const assert_1 = require("assert"); const console_1 = require("console"); const ui_interaction_1 = require("../ui-interaction"); const miscellaneous_1 = require("../core/miscellaneous"); const retryUtils_1 = require("../retryUtils"); /** * Runs a Salesforce deployment or retrieval command and validates the results * @param operation - The operation to perform (Deploy/Retrieve) * @param fromTo - The direction of the operation (To/From) * @param operationType - Text to identify operation type (source tracking enabled/disabled, deploy on save) * @param metadataType - The type of metadata being operated on * @param fullName - The full name of the metadata item * @param prefix - Optional prefix to check for in the output */ const runAndValidateCommand = async (operation, fromTo, operationType, metadataType, fullName, prefix) => { (0, console_1.log)(`runAndValidateCommand()`); await (0, ui_interaction_1.executeQuickPick)('View: Focus Active Editor Group', miscellaneous_1.Duration.seconds(1)); await (0, ui_interaction_1.executeQuickPick)(`SFDX: ${operation} This Source ${fromTo} Org`, miscellaneous_1.Duration.seconds(5)); await (0, exports.validateCommand)(operation, fromTo, operationType, metadataType, [fullName], prefix); }; exports.runAndValidateCommand = runAndValidateCommand; const validateCommand = async (operation, fromTo, operationType, // Text to identify operation operationType (if it has source tracking enabled, disabled or if it was a deploy on save), metadataType, fullNames, prefix = '') => { (0, console_1.log)(`validateCommand()`); await (0, retryUtils_1.verifyNotificationWithRetry)(new RegExp(`SFDX: ${operation} This Source ${fromTo} Org successfully ran`), miscellaneous_1.Duration.minutes(10)); // Verify Output tab const outputPanelText = await (0, ui_interaction_1.attemptToFindOutputPanelText)('Salesforce CLI', `Starting SFDX: ${operation} This Source ${fromTo}`, 10); if (!outputPanelText) { (0, assert_1.fail)('No output panel text found'); } (0, console_1.log)(`${operation} time ${operationType}: ` + (await (0, ui_interaction_1.getOperationTime)(outputPanelText))); const pathSeparator = process.platform === 'win32' ? '\\' : '/'; const longestFullName = fullNames.reduce((a, b) => (a.length > b.length ? a : b), ''); const expectedTexts = constructExpectedTexts(operation, fromTo, metadataType, fullNames, prefix, longestFullName, pathSeparator); if (!outputPanelText) { (0, assert_1.fail)('No output panel text found'); } await (0, ui_interaction_1.verifyOutputPanelText)(outputPanelText, expectedTexts); }; exports.validateCommand = validateCommand; /** * Determines the number of spaces needed to align the output text * @param longestFullName - The longest full name in the list of full names * @param currentFileName - The full name of the current file that is used to calculate the size of the spacer * @returns - A string of spaces to align the output text */ const calculateSpacer = (longestFullName, currentFileName) => { let numberOfSpaces = 2; if (longestFullName.length < 'FULL_NAME'.length) { numberOfSpaces += 'FULL_NAME'.length - currentFileName.length; } else { numberOfSpaces += longestFullName.length - currentFileName.length; } return ' '.repeat(numberOfSpaces); }; exports.calculateSpacer = calculateSpacer; /** * Constructs the expected texts for validation based on metadata type and file paths. * @param operation - The operation being performed (e.g., Deploy, Retrieve). * @param fromTo - The direction of the operation (e.g., To, From). * @param metadataType - The type of metadata being processed. * @param fullNames - The list of metadata full names. * @param prefix - Optional prefix to check for in the Output Tab. * @param longestFullName - The longest full name in the list of full names. * @param pathSeparator - The platform-specific path separator. * @returns - An array of expected texts for validation. */ const constructExpectedTexts = (operation, fromTo, metadataType, fullNames, prefix, longestFullName, pathSeparator) => { const expectedTexts = [ `${operation}ed Source`.replace('Retrieveed', 'Retrieved'), `Ended SFDX: ${operation} This Source ${fromTo} Org` ]; const metadataPaths = { ApexClass: `force-app${pathSeparator}main${pathSeparator}default${pathSeparator}classes`, ExternalServiceRegistration: `force-app${pathSeparator}main${pathSeparator}default${pathSeparator}externalServiceRegistrations`, CustomObject: `force-app${pathSeparator}main${pathSeparator}default${pathSeparator}objects`, CustomField: `force-app${pathSeparator}main${pathSeparator}default${pathSeparator}objects` }; if (!metadataPaths[metadataType]) { return expectedTexts; } const metadataPath = metadataPaths[metadataType]; const additionalTexts = fullNames.flatMap(fullName => { const spacer = (0, exports.calculateSpacer)(longestFullName, fullName); if (metadataType === 'CustomObject') { return [ `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${fullName}${pathSeparator}${fullName}.object-meta.xml` ]; } else if (metadataType === 'ExternalServiceRegistration') { return [ `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${fullName}.externalServiceRegistration-meta.xml` ]; } else if (metadataType === 'ApexClass') { return [ `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${fullName}.cls`, `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${fullName}.cls-meta.xml` ]; } else if (metadataType === 'CustomField') { const [objectName, fieldName] = fullName.split('.'); const customObjectSpacer = (0, exports.calculateSpacer)(fullName, objectName); if (operation === 'Retrieve') { return [ `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${objectName}${pathSeparator}fields${pathSeparator}${fieldName}.field-meta.xml`, `${prefix}${objectName}${customObjectSpacer}CustomObject ${metadataPath}${pathSeparator}${objectName}${pathSeparator}${objectName}.object-meta.xml` ]; } else { return `${prefix}${fullName}${spacer}${metadataType} ${metadataPath}${pathSeparator}${objectName}${pathSeparator}fields${pathSeparator}${fieldName}.field-meta.xml`; } } }); additionalTexts.filter((text) => text !== undefined).forEach(text => expectedTexts.push(text)); return expectedTexts; }; //# sourceMappingURL=deployAndRetrieve.js.map