@salesforce/apex-node 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/lib/src/common/cancellation.js +6 -17
  2. package/lib/src/common/cancellation.js.map +1 -1
  3. package/lib/src/execute/executeService.js +52 -69
  4. package/lib/src/execute/executeService.js.map +1 -1
  5. package/lib/src/execute/types.d.ts +3 -3
  6. package/lib/src/execute/utils.js +1 -1
  7. package/lib/src/execute/utils.js.map +1 -1
  8. package/lib/src/i18n/index.js.map +1 -1
  9. package/lib/src/i18n/localization.d.ts +1 -1
  10. package/lib/src/i18n/localization.js +1 -1
  11. package/lib/src/i18n/localization.js.map +1 -1
  12. package/lib/src/logs/logService.d.ts +1 -1
  13. package/lib/src/logs/logService.js +73 -101
  14. package/lib/src/logs/logService.js.map +1 -1
  15. package/lib/src/logs/types.d.ts +3 -3
  16. package/lib/src/reporters/coverageReporter.d.ts +1 -1
  17. package/lib/src/reporters/coverageReporter.js +9 -11
  18. package/lib/src/reporters/coverageReporter.js.map +1 -1
  19. package/lib/src/reporters/humanReporter.js +2 -2
  20. package/lib/src/reporters/humanReporter.js.map +1 -1
  21. package/lib/src/reporters/junitReporter.js +2 -2
  22. package/lib/src/reporters/junitReporter.js.map +1 -1
  23. package/lib/src/reporters/tapReporter.js +6 -6
  24. package/lib/src/reporters/tapReporter.js.map +1 -1
  25. package/lib/src/streaming/streamingClient.js +116 -137
  26. package/lib/src/streaming/streamingClient.js.map +1 -1
  27. package/lib/src/streaming/types.d.ts +4 -4
  28. package/lib/src/streaming/types.js +3 -3
  29. package/lib/src/streaming/types.js.map +1 -1
  30. package/lib/src/tests/asyncTests.js +234 -246
  31. package/lib/src/tests/asyncTests.js.map +1 -1
  32. package/lib/src/tests/codeCoverage.js +86 -100
  33. package/lib/src/tests/codeCoverage.js.map +1 -1
  34. package/lib/src/tests/diagnosticUtil.js +1 -2
  35. package/lib/src/tests/diagnosticUtil.js.map +1 -1
  36. package/lib/src/tests/syncTests.js +86 -87
  37. package/lib/src/tests/syncTests.js.map +1 -1
  38. package/lib/src/tests/testService.js +235 -273
  39. package/lib/src/tests/testService.js.map +1 -1
  40. package/lib/src/tests/types.d.ts +31 -31
  41. package/lib/src/tests/types.js +5 -5
  42. package/lib/src/tests/types.js.map +1 -1
  43. package/lib/src/tests/utils.d.ts +2 -0
  44. package/lib/src/tests/utils.js +29 -24
  45. package/lib/src/tests/utils.js.map +1 -1
  46. package/lib/src/utils/authUtil.js +4 -15
  47. package/lib/src/utils/authUtil.js.map +1 -1
  48. package/lib/src/utils/dateUtil.js.map +1 -1
  49. package/lib/src/utils/fileSystemHandler.js +8 -19
  50. package/lib/src/utils/fileSystemHandler.js.map +1 -1
  51. package/lib/src/utils/table.js +3 -3
  52. package/lib/src/utils/table.js.map +1 -1
  53. package/lib/src/utils/traceFlags.js +95 -122
  54. package/lib/src/utils/traceFlags.js.map +1 -1
  55. package/lib/src/utils/types.d.ts +9 -9
  56. package/package.json +36 -39
@@ -1,15 +1,15 @@
1
- export declare type StreamingEvent = {
1
+ export type StreamingEvent = {
2
2
  createdDate: string;
3
3
  replayId?: number;
4
4
  type: string;
5
5
  };
6
- export declare type TestResultMessage = {
6
+ export type TestResultMessage = {
7
7
  event: StreamingEvent;
8
8
  sobject: {
9
9
  Id: string;
10
10
  };
11
11
  };
12
- export declare type StreamMessage = {
12
+ export type StreamMessage = {
13
13
  channel: string;
14
14
  clientId: string;
15
15
  successful?: boolean;
@@ -26,4 +26,4 @@ export declare const enum StreamingErrors {
26
26
  ERROR_AUTH_INVALID = "401::Authentication invalid",
27
27
  ERROR_UNKNOWN_CLIENT_ID = "403::Unknown client"
28
28
  }
29
- export declare const RetreiveResultsInterval: number;
29
+ export declare const RetrieveResultsInterval: number;
@@ -6,11 +6,11 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.RetreiveResultsInterval = exports.StreamingErrors = void 0;
9
+ exports.RetrieveResultsInterval = exports.StreamingErrors = void 0;
10
10
  var StreamingErrors;
11
11
  (function (StreamingErrors) {
12
12
  StreamingErrors["ERROR_AUTH_INVALID"] = "401::Authentication invalid";
13
13
  StreamingErrors["ERROR_UNKNOWN_CLIENT_ID"] = "403::Unknown client";
14
- })(StreamingErrors = exports.StreamingErrors || (exports.StreamingErrors = {}));
15
- exports.RetreiveResultsInterval = 60 * 1000;
14
+ })(StreamingErrors || (exports.StreamingErrors = StreamingErrors = {}));
15
+ exports.RetrieveResultsInterval = 60 * 1000;
16
16
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/streaming/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA6BH,IAAkB,eAGjB;AAHD,WAAkB,eAAe;IAC/B,qEAAkD,CAAA;IAClD,kEAA+C,CAAA;AACjD,CAAC,EAHiB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAGhC;AAEY,QAAA,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/streaming/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA6BH,IAAkB,eAGjB;AAHD,WAAkB,eAAe;IAC/B,qEAAkD,CAAA;IAClD,kEAA+C,CAAA;AACjD,CAAC,EAHiB,eAAe,+BAAf,eAAe,QAGhC;AAEY,QAAA,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC"}
@@ -5,15 +5,6 @@
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
8
  Object.defineProperty(exports, "__esModule", { value: true });
18
9
  exports.AsyncTests = void 0;
19
10
  const i18n_1 = require("../i18n");
@@ -37,33 +28,31 @@ class AsyncTests {
37
28
  * @param progress progress reporter
38
29
  * @param token cancellation token
39
30
  */
40
- runTests(options, codeCoverage = false, exitOnTestRunId = false, progress, token) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- try {
43
- const sClient = new streaming_1.StreamingClient(this.connection, progress);
44
- yield sClient.init();
45
- yield sClient.handshake();
46
- token &&
47
- token.onCancellationRequested(() => __awaiter(this, void 0, void 0, function* () {
48
- const testRunId = yield sClient.subscribedTestRunIdPromise;
49
- yield this.abortTestRun(testRunId, progress);
50
- sClient.disconnect();
51
- }));
52
- const testRunId = yield this.getTestRunRequestAction(options)();
53
- if (exitOnTestRunId) {
54
- return { testRunId };
55
- }
56
- if (token && token.isCancellationRequested) {
57
- return null;
58
- }
59
- const asyncRunResult = yield sClient.subscribe(undefined, testRunId);
60
- const testRunSummary = yield this.checkRunStatus(asyncRunResult.runId);
61
- return yield this.formatAsyncResults(asyncRunResult, (0, utils_1.getCurrentTime)(), codeCoverage, testRunSummary, progress);
31
+ async runTests(options, codeCoverage = false, exitOnTestRunId = false, progress, token) {
32
+ try {
33
+ const sClient = new streaming_1.StreamingClient(this.connection, progress);
34
+ await sClient.init();
35
+ await sClient.handshake();
36
+ token &&
37
+ token.onCancellationRequested(async () => {
38
+ const testRunId = await sClient.subscribedTestRunIdPromise;
39
+ await this.abortTestRun(testRunId, progress);
40
+ sClient.disconnect();
41
+ });
42
+ const testRunId = await this.getTestRunRequestAction(options)();
43
+ if (exitOnTestRunId) {
44
+ return { testRunId };
62
45
  }
63
- catch (e) {
64
- throw (0, diagnosticUtil_1.formatTestErrors)(e);
46
+ if (token && token.isCancellationRequested) {
47
+ return null;
65
48
  }
66
- });
49
+ const asyncRunResult = await sClient.subscribe(undefined, testRunId);
50
+ const testRunSummary = await this.checkRunStatus(asyncRunResult.runId);
51
+ return await this.formatAsyncResults(asyncRunResult, (0, utils_1.getCurrentTime)(), codeCoverage, testRunSummary, progress);
52
+ }
53
+ catch (e) {
54
+ throw (0, diagnosticUtil_1.formatTestErrors)(e);
55
+ }
67
56
  }
68
57
  /**
69
58
  * Report Asynchronous Test Run Results
@@ -71,69 +60,65 @@ class AsyncTests {
71
60
  * @param codeCoverage should report code coverages
72
61
  * @param token cancellation token
73
62
  */
74
- reportAsyncResults(testRunId, codeCoverage = false, token) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- try {
77
- const sClient = new streaming_1.StreamingClient(this.connection);
78
- yield sClient.init();
79
- yield sClient.handshake();
80
- let queueItem;
81
- let testRunSummary = yield this.checkRunStatus(testRunId);
82
- if (testRunSummary !== undefined) {
83
- queueItem = yield sClient.handler(undefined, testRunId);
84
- }
85
- else {
86
- queueItem = (yield sClient.subscribe(undefined, testRunId)).queueItem;
87
- testRunSummary = yield this.checkRunStatus(testRunId);
88
- }
89
- token &&
90
- token.onCancellationRequested(() => __awaiter(this, void 0, void 0, function* () {
91
- sClient.disconnect();
92
- }));
93
- if (token && token.isCancellationRequested) {
94
- return null;
95
- }
96
- return yield this.formatAsyncResults({ queueItem, runId: testRunId }, (0, utils_1.getCurrentTime)(), codeCoverage, testRunSummary);
97
- }
98
- catch (e) {
99
- throw (0, diagnosticUtil_1.formatTestErrors)(e);
100
- }
101
- });
102
- }
103
- checkRunStatus(testRunId, progress) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- if (!(0, utils_2.isValidTestRunID)(testRunId)) {
106
- throw new Error(i18n_1.nls.localize('invalidTestRunIdErr', testRunId));
63
+ async reportAsyncResults(testRunId, codeCoverage = false, token) {
64
+ try {
65
+ const sClient = new streaming_1.StreamingClient(this.connection);
66
+ await sClient.init();
67
+ await sClient.handshake();
68
+ let queueItem;
69
+ let testRunSummary = await this.checkRunStatus(testRunId);
70
+ if (testRunSummary !== undefined) {
71
+ queueItem = await sClient.handler(undefined, testRunId);
107
72
  }
108
- let testRunSummaryQuery = 'SELECT AsyncApexJobId, Status, ClassesCompleted, ClassesEnqueued, ';
109
- testRunSummaryQuery +=
110
- 'MethodsEnqueued, StartTime, EndTime, TestTime, UserId ';
111
- testRunSummaryQuery += `FROM ApexTestRunResult WHERE AsyncApexJobId = '${testRunId}'`;
112
- progress === null || progress === void 0 ? void 0 : progress.report({
113
- type: 'FormatTestResultProgress',
114
- value: 'retrievingTestRunSummary',
115
- message: i18n_1.nls.localize('retrievingTestRunSummary')
116
- });
117
- const testRunSummaryResults = (yield this.connection.tooling.query(testRunSummaryQuery, {
118
- autoFetch: true
119
- }));
120
- if (testRunSummaryResults.records.length === 0) {
121
- throw new Error(i18n_1.nls.localize('noTestResultSummary', testRunId));
73
+ else {
74
+ queueItem = (await sClient.subscribe(undefined, testRunId)).queueItem;
75
+ testRunSummary = await this.checkRunStatus(testRunId);
122
76
  }
123
- if (testRunSummaryResults.records[0].Status ===
124
- "Aborted" /* Aborted */ ||
125
- testRunSummaryResults.records[0].Status ===
126
- "Failed" /* Failed */ ||
127
- testRunSummaryResults.records[0].Status ===
128
- "Completed" /* Completed */ ||
129
- testRunSummaryResults.records[0].Status ===
130
- "Passed" /* Passed */ ||
131
- testRunSummaryResults.records[0].Status ===
132
- "Skipped" /* Skipped */) {
133
- return testRunSummaryResults.records[0];
77
+ token &&
78
+ token.onCancellationRequested(async () => {
79
+ sClient.disconnect();
80
+ });
81
+ if (token && token.isCancellationRequested) {
82
+ return null;
134
83
  }
135
- return undefined;
84
+ return await this.formatAsyncResults({ queueItem, runId: testRunId }, (0, utils_1.getCurrentTime)(), codeCoverage, testRunSummary);
85
+ }
86
+ catch (e) {
87
+ throw (0, diagnosticUtil_1.formatTestErrors)(e);
88
+ }
89
+ }
90
+ async checkRunStatus(testRunId, progress) {
91
+ if (!(0, utils_2.isValidTestRunID)(testRunId)) {
92
+ throw new Error(i18n_1.nls.localize('invalidTestRunIdErr', testRunId));
93
+ }
94
+ let testRunSummaryQuery = 'SELECT AsyncApexJobId, Status, ClassesCompleted, ClassesEnqueued, ';
95
+ testRunSummaryQuery +=
96
+ 'MethodsEnqueued, StartTime, EndTime, TestTime, UserId ';
97
+ testRunSummaryQuery += `FROM ApexTestRunResult WHERE AsyncApexJobId = '${testRunId}'`;
98
+ progress?.report({
99
+ type: 'FormatTestResultProgress',
100
+ value: 'retrievingTestRunSummary',
101
+ message: i18n_1.nls.localize('retrievingTestRunSummary')
136
102
  });
103
+ const testRunSummaryResults = (await this.connection.tooling.query(testRunSummaryQuery, {
104
+ autoFetch: true
105
+ }));
106
+ if (testRunSummaryResults.records.length === 0) {
107
+ throw new Error(i18n_1.nls.localize('noTestResultSummary', testRunId));
108
+ }
109
+ if (testRunSummaryResults.records[0].Status ===
110
+ "Aborted" /* ApexTestRunResultStatus.Aborted */ ||
111
+ testRunSummaryResults.records[0].Status ===
112
+ "Failed" /* ApexTestRunResultStatus.Failed */ ||
113
+ testRunSummaryResults.records[0].Status ===
114
+ "Completed" /* ApexTestRunResultStatus.Completed */ ||
115
+ testRunSummaryResults.records[0].Status ===
116
+ "Passed" /* ApexTestRunResultStatus.Passed */ ||
117
+ testRunSummaryResults.records[0].Status ===
118
+ "Skipped" /* ApexTestRunResultStatus.Skipped */) {
119
+ return testRunSummaryResults.records[0];
120
+ }
121
+ return undefined;
137
122
  }
138
123
  /**
139
124
  * Format the results of a completed asynchronous test run
@@ -144,169 +129,172 @@ class AsyncTests {
144
129
  * @param progress progress reporter
145
130
  * @returns
146
131
  */
147
- formatAsyncResults(asyncRunResult, commandStartTime, codeCoverage = false, testRunSummary, progress) {
148
- var _a, _b;
149
- return __awaiter(this, void 0, void 0, function* () {
150
- const coveredApexClassIdSet = new Set();
151
- const apexTestResults = yield this.getAsyncTestResults(asyncRunResult.queueItem);
152
- const { apexTestClassIdSet, testResults, globalTests } = yield this.buildAsyncTestResults(apexTestResults);
153
- let outcome = testRunSummary.Status;
154
- if (globalTests.failed > 0) {
155
- outcome = "Failed" /* Failed */;
156
- }
157
- else if (globalTests.passed === 0) {
158
- outcome = "Skipped" /* Skipped */;
159
- }
160
- else if (testRunSummary.Status === "Completed" /* Completed */) {
161
- outcome = "Passed" /* Passed */;
162
- }
163
- // TODO: deprecate testTotalTime
164
- const result = {
165
- summary: {
166
- outcome,
167
- testsRan: testResults.length,
168
- passing: globalTests.passed,
169
- failing: globalTests.failed,
170
- skipped: globalTests.skipped,
171
- passRate: (0, utils_2.calculatePercentage)(globalTests.passed, testResults.length),
172
- failRate: (0, utils_2.calculatePercentage)(globalTests.failed, testResults.length),
173
- skipRate: (0, utils_2.calculatePercentage)(globalTests.skipped, testResults.length),
174
- testStartTime: (0, utils_1.formatStartTime)(testRunSummary.StartTime, 'ISO'),
175
- testExecutionTimeInMs: (_a = testRunSummary.TestTime) !== null && _a !== void 0 ? _a : 0,
176
- testTotalTimeInMs: (_b = testRunSummary.TestTime) !== null && _b !== void 0 ? _b : 0,
177
- commandTimeInMs: (0, utils_1.getCurrentTime)() - commandStartTime,
178
- hostname: this.connection.instanceUrl,
179
- orgId: this.connection.getAuthInfoFields().orgId,
180
- username: this.connection.getUsername(),
181
- testRunId: asyncRunResult.runId,
182
- userId: testRunSummary.UserId
183
- },
184
- tests: testResults
185
- };
186
- if (codeCoverage) {
187
- const perClassCovMap = yield this.codecoverage.getPerClassCodeCoverage(apexTestClassIdSet);
188
- result.tests.forEach(item => {
189
- const keyCodeCov = `${item.apexClass.id}-${item.methodName}`;
190
- const perClassCov = perClassCovMap.get(keyCodeCov);
191
- // Skipped test is not in coverage map, check to see if perClassCov exists first
192
- if (perClassCov) {
193
- perClassCov.forEach(classCov => coveredApexClassIdSet.add(classCov.apexClassOrTriggerId));
194
- item.perClassCoverage = perClassCov;
195
- }
196
- });
197
- progress === null || progress === void 0 ? void 0 : progress.report({
198
- type: 'FormatTestResultProgress',
199
- value: 'queryingForAggregateCodeCoverage',
200
- message: i18n_1.nls.localize('queryingForAggregateCodeCoverage')
201
- });
202
- const { codeCoverageResults, totalLines, coveredLines } = yield this.codecoverage.getAggregateCodeCoverage(coveredApexClassIdSet);
203
- result.codecoverage = codeCoverageResults;
204
- result.summary.totalLines = totalLines;
205
- result.summary.coveredLines = coveredLines;
206
- result.summary.testRunCoverage = (0, utils_2.calculatePercentage)(coveredLines, totalLines);
207
- result.summary.orgWideCoverage = yield this.codecoverage.getOrgWideCoverage();
208
- }
209
- return result;
210
- });
211
- }
212
- getAsyncTestResults(testQueueResult) {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- let apexTestResultQuery = 'SELECT Id, QueueItemId, StackTrace, Message, ';
215
- apexTestResultQuery +=
216
- 'RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, ';
217
- apexTestResultQuery +=
218
- 'ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix ';
219
- apexTestResultQuery += 'FROM ApexTestResult WHERE QueueItemId IN (%s)';
220
- const apexResultIds = testQueueResult.records.map(record => record.Id);
221
- // iterate thru ids, create query with id, & compare query length to char limit
222
- const queries = [];
223
- for (let i = 0; i < apexResultIds.length; i += constants_1.QUERY_RECORD_LIMIT) {
224
- const recordSet = apexResultIds
225
- .slice(i, i + constants_1.QUERY_RECORD_LIMIT)
226
- .map(id => `'${id}'`);
227
- const query = util.format(apexTestResultQuery, recordSet.join(','));
228
- queries.push(query);
229
- }
230
- const queryPromises = queries.map(query => {
231
- return this.connection.tooling.query(query, {
232
- autoFetch: true
233
- });
132
+ async formatAsyncResults(asyncRunResult, commandStartTime, codeCoverage = false, testRunSummary, progress) {
133
+ const coveredApexClassIdSet = new Set();
134
+ const apexTestResults = await this.getAsyncTestResults(asyncRunResult.queueItem);
135
+ const { apexTestClassIdSet, testResults, globalTests } = await this.buildAsyncTestResults(apexTestResults);
136
+ let outcome = testRunSummary.Status;
137
+ if (globalTests.failed > 0) {
138
+ outcome = "Failed" /* ApexTestRunResultStatus.Failed */;
139
+ }
140
+ else if (globalTests.passed === 0) {
141
+ outcome = "Skipped" /* ApexTestRunResultStatus.Skipped */;
142
+ }
143
+ else if (testRunSummary.Status === "Completed" /* ApexTestRunResultStatus.Completed */) {
144
+ outcome = "Passed" /* ApexTestRunResultStatus.Passed */;
145
+ }
146
+ // TODO: deprecate testTotalTime
147
+ const result = {
148
+ summary: {
149
+ outcome,
150
+ testsRan: testResults.length,
151
+ passing: globalTests.passed,
152
+ failing: globalTests.failed,
153
+ skipped: globalTests.skipped,
154
+ passRate: (0, utils_2.calculatePercentage)(globalTests.passed, testResults.length),
155
+ failRate: (0, utils_2.calculatePercentage)(globalTests.failed, testResults.length),
156
+ skipRate: (0, utils_2.calculatePercentage)(globalTests.skipped, testResults.length),
157
+ testStartTime: (0, utils_1.formatStartTime)(testRunSummary.StartTime, 'ISO'),
158
+ testExecutionTimeInMs: testRunSummary.TestTime ?? 0,
159
+ testTotalTimeInMs: testRunSummary.TestTime ?? 0,
160
+ commandTimeInMs: (0, utils_1.getCurrentTime)() - commandStartTime,
161
+ hostname: this.connection.instanceUrl,
162
+ orgId: this.connection.getAuthInfoFields().orgId,
163
+ username: this.connection.getUsername(),
164
+ testRunId: asyncRunResult.runId,
165
+ userId: testRunSummary.UserId
166
+ },
167
+ tests: testResults
168
+ };
169
+ if (codeCoverage) {
170
+ const perClassCovMap = await this.codecoverage.getPerClassCodeCoverage(apexTestClassIdSet);
171
+ result.tests.forEach((item) => {
172
+ const keyCodeCov = `${item.apexClass.id}-${item.methodName}`;
173
+ const perClassCov = perClassCovMap.get(keyCodeCov);
174
+ // Skipped test is not in coverage map, check to see if perClassCov exists first
175
+ if (perClassCov) {
176
+ perClassCov.forEach((classCov) => coveredApexClassIdSet.add(classCov.apexClassOrTriggerId));
177
+ item.perClassCoverage = perClassCov;
178
+ }
179
+ });
180
+ progress?.report({
181
+ type: 'FormatTestResultProgress',
182
+ value: 'queryingForAggregateCodeCoverage',
183
+ message: i18n_1.nls.localize('queryingForAggregateCodeCoverage')
234
184
  });
235
- const apexTestResults = yield Promise.all(queryPromises);
236
- return apexTestResults;
185
+ const { codeCoverageResults, totalLines, coveredLines } = await this.codecoverage.getAggregateCodeCoverage(coveredApexClassIdSet);
186
+ result.codecoverage = codeCoverageResults;
187
+ result.summary.totalLines = totalLines;
188
+ result.summary.coveredLines = coveredLines;
189
+ result.summary.testRunCoverage = (0, utils_2.calculatePercentage)(coveredLines, totalLines);
190
+ result.summary.orgWideCoverage =
191
+ await this.codecoverage.getOrgWideCoverage();
192
+ }
193
+ return result;
194
+ }
195
+ async getAsyncTestResults(testQueueResult) {
196
+ let apexTestResultQuery = 'SELECT Id, QueueItemId, StackTrace, Message, ';
197
+ apexTestResultQuery +=
198
+ 'RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, ';
199
+ apexTestResultQuery +=
200
+ 'ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix ';
201
+ apexTestResultQuery += 'FROM ApexTestResult WHERE QueueItemId IN (%s)';
202
+ const apexResultIds = testQueueResult.records.map((record) => record.Id);
203
+ // iterate thru ids, create query with id, & compare query length to char limit
204
+ const queries = [];
205
+ for (let i = 0; i < apexResultIds.length; i += constants_1.QUERY_RECORD_LIMIT) {
206
+ const recordSet = apexResultIds
207
+ .slice(i, i + constants_1.QUERY_RECORD_LIMIT)
208
+ .map((id) => `'${id}'`);
209
+ const query = util.format(apexTestResultQuery, recordSet.join(','));
210
+ queries.push(query);
211
+ }
212
+ const queryPromises = queries.map((query) => {
213
+ return (0, utils_2.queryAll)(this.connection, query, true);
237
214
  });
215
+ const apexTestResults = await Promise.all(queryPromises);
216
+ return apexTestResults;
238
217
  }
239
- buildAsyncTestResults(apexTestResults) {
240
- return __awaiter(this, void 0, void 0, function* () {
241
- const apexTestClassIdSet = new Set();
242
- let passed = 0;
243
- let failed = 0;
244
- let skipped = 0;
245
- // Iterate over test results, format and add them as results.tests
246
- const testResults = [];
247
- for (const result of apexTestResults) {
248
- result.records.forEach(item => {
249
- var _a;
250
- switch (item.Outcome) {
251
- case "Pass" /* Pass */:
252
- passed++;
253
- break;
254
- case "Fail" /* Fail */:
255
- case "CompileFail" /* CompileFail */:
256
- failed++;
257
- break;
258
- case "Skip" /* Skip */:
259
- skipped++;
260
- break;
261
- }
262
- apexTestClassIdSet.add(item.ApexClass.Id);
263
- // Can only query the FullName field if a single record is returned, so manually build the field
264
- item.ApexClass.FullName = item.ApexClass.NamespacePrefix
265
- ? `${item.ApexClass.NamespacePrefix}.${item.ApexClass.Name}`
266
- : item.ApexClass.Name;
267
- const diagnostic = item.Message || item.StackTrace ? (0, diagnosticUtil_1.getAsyncDiagnostic)(item) : null;
268
- testResults.push(Object.assign({ id: item.Id, queueItemId: item.QueueItemId, stackTrace: item.StackTrace, message: item.Message, asyncApexJobId: item.AsyncApexJobId, methodName: item.MethodName, outcome: item.Outcome, apexLogId: item.ApexLogId, apexClass: {
269
- id: item.ApexClass.Id,
270
- name: item.ApexClass.Name,
271
- namespacePrefix: item.ApexClass.NamespacePrefix,
272
- fullName: item.ApexClass.FullName
273
- }, runTime: (_a = item.RunTime) !== null && _a !== void 0 ? _a : 0, testTimestamp: item.TestTimestamp, fullName: `${item.ApexClass.FullName}.${item.MethodName}` }, (diagnostic ? { diagnostic } : {})));
218
+ async buildAsyncTestResults(apexTestResults) {
219
+ const apexTestClassIdSet = new Set();
220
+ let passed = 0;
221
+ let failed = 0;
222
+ let skipped = 0;
223
+ // Iterate over test results, format and add them as results.tests
224
+ const testResults = [];
225
+ for (const result of apexTestResults) {
226
+ result.records.forEach((item) => {
227
+ switch (item.Outcome) {
228
+ case "Pass" /* ApexTestResultOutcome.Pass */:
229
+ passed++;
230
+ break;
231
+ case "Fail" /* ApexTestResultOutcome.Fail */:
232
+ case "CompileFail" /* ApexTestResultOutcome.CompileFail */:
233
+ failed++;
234
+ break;
235
+ case "Skip" /* ApexTestResultOutcome.Skip */:
236
+ skipped++;
237
+ break;
238
+ }
239
+ apexTestClassIdSet.add(item.ApexClass.Id);
240
+ // Can only query the FullName field if a single record is returned, so manually build the field
241
+ item.ApexClass.FullName = item.ApexClass.NamespacePrefix
242
+ ? `${item.ApexClass.NamespacePrefix}.${item.ApexClass.Name}`
243
+ : item.ApexClass.Name;
244
+ const diagnostic = item.Message || item.StackTrace ? (0, diagnosticUtil_1.getAsyncDiagnostic)(item) : null;
245
+ testResults.push({
246
+ id: item.Id,
247
+ queueItemId: item.QueueItemId,
248
+ stackTrace: item.StackTrace,
249
+ message: item.Message,
250
+ asyncApexJobId: item.AsyncApexJobId,
251
+ methodName: item.MethodName,
252
+ outcome: item.Outcome,
253
+ apexLogId: item.ApexLogId,
254
+ apexClass: {
255
+ id: item.ApexClass.Id,
256
+ name: item.ApexClass.Name,
257
+ namespacePrefix: item.ApexClass.NamespacePrefix,
258
+ fullName: item.ApexClass.FullName
259
+ },
260
+ runTime: item.RunTime ?? 0,
261
+ testTimestamp: item.TestTimestamp, // TODO: convert timestamp
262
+ fullName: `${item.ApexClass.FullName}.${item.MethodName}`,
263
+ ...(diagnostic ? { diagnostic } : {})
274
264
  });
275
- }
276
- return {
277
- apexTestClassIdSet,
278
- testResults,
279
- globalTests: { passed, failed, skipped }
280
- };
281
- });
265
+ });
266
+ }
267
+ return {
268
+ apexTestClassIdSet,
269
+ testResults,
270
+ globalTests: { passed, failed, skipped }
271
+ };
282
272
  }
283
273
  /**
284
274
  * Abort test run with test run id
285
275
  * @param testRunId
286
276
  */
287
- abortTestRun(testRunId, progress) {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- progress === null || progress === void 0 ? void 0 : progress.report({
290
- type: 'AbortTestRunProgress',
291
- value: 'abortingTestRun',
292
- message: i18n_1.nls.localize('abortingTestRun', testRunId),
293
- testRunId
294
- });
295
- const testQueueItems = yield this.connection.tooling.query(`SELECT Id, Status FROM ApexTestQueueItem WHERE ParentJobId = '${testRunId}'`);
296
- for (const record of testQueueItems.records) {
297
- record.Status = "Aborted" /* Aborted */;
298
- }
299
- yield this.connection.tooling.update('ApexTestQueueItem', testQueueItems.records);
300
- progress === null || progress === void 0 ? void 0 : progress.report({
301
- type: 'AbortTestRunProgress',
302
- value: 'abortingTestRunRequested',
303
- message: i18n_1.nls.localize('abortingTestRunRequested', testRunId),
304
- testRunId
305
- });
277
+ async abortTestRun(testRunId, progress) {
278
+ progress?.report({
279
+ type: 'AbortTestRunProgress',
280
+ value: 'abortingTestRun',
281
+ message: i18n_1.nls.localize('abortingTestRun', testRunId),
282
+ testRunId
283
+ });
284
+ const testQueueItems = await this.connection.tooling.query(`SELECT Id, Status FROM ApexTestQueueItem WHERE ParentJobId = '${testRunId}'`);
285
+ for (const record of testQueueItems.records) {
286
+ record.Status = "Aborted" /* ApexTestQueueItemStatus.Aborted */;
287
+ }
288
+ await this.connection.tooling.update('ApexTestQueueItem', testQueueItems.records);
289
+ progress?.report({
290
+ type: 'AbortTestRunProgress',
291
+ value: 'abortingTestRunRequested',
292
+ message: i18n_1.nls.localize('abortingTestRunRequested', testRunId),
293
+ testRunId
306
294
  });
307
295
  }
308
296
  getTestRunRequestAction(options) {
309
- const requestTestRun = () => __awaiter(this, void 0, void 0, function* () {
297
+ const requestTestRun = async () => {
310
298
  const url = `${this.connection.tooling._baseUrl()}/runTestsAsynchronous`;
311
299
  const request = {
312
300
  method: 'POST',
@@ -315,13 +303,13 @@ class AsyncTests {
315
303
  headers: { 'content-type': 'application/json' }
316
304
  };
317
305
  try {
318
- const testRunId = (yield this.connection.tooling.request(request));
306
+ const testRunId = (await this.connection.tooling.request(request));
319
307
  return Promise.resolve(testRunId);
320
308
  }
321
309
  catch (e) {
322
310
  return Promise.reject(e);
323
311
  }
324
- });
312
+ };
325
313
  return requestTestRun;
326
314
  }
327
315
  }