@salesforce/apex-node
Advanced tools
Comparing version 0.1.22 to 0.2.0
@@ -62,2 +62,7 @@ /** | ||
payloadErr: string; | ||
suitenameErr: string; | ||
missingSuiteErr: string; | ||
missingTestClassErr: string; | ||
testSuiteMsg: string; | ||
classSuiteMsg: string; | ||
}; |
@@ -69,4 +69,9 @@ "use strict"; | ||
invalidsObjectErr: `You don't have permissions to access sObject of type %s. Ask your Salesforce admin to give you permissions to access Apex code and the Streaming API. \nError: %s`, | ||
payloadErr: 'Specify a test class or test methods when running tests synchronously' | ||
payloadErr: 'Specify a test class or test methods when running tests synchronously', | ||
suitenameErr: 'Must provide a suite name or suite id to retrieve test classes in suite', | ||
missingSuiteErr: 'Suite does not exist', | ||
missingTestClassErr: 'Apex class %s does not exist in the org', | ||
testSuiteMsg: 'Apex test class %s already exists in Apex test suite %s', | ||
classSuiteMsg: `Added Apex class %s to your Apex test suite %s` | ||
}; | ||
//# sourceMappingURL=i18n.js.map |
@@ -5,3 +5,3 @@ export { CancellationToken, CancellationTokenSource, Progress } from './common'; | ||
export { JUnitReporter, TapReporter, HumanReporter } from './reporters'; | ||
export { ApexTestProgressValue, ApexTestRunResultStatus, ApexTestResultData, ApexTestResultOutcome, AsyncTestArrayConfiguration, AsyncTestConfiguration, CodeCoverageResult, OutputDirConfig, ResultFormat, SyncTestConfiguration, TestItem, TestLevel, TestResult, TestService } from './tests'; | ||
export { ApexTestProgressValue, ApexTestResultData, ApexTestResultOutcome, ApexTestRunResultStatus, AsyncTestArrayConfiguration, AsyncTestConfiguration, CodeCoverageResult, OutputDirConfig, ResultFormat, SyncTestConfiguration, TestItem, TestLevel, TestResult, TestService } from './tests'; | ||
export { Row, Table } from './utils'; |
@@ -20,4 +20,4 @@ "use strict"; | ||
var tests_1 = require("./tests"); | ||
exports.ApexTestResultOutcome = tests_1.ApexTestResultOutcome; | ||
exports.ApexTestRunResultStatus = tests_1.ApexTestRunResultStatus; | ||
exports.ApexTestResultOutcome = tests_1.ApexTestResultOutcome; | ||
exports.ResultFormat = tests_1.ResultFormat; | ||
@@ -24,0 +24,0 @@ exports.TestLevel = tests_1.TestLevel; |
import { Connection } from '@salesforce/core'; | ||
import { SyncTestConfiguration, AsyncTestConfiguration, AsyncTestArrayConfiguration, ApexTestProgressValue, TestResult, OutputDirConfig, TestLevel } from './types'; | ||
import { SyncTestConfiguration, AsyncTestConfiguration, AsyncTestArrayConfiguration, ApexTestProgressValue, TestResult, OutputDirConfig, TestLevel, TestSuiteMembershipRecord } from './types'; | ||
import { CancellationToken, Progress } from '../common'; | ||
@@ -10,2 +10,36 @@ export declare class TestService { | ||
/** | ||
* Retrieve all suites in org | ||
* @returns list of Suites in org | ||
*/ | ||
retrieveAllSuites(): Promise<{ | ||
id: string; | ||
TestSuiteName: string; | ||
}[]>; | ||
private retrieveSuiteId; | ||
/** | ||
* Retrive the ids for the given suites | ||
* @param suitenames names of suites | ||
* @returns Ids associated with each suite | ||
*/ | ||
private getOrCreateSuiteIds; | ||
/** | ||
* Retrieves the test classes in a given suite | ||
* @param suitename name of suite | ||
* @param suiteId id of suite | ||
* @returns list of test classes in the suite | ||
*/ | ||
getTestsInSuite(suitename?: string, suiteId?: string): Promise<TestSuiteMembershipRecord[]>; | ||
/** | ||
* Returns the associated Ids for each given Apex class | ||
* @param testClasses list of Apex class names | ||
* @returns the associated ids for each Apex class | ||
*/ | ||
getApexClassIds(testClasses: string[]): Promise<string[]>; | ||
/** | ||
* Builds a test suite with the given test classes. Creates the test suite if it doesn't exist already | ||
* @param suitename name of suite | ||
* @param tests tests to be added to suite | ||
*/ | ||
buildSuite(suitename: string, testClasses: string[]): Promise<void>; | ||
/** | ||
* Synchronous Test Runs | ||
@@ -12,0 +46,0 @@ * @param options Synchronous Test Runs configuration |
@@ -28,2 +28,105 @@ "use strict"; | ||
/** | ||
* Retrieve all suites in org | ||
* @returns list of Suites in org | ||
*/ | ||
retrieveAllSuites() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const testSuiteRecords = (yield this.connection.tooling.query(`SELECT id, TestSuiteName FROM ApexTestSuite`)); | ||
return testSuiteRecords.records; | ||
}); | ||
} | ||
retrieveSuiteId(suitename) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const suiteResult = (yield this.connection.tooling.query(`SELECT id FROM ApexTestSuite WHERE TestSuiteName = '${suitename}'`)); | ||
if (suiteResult.records.length === 0) { | ||
return undefined; | ||
} | ||
return suiteResult.records[0].Id; | ||
}); | ||
} | ||
/** | ||
* Retrive the ids for the given suites | ||
* @param suitenames names of suites | ||
* @returns Ids associated with each suite | ||
*/ | ||
getOrCreateSuiteIds(suitenames) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const suiteIds = suitenames.map((suite) => __awaiter(this, void 0, void 0, function* () { | ||
const suiteId = yield this.retrieveSuiteId(suite); | ||
if (suiteId === undefined) { | ||
const result = (yield this.connection.tooling.create('ApexTestSuite', { | ||
TestSuiteName: suite | ||
})); | ||
return result.id; | ||
} | ||
return suiteId; | ||
})); | ||
return yield Promise.all(suiteIds); | ||
}); | ||
} | ||
/** | ||
* Retrieves the test classes in a given suite | ||
* @param suitename name of suite | ||
* @param suiteId id of suite | ||
* @returns list of test classes in the suite | ||
*/ | ||
getTestsInSuite(suitename, suiteId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (suitename === undefined && suiteId === undefined) { | ||
throw new Error(i18n_1.nls.localize('suitenameErr')); | ||
} | ||
if (suitename) { | ||
suiteId = yield this.retrieveSuiteId(suitename); | ||
if (suiteId === undefined) { | ||
throw new Error(i18n_1.nls.localize('missingSuiteErr')); | ||
} | ||
} | ||
const classRecords = (yield this.connection.tooling.query(`SELECT ApexClassId FROM TestSuiteMembership WHERE ApexTestSuiteId = '${suiteId}'`)); | ||
return classRecords.records; | ||
}); | ||
} | ||
/** | ||
* Returns the associated Ids for each given Apex class | ||
* @param testClasses list of Apex class names | ||
* @returns the associated ids for each Apex class | ||
*/ | ||
getApexClassIds(testClasses) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const classIds = testClasses.map((testClass) => __awaiter(this, void 0, void 0, function* () { | ||
const apexClass = (yield this.connection.tooling.query(`SELECT id, name FROM ApexClass WHERE Name = '${testClass}'`)); | ||
if (apexClass.records.length === 0) { | ||
throw new Error(i18n_1.nls.localize('missingTestClassErr', testClass)); | ||
} | ||
return apexClass.records[0].Id; | ||
})); | ||
return yield Promise.all(classIds); | ||
}); | ||
} | ||
/** | ||
* Builds a test suite with the given test classes. Creates the test suite if it doesn't exist already | ||
* @param suitename name of suite | ||
* @param tests tests to be added to suite | ||
*/ | ||
buildSuite(suitename, testClasses) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const testSuiteId = (yield this.getOrCreateSuiteIds([suitename]))[0]; | ||
const classesInSuite = yield this.getTestsInSuite(undefined, testSuiteId); | ||
const testClassIds = yield this.getApexClassIds(testClasses); | ||
yield Promise.all(testClassIds.map((classId) => __awaiter(this, void 0, void 0, function* () { | ||
const existingClass = classesInSuite.filter(rec => rec.ApexClassId === classId); | ||
const testClass = testClasses[testClassIds.indexOf(classId)]; | ||
if (existingClass.length > 0) { | ||
console.log(i18n_1.nls.localize('testSuiteMsg', [testClass, suitename])); | ||
} | ||
else { | ||
yield this.connection.tooling.create('TestSuiteMembership', { | ||
ApexClassId: classId, | ||
ApexTestSuiteId: testSuiteId | ||
}); | ||
console.log(i18n_1.nls.localize('classSuiteMsg', [testClass, suitename])); | ||
} | ||
}))); | ||
}); | ||
} | ||
/** | ||
* Synchronous Test Runs | ||
@@ -30,0 +133,0 @@ * @param options Synchronous Test Runs configuration |
@@ -458,1 +458,4 @@ import { ApexDiagnostic } from '../utils/types'; | ||
}; | ||
export declare type TestSuiteMembershipRecord = { | ||
ApexClassId: string; | ||
}; |
@@ -21,2 +21,8 @@ declare enum logLevel { | ||
}; | ||
export declare type QueryResult<T = QueryRecord> = { | ||
records: T[]; | ||
}; | ||
export declare type QueryRecord = { | ||
Id: string; | ||
}; | ||
export {}; |
{ | ||
"name": "@salesforce/apex-node", | ||
"description": "Salesforce js library for Apex", | ||
"version": "0.1.22", | ||
"version": "0.2.0", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues", |
@@ -13,13 +13,4 @@ # Salesforce Apex Library | ||
<br/> | ||
## Getting Started | ||
If you're interested in contributing, see the [CONTRIBUTING](../../CONTRIBUTING.md) guide. | ||
If you're interested in building the library locally, see the [Developing](./contributing/developing.md) doc. | ||
You can find more information about commands that the library supports in the [Commands](../../contributing/commands.md) doc. | ||
<br /> | ||
### Building the Library | ||
@@ -50,2 +41,24 @@ | ||
For more information on developing and testing with this library, see the [Developing](./developing.md) doc. | ||
Using the library directly requires access to a Salesforce [Connection](https://forcedotcom.github.io/sfdx-core/classes/authinfo.html). Create an instance of the specific Apex service to get access to the required methods. For example, to get a list of logs: | ||
``` | ||
$ const authInfo = await AuthInfo.create({ username: myAdminUsername }); | ||
$ const connection = await Connection.create({ authInfo }); | ||
$ const logService = new LogService(connection); | ||
$ const logList = await logService.getLogRecords(); | ||
``` | ||
You can use the same pattern for the `Test Service` and `Execute Service` as well. | ||
### Running the Test Suite | ||
Run the test suite locally by building the project first and then running the tests. | ||
``` | ||
$ yarn build | ||
$ yarn test | ||
``` | ||
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
216852
3553
63
0