-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsForceApexTestRunner.js
43 lines (36 loc) · 1.08 KB
/
jsForceApexTestRunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const jsforce = require("jsforce");
const apexUnitTest = function() {
const conn = new jsforce.Connection({
serverUrl: "Server Url",
sessionId: "Session Id"
});
const url = conn._baseUrl() + "/tooling/runTestsSynchronous/";
function runTest(className, testMethod) {
const parameters = { tests: [{ className: className, testMethods: [testMethod] }] };
return conn.requestPost(url, parameters).then(parseResponse).catch(errorHandler);
}
function parseResponse(response) {
const result = {};
if (response.successes.length) {
result[response.successes[0].methodName] = { isSuccess: true, message: "none" };
}
if (response.failures.length) {
result[response.failures[0].methodName] = {
isSuccess: false,
message: response.failures[0].methodName +
" test failed: " +
response.failures[0].message +
" " +
response.failures[0].stackTrace
};
}
return result;
}
function errorHandler(err) {
throw err;
}
return {
runTest: runTest
};
};
module.exports = apexUnitTest;