Skip to content

Commit ce8e2af

Browse files
committed
chore: upd pkg json point at commands and format
1 parent c731b82 commit ce8e2af

File tree

4 files changed

+510
-585
lines changed

4 files changed

+510
-585
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "1.3.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues",
7-
"main": "lib/index.js",
7+
"main": "lib/src/index.js",
88
"dependencies": {
99
"@oclif/core": "^1.16.4",
1010
"@salesforce/apex-node": "1.3.0",
@@ -60,7 +60,7 @@
6060
],
6161
"license": "BSD-3-Clause",
6262
"oclif": {
63-
"commands": "./lib/commands",
63+
"commands": "./lib/src/commands",
6464
"topics": {
6565
"force": {
6666
"external": true,
@@ -93,7 +93,7 @@
9393
"@salesforce/plugin-command-reference"
9494
]
9595
},
96-
"repository": "forcedotcom/salesforcedx-apex",
96+
"repository": "salesforcecli/plugin-apex",
9797
"scripts": {
9898
"build": "shx rm -rf lib && tsc -b",
9999
"compile": "yarn build",

src/commands/force/apex/test/run.ts

Lines changed: 20 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ import {
1818
import { flags, SfdxCommand } from '@salesforce/command';
1919
import { Messages, SfError } from '@salesforce/core';
2020
import { AnyJson } from '@salesforce/ts-types';
21-
import {
22-
buildOutputDirConfig,
23-
CliJsonFormat,
24-
JsonReporter
25-
} from '../../../../reporters';
26-
import {
27-
buildDescription,
28-
logLevels,
29-
resultFormat,
30-
FAILURE_EXIT_CODE
31-
} from '../../../../utils';
21+
import { buildOutputDirConfig, CliJsonFormat, JsonReporter } from '../../../../reporters';
22+
import { buildDescription, logLevels, resultFormat, FAILURE_EXIT_CODE } from '../../../../utils';
3223

3324
Messages.importMessagesDirectory(__dirname);
3425
const messages = Messages.load('@salesforce/plugin-apex', 'run', [
@@ -60,11 +51,7 @@ const messages = Messages.load('@salesforce/plugin-apex', 'run', [
6051
'warningMessage'
6152
]);
6253

63-
export const TestLevelValues = [
64-
'RunLocalTests',
65-
'RunAllTestsInOrg',
66-
'RunSpecifiedTests'
67-
];
54+
export const TestLevelValues = ['RunLocalTests', 'RunAllTestsInOrg', 'RunSpecifiedTests'];
6855
export default class Run extends SfdxCommand {
6956
protected static requiresUsername = true;
7057
protected cancellationTokenSource = new CancellationTokenSource();
@@ -150,9 +137,7 @@ export default class Run extends SfdxCommand {
150137

151138
// add listener for errors
152139
process.on('uncaughtException', err => {
153-
const formattedErr = this.formatError(
154-
new SfError(messages.getMessage('apexLibErr', [err.message]))
155-
);
140+
const formattedErr = this.formatError(new SfError(messages.getMessage('apexLibErr', [err.message])));
156141
this.ux.error(...formattedErr);
157142
process.exit();
158143
});
@@ -178,11 +163,7 @@ export default class Run extends SfdxCommand {
178163
// This was re-introduced due to https://github.com/forcedotcom/salesforcedx-vscode/issues/3154
179164
// Address with W-9163533
180165
if (this.flags.synchronous && testLevel === TestLevel.RunSpecifiedTests) {
181-
const payload = await testService.buildSyncPayload(
182-
testLevel,
183-
this.flags.tests,
184-
this.flags.classnames
185-
);
166+
const payload = await testService.buildSyncPayload(testLevel, this.flags.tests, this.flags.classnames);
186167
payload.skipCodeCoverage = this.flags.codecoverage ? false : true;
187168
result = (await testService.runTestSynchronous(
188169
payload,
@@ -223,28 +204,19 @@ export default class Run extends SfdxCommand {
223204
this.flags.synchronous
224205
);
225206

226-
await testService.writeResultFiles(
227-
result,
228-
outputDirConfig,
229-
this.flags.codecoverage
230-
);
207+
await testService.writeResultFiles(result, outputDirConfig, this.flags.codecoverage);
231208
}
232209

233210
try {
234211
if (
235212
result.hasOwnProperty('summary') &&
236-
(result as TestResult).summary.outcome ===
237-
ApexTestRunResultStatus.Failed
213+
(result as TestResult).summary.outcome === ApexTestRunResultStatus.Failed
238214
) {
239215
process.exitCode = FAILURE_EXIT_CODE;
240216
}
241217
switch (this.flags.resultformat) {
242218
case 'human':
243-
this.logHuman(
244-
result as TestResult,
245-
this.flags.detailedcoverage,
246-
this.flags.outputdir
247-
);
219+
this.logHuman(result as TestResult, this.flags.detailedcoverage, this.flags.outputdir);
248220
break;
249221
case 'tap':
250222
this.logTap(result as TestResult);
@@ -263,26 +235,15 @@ export default class Run extends SfdxCommand {
263235
break;
264236
default:
265237
if (this.flags.synchronous || this.flags.wait) {
266-
this.logHuman(
267-
result as TestResult,
268-
this.flags.detailedcoverage,
269-
this.flags.outputdir
270-
);
238+
this.logHuman(result as TestResult, this.flags.detailedcoverage, this.flags.outputdir);
271239
} else {
272-
const id = (result as TestRunIdResult).testRunId;
273-
this.ux.log(
274-
messages.getMessage('runTestReportCommand', [
275-
id,
276-
this.org?.getUsername()
277-
])
278-
);
240+
const id: TestRunIdResult = ((result as TestResult).tests[0].id as unknown) as TestRunIdResult;
241+
this.ux.log(messages.getMessage('runTestReportCommand', [String(id), this.org?.getUsername()]));
279242
}
280243
}
281244
} catch (e) {
282245
this.ux.logJson(result);
283-
const msg = messages.getMessage('testResultProcessErr', [
284-
(e as Error).message
285-
]);
246+
const msg = messages.getMessage('testResultProcessErr', [(e as Error).message]);
286247
this.ux.error(msg);
287248
}
288249

@@ -291,24 +252,19 @@ export default class Run extends SfdxCommand {
291252

292253
public async validateFlags(): Promise<void> {
293254
if (this.flags.codecoverage && !this.flags.resultformat) {
294-
return Promise.reject(
295-
new Error(messages.getMessage('missingReporterErr'))
296-
);
255+
return Promise.reject(new Error(messages.getMessage('missingReporterErr')));
297256
}
298257

299258
if (
300259
(this.flags.classnames && (this.flags.suitenames || this.flags.tests)) ||
301260
(this.flags.suitenames && this.flags.tests)
302261
) {
303-
return Promise.reject(
304-
new Error(messages.getMessage('classSuiteTestErr'))
305-
);
262+
return Promise.reject(new Error(messages.getMessage('classSuiteTestErr')));
306263
}
307264

308265
if (
309266
this.flags.synchronous &&
310-
(this.flags.suitenames ||
311-
(this.flags.classnames && this.flags.classnames.split(',').length > 1))
267+
(this.flags.suitenames || (this.flags.classnames && this.flags.classnames.split(',').length > 1))
312268
) {
313269
return Promise.reject(new Error(messages.getMessage('syncClassErr')));
314270
}
@@ -326,11 +282,7 @@ export default class Run extends SfdxCommand {
326282
let testLevel: TestLevel;
327283
if (this.flags.testlevel) {
328284
testLevel = this.flags.testlevel;
329-
} else if (
330-
this.flags.classnames ||
331-
this.flags.suitenames ||
332-
this.flags.tests
333-
) {
285+
} else if (this.flags.classnames || this.flags.suitenames || this.flags.tests) {
334286
testLevel = TestLevel.RunSpecifiedTests;
335287
} else {
336288
testLevel = TestLevel.RunLocalTests;
@@ -339,11 +291,7 @@ export default class Run extends SfdxCommand {
339291
return testLevel;
340292
}
341293

342-
private logHuman(
343-
result: TestResult,
344-
detailedCoverage: boolean,
345-
outputDir: string
346-
): void {
294+
private logHuman(result: TestResult, detailedCoverage: boolean, outputDir: string): void {
347295
if (outputDir) {
348296
this.ux.log(messages.getMessage('outputDirHint', [outputDir]));
349297
}
@@ -363,19 +311,13 @@ export default class Run extends SfdxCommand {
363311
this.ux.log(reporter.format(result));
364312
}
365313

366-
private formatResultInJson(
367-
result: TestResult | TestRunIdResult
368-
): CliJsonFormat | TestRunIdResult {
314+
private formatResultInJson(result: TestResult | TestRunIdResult): CliJsonFormat | TestRunIdResult {
369315
try {
370316
const reporter = new JsonReporter();
371-
return result.hasOwnProperty('summary')
372-
? reporter.format(result as TestResult)
373-
: (result as TestRunIdResult);
317+
return result.hasOwnProperty('summary') ? reporter.format(result as TestResult) : (result as TestRunIdResult);
374318
} catch (e) {
375319
this.ux.logJson(result);
376-
const msg = messages.getMessage('testResultProcessErr', [
377-
(e as Error).message
378-
]);
320+
const msg = messages.getMessage('testResultProcessErr', [(e as Error).message]);
379321
this.ux.error(msg);
380322
throw e;
381323
}

test/commands/force/apex/execute.test.ts

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import { createSandbox, SinonSandbox } from 'sinon';
1212
import { Connection, Org } from '@salesforce/core';
1313

1414
describe('force:apex:execute', () => {
15-
const log =
16-
'47.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO\nExecute Anonymous: System.assert(true);|EXECUTION_FINISHED\n';
15+
const log = '47.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO\nExecute Anonymous: System.assert(true);|EXECUTION_FINISHED\n';
1716
const successJsonResult = {
1817
column: -1,
1918
line: -1,
@@ -89,8 +88,7 @@ describe('force:apex:execute', () => {
8988
};
9089

9190
const successfulResponse = `Compiled successfully.\nExecuted successfully.\n\n${log}\n`;
92-
const compileResponse =
93-
'Error: Line: 11, Column: 1\nError: problem compiling\n\n';
91+
const compileResponse = 'Error: Line: 11, Column: 1\nError: problem compiling\n\n';
9492
const runtimeResponse = `Compiled successfully.\nError: problem at runtime\nError: Issue in mock file\n\n${log}\n`;
9593
const TEST_USERNAME = '[email protected]';
9694

@@ -100,9 +98,7 @@ describe('force:apex:execute', () => {
10098
sandboxStub = createSandbox();
10199

102100
sandboxStub.stub(Org, 'create').resolves(Org.prototype);
103-
sandboxStub
104-
.stub(Org.prototype, 'getConnection')
105-
.returns(Connection.prototype);
101+
sandboxStub.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
106102
sandboxStub.stub(Org.prototype, 'getUsername').returns(TEST_USERNAME);
107103
sandboxStub.stub(Org.prototype, 'getOrgId').returns('abc123');
108104
});
@@ -116,21 +112,12 @@ describe('force:apex:execute', () => {
116112
.withConnectionRequest(() => {
117113
return Promise.resolve(soapResponse);
118114
})
119-
.stub(
120-
ExecuteService.prototype,
121-
'readApexFile',
122-
() => 'System.assert(true);'
123-
)
115+
.stub(ExecuteService.prototype, 'readApexFile', () => 'System.assert(true);')
124116
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
125117
'fakeData';
126118
})
127119
.stdout()
128-
.command([
129-
'force:apex:execute',
130-
'--apexcodefile',
131-
path.join('Users', 'test', 'path', 'to', 'file'),
132-
'--json'
133-
])
120+
.command(['force:apex:execute', '--apexcodefile', path.join('Users', 'test', 'path', 'to', 'file'), '--json'])
134121
.it('runs command with filepath flag and successful result', ctx => {
135122
const result = ctx.stdout;
136123
expect(result).to.not.be.empty;
@@ -146,21 +133,12 @@ describe('force:apex:execute', () => {
146133
.withConnectionRequest(() => {
147134
return Promise.resolve(soapResponse);
148135
})
149-
.stub(
150-
ExecuteService.prototype,
151-
'getUserInput',
152-
() => 'System.assert(true);'
153-
)
136+
.stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true);')
154137
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
155138
'fakeData';
156139
})
157140
.stdout()
158-
.command([
159-
'force:apex:execute',
160-
'--targetusername',
161-
162-
'--json'
163-
])
141+
.command(['force:apex:execute', '--targetusername', '[email protected]', '--json'])
164142
.it('runs default command with json flag and successful result', ctx => {
165143
const result = ctx.stdout;
166144
expect(result).to.not.be.empty;
@@ -181,12 +159,7 @@ describe('force:apex:execute', () => {
181159
'fakeData';
182160
})
183161
.stdout()
184-
.command([
185-
'force:apex:execute',
186-
'--targetusername',
187-
188-
'--json'
189-
])
162+
.command(['force:apex:execute', '--targetusername', '[email protected]', '--json'])
190163
.it('runs default command with json flag and compile problem', ctx => {
191164
const result = ctx.stdout;
192165
expect(result).to.not.be.empty;
@@ -200,10 +173,10 @@ describe('force:apex:execute', () => {
200173
.withConnectionRequest(() => {
201174
return Promise.resolve(soapResponse);
202175
})
203-
.stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true)')
204-
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
205-
'fakeData';
206-
})
176+
// .stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true)')
177+
// .stub(ExecuteService.prototype, 'buildExecRequest', () => {
178+
// 'fakeData';
179+
// })
207180
.stdout()
208181
.command(['force:apex:execute', '--targetusername', '[email protected]'])
209182
.it('runs default command successfully with human readable output', ctx => {
@@ -223,14 +196,11 @@ describe('force:apex:execute', () => {
223196
})
224197
.stdout()
225198
.command(['force:apex:execute', '--targetusername', '[email protected]'])
226-
.it(
227-
'runs default command with compile issue in human readable output',
228-
ctx => {
229-
const result = ctx.stdout;
230-
expect(result).to.not.be.empty;
231-
expect(result).to.eql(compileResponse);
232-
}
233-
);
199+
.it('runs default command with compile issue in human readable output', ctx => {
200+
const result = ctx.stdout;
201+
expect(result).to.not.be.empty;
202+
expect(result).to.eql(compileResponse);
203+
});
234204

235205
test
236206
.withOrg({ username: '[email protected]' }, true)
@@ -243,12 +213,9 @@ describe('force:apex:execute', () => {
243213
})
244214
.stdout()
245215
.command(['force:apex:execute', '--targetusername', '[email protected]'])
246-
.it(
247-
'runs default command with runtime issue in human readable output',
248-
ctx => {
249-
const result = ctx.stdout;
250-
expect(result).to.not.be.empty;
251-
expect(result).to.eql(runtimeResponse);
252-
}
253-
);
216+
.it('runs default command with runtime issue in human readable output', ctx => {
217+
const result = ctx.stdout;
218+
expect(result).to.not.be.empty;
219+
expect(result).to.eql(runtimeResponse);
220+
});
254221
});

0 commit comments

Comments
 (0)