You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@salesforce/apex-node

Package Overview
Dependencies
Maintainers
47
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salesforce/apex-node - npm Package Compare versions

Comparing version

to
8.1.20-qa.0

10

lib/src/tests/asyncTests.d.ts
import { Connection } from '@salesforce/core';
import { CancellationToken, Progress } from '../common';
import { AsyncTestRun } from '../streaming';
import { ApexTestProgressValue, ApexTestQueueItem, ApexTestResult, ApexTestRunResult, AsyncTestArrayConfiguration, AsyncTestConfiguration, TestResult, TestRunIdResult } from './types';
import { ApexTestProgressValue, ApexTestQueueItem, ApexTestResult, ApexTestRunResult, AsyncTestArrayConfiguration, AsyncTestConfiguration, TestResult, TestRunIdResult, FlowTestResult } from './types';
import { Duration } from '@salesforce/kit';

@@ -44,2 +44,6 @@ export declare class AsyncTests {

getAsyncTestResults(testQueueResult: ApexTestQueueItem): Promise<ApexTestResult[]>;
/**
* @returns Convert FlowTest result to ApexTestResult type
*/
convertFlowTestResult(flowtestResults: FlowTestResult[]): ApexTestResult[];
private buildAsyncTestResults;

@@ -58,2 +62,6 @@ /**

/**
* @returns A boolean indicating if this is running FlowTest.
*/
isJobIdForFlowTestRun(testRunId: string): Promise<boolean>;
/**
* @returns A connection based on the current api version and the max api version.

@@ -60,0 +68,0 @@ */

@@ -272,10 +272,13 @@ "use strict";

try {
const apexTestResultQuery = hasIsTestSetupField
? `SELECT Id, QueueItemId, StackTrace, Message, RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, IsTestSetup, ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix FROM ApexTestResult WHERE QueueItemId IN (%s)`
: `SELECT Id, QueueItemId, StackTrace, Message, RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix FROM ApexTestResult WHERE QueueItemId IN (%s)`;
const apexResultIds = testQueueResult.records.map((record) => record.Id);
const resultIds = testQueueResult.records.map((record) => record.Id);
const isFlowRunTest = await this.isJobIdForFlowTestRun(resultIds[0]);
const apexTestResultQuery = isFlowRunTest
? `SELECT Id, ApexTestQueueItemId, Result, TestStartDateTime,TestEndDateTime, FlowTest.DeveloperName, FlowDefinition.DeveloperName, FlowDefinition.NamespacePrefix FROM FlowTestResult WHERE ApexTestQueueItemId IN (%s)`
: hasIsTestSetupField
? `SELECT Id, QueueItemId, StackTrace, Message, RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, IsTestSetup, ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix FROM ApexTestResult WHERE QueueItemId IN (%s)`
: `SELECT Id, QueueItemId, StackTrace, Message, RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix FROM ApexTestResult WHERE QueueItemId IN (%s)`;
// iterate thru ids, create query with id, & compare query length to char limit
const queries = [];
for (let i = 0; i < apexResultIds.length; i += constants_1.QUERY_RECORD_LIMIT) {
const recordSet = apexResultIds
for (let i = 0; i < resultIds.length; i += constants_1.QUERY_RECORD_LIMIT) {
const recordSet = resultIds
.slice(i, i + constants_1.QUERY_RECORD_LIMIT)

@@ -290,4 +293,7 @@ .map((id) => `'${id}'`);

});
const apexTestResults = await Promise.all(queryPromises);
return apexTestResults;
const testResults = await Promise.all(queryPromises);
if (isFlowRunTest) {
return this.convertFlowTestResult(testResults);
}
return testResults;
}

@@ -298,2 +304,35 @@ finally {

}
/**
* @returns Convert FlowTest result to ApexTestResult type
*/
convertFlowTestResult(flowtestResults) {
return flowtestResults.map((flowtestResult) => {
const tmpRecords = flowtestResult.records.map((record) => ({
Id: record.Id,
QueueItemId: record.ApexTestQueueItemId,
StackTrace: '', // Default value
Message: '', // Default value
AsyncApexJobId: record.ApexTestQueueItemId, // Assuming this maps from ApexTestQueueItem
MethodName: record.FlowTest.DeveloperName,
Outcome: record.Result,
ApexLogId: '', // Default value
IsTestSetup: false,
ApexClass: {
Id: record.ApexTestQueueItemId,
Name: record.FlowDefinition.DeveloperName,
NamespacePrefix: record.FlowDefinition.NamespacePrefix,
FullName: record.FlowDefinition.NamespacePrefix
? `${record.FlowDefinition.NamespacePrefix}.${record.FlowTest.DeveloperName}`
: record.FlowTest.DeveloperName
},
RunTime: 0, // Default value, replace with actual runtime if available
TestTimestamp: record.TestStartDateTime
}));
return {
done: flowtestResult.done,
totalSize: tmpRecords.length,
records: tmpRecords
};
});
}
async buildAsyncTestResults(apexTestResults) {

@@ -415,2 +454,23 @@ utils_1.HeapMonitor.getInstance().checkHeapSize('asyncTests.buildAsyncTestResults');

/**
* @returns A boolean indicating if this is running FlowTest.
*/
async isJobIdForFlowTestRun(testRunId) {
const apexIdQuery = `SELECT ApexClassId FROM ApexTestQueueItem WHERE Id = '${testRunId}'`;
try {
const testRunApexIdResults = await this.connection.tooling.query(apexIdQuery);
if (testRunApexIdResults.records.length > 0) {
for (const record of testRunApexIdResults.records) {
if (record.ApexClassId === null) {
return true;
}
}
return false;
}
return false;
}
catch (e) {
return false;
}
}
/**
* @returns A connection based on the current api version and the max api version.

@@ -417,0 +477,0 @@ */

2

lib/src/tests/testService.d.ts

@@ -79,3 +79,3 @@ import { Connection } from '@salesforce/core';

buildSyncPayload(testLevel: TestLevel, tests?: string, classnames?: string): Promise<SyncTestConfiguration>;
buildAsyncPayload(testLevel: TestLevel, tests?: string, classNames?: string, suiteNames?: string): Promise<AsyncTestConfiguration | AsyncTestArrayConfiguration>;
buildAsyncPayload(testLevel: TestLevel, tests?: string, classNames?: string, suiteNames?: string, category?: string): Promise<AsyncTestConfiguration | AsyncTestArrayConfiguration>;
private buildAsyncClassPayload;

@@ -82,0 +82,0 @@ private buildTestPayload;

@@ -299,3 +299,3 @@ "use strict";

}
async buildAsyncPayload(testLevel, tests, classNames, suiteNames) {
async buildAsyncPayload(testLevel, tests, classNames, suiteNames, category) {
try {

@@ -309,2 +309,9 @@ if (tests) {

else {
if (category && category.length !== 0) {
return {
suiteNames,
testLevel,
category
};
}
return {

@@ -325,5 +332,3 @@ suiteNames,

if (classParts.length > 1) {
return {
className: `${classParts[0]}.${classParts[1]}`
};
return { className: `${classParts[0]}.${classParts[1]}` };
}

@@ -330,0 +335,0 @@ const prop = (0, narrowing_1.isValidApexClassID)(item) ? 'classId' : 'className';

@@ -50,2 +50,6 @@ import { ApexDiagnostic } from '../utils';

exitOnTestRunId?: boolean;
/**
* Category for this run, for Flow or Apex
*/
category?: string;
};

@@ -86,2 +90,3 @@ export declare enum ResultFormat {

namespace?: string;
category?: string;
};

@@ -107,2 +112,3 @@ export type AsyncTestArrayConfiguration = {

skipCodeCoverage?: boolean;
category?: string;
};

@@ -171,2 +177,22 @@ export type SyncTestConfiguration = {

}
export type FlowTestResultRecord = {
Id: string;
ApexTestQueueItemId: string;
Result: ApexTestResultOutcome;
FlowTest: {
/**
* Name of the Flow Test Method (up to 255 characters)
*/
DeveloperName: string;
};
FlowDefinition: {
DeveloperName: string;
NamespacePrefix: string;
};
/**
* The start time of the test method.
*/
TestStartDateTime: string;
TestEndDateTime: string;
};
export type ApexTestResultRecord = {

@@ -235,2 +261,7 @@ Id: string;

};
export type FlowTestResult = {
done: boolean;
totalSize: number;
records: FlowTestResultRecord[];
};
export declare const enum ApexTestRunResultStatus {

@@ -237,0 +268,0 @@ Queued = "Queued",

{
"name": "@salesforce/apex-node",
"description": "Salesforce JS library for Apex",
"version": "8.1.19",
"version": "8.1.20-qa.0",
"author": "Salesforce",

@@ -9,4 +9,4 @@ "bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues",

"dependencies": {
"@jsforce/jsforce-node": "^3.6.3",
"@salesforce/core": "^8.8.0",
"@jsforce/jsforce-node": "^3.6.6",
"@salesforce/core": "^8.8.6",
"@salesforce/kit": "^3.2.3",

@@ -37,4 +37,3 @@ "@types/istanbul-reports": "^3.0.4",

"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.24.0",
"ts-morph": "^23.0.0",
"esbuild": "^0.24.2",
"eslint": "^8.57.1",

@@ -46,10 +45,11 @@ "eslint-config-prettier": "^9.0.0",

"husky": "^8.0.0",
"lint-staged": "^15.2.10",
"lint-staged": "^15.3.0",
"mocha": "^10.8.2",
"mocha-junit-reporter": "^2.2.1",
"nyc": "^15.1.0",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"shx": "^0.3.4",
"sinon": "^17.0.1",
"source-map-support": "^0.5.16",
"ts-morph": "^23.0.0",
"ts-node": "^10.9.2",

@@ -56,0 +56,0 @@ "typescript": "^5.7.2"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet