@jayree/sfdx-plugin-org
Version:
A Salesforce CLI plugin containing commands to configure State and Country/Territory Picklists and other org settings.
90 lines • 5.25 kB
JavaScript
/*
* Copyright 2026, jayree
*
* 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.
*/
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { SfCommand, requiredOrgFlagWithDeprecations, orgApiVersionFlagWithDeprecations, convertToNewTableAPI, } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
// eslint-disable-next-line no-underscore-dangle
const __filename = fileURLToPath(import.meta.url);
// eslint-disable-next-line no-underscore-dangle
const __dirname = dirname(__filename);
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@jayree/sfdx-plugin-org', 'flowtestcoverage');
export default class FlowTestCoverage extends SfCommand {
static summary = messages.getMessage('commandDescription');
static examples = [
`$ sfdx jayree:flowtestcoverage
=== Flow Test Coverage
Coverage: 82%
...
`,
];
static flags = {
'target-org': requiredOrgFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
};
static deprecateAliases = true;
static aliases = ['jayree:flowtestcoverage'];
async run() {
const { flags } = await this.parse(FlowTestCoverage);
const org = flags['target-org'];
const conn = org.getConnection(flags['api-version']);
const query1 = await conn.tooling.query("SELECT count_distinct(DefinitionId) FROM Flow WHERE Status = 'Active' AND(ProcessType = 'AutolaunchedFlow' OR ProcessType = 'Workflow' OR ProcessType = 'CustomEvent' OR ProcessType = 'InvocableProcess')");
const numberOfActiveAutolaunchedFlowsAndProcesses = query1.records[0]['expr0'];
const query2 = await conn.tooling.query('SELECT count_distinct(FlowVersionId) FROM FlowTestCoverage');
const numberOfCoveredActiveAutolaunchedFlowsAndProcesses = query2.records[0]['expr0'];
const query3 = await conn.tooling.query("SELECT Definition.DeveloperName FROM Flow WHERE Status = 'Active' AND(ProcessType = 'AutolaunchedFlow' OR ProcessType = 'Workflow' OR ProcessType = 'CustomEvent' OR ProcessType = 'InvocableProcess') AND Id NOT IN(SELECT FlowVersionId FROM FlowTestCoverage)");
const uncovered = query3.records.map((value) => value.Definition.DeveloperName);
const query4 = await conn.tooling.query('SELECT FlowVersion.Definition.DeveloperName FROM FlowTestCoverage GROUP BY FlowVersion.Definition.DeveloperName');
const covered = query4.records.map((value) => value.DeveloperName);
this.styledHeader('Flow Test Coverage');
this.styledObject({
'number of active autolaunched flows and processes': numberOfActiveAutolaunchedFlowsAndProcesses,
'number of covered active autolaunched flows and processes': numberOfCoveredActiveAutolaunchedFlowsAndProcesses,
Coverage: `${Math.floor((numberOfCoveredActiveAutolaunchedFlowsAndProcesses / numberOfActiveAutolaunchedFlowsAndProcesses) * 100)}%'`,
});
const x = [];
const length = uncovered.length > covered.length ? uncovered.length : covered.length;
for (let i = 0; i < length; i++) {
x.push({
'all active autolaunched flows and processes that don’t have test coverage': uncovered[i],
'all flows and processes that have test coverage': covered[i],
});
}
this.table(convertToNewTableAPI(x, {
TESTCOVERAGE: {
header: 'all flows and processes that have test coverage',
get: (row) => row['all flows and processes that have test coverage'],
},
NOTESTCOVERAGE: {
header: 'all active autolaunched flows and processes that don’t have test coverage',
get: (row) => row['all active autolaunched flows and processes that don’t have test coverage'],
},
}));
if (covered.length !== numberOfCoveredActiveAutolaunchedFlowsAndProcesses) {
this.warn('Error in the FlowTestCoverage table found, please delete all records in the FlowTestCoverage table, then run all tests, and use this command to check the Flow Test Coverage again');
}
return {
orgId: org.getOrgId(),
Coverage: `${Math.floor((numberOfCoveredActiveAutolaunchedFlowsAndProcesses / numberOfActiveAutolaunchedFlowsAndProcesses) * 100)}%'`,
numberOfActiveAutolaunchedFlowsAndProcesses,
numberOfCoveredActiveAutolaunchedFlowsAndProcesses,
'all active autolaunched flows and processes that don’t have test coverage': uncovered,
'all flows and processes that have test coverage': covered,
};
}
}
//# sourceMappingURL=coverage.js.map