Skip to content

Commit cbd1569

Browse files
committed
chore: revert some unneeded changes
1 parent 81f915b commit cbd1569

File tree

6 files changed

+632
-533
lines changed

6 files changed

+632
-533
lines changed

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"version": "1.3.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues",
7-
"main": "lib/src/index.js",
7+
"main": "lib/index.js",
88
"dependencies": {
99
"@oclif/core": "^1.16.4",
1010
"@salesforce/apex-node": "1.3.0",
1111
"@salesforce/command": "^5.1.0",
12-
"@salesforce/core": "^3.19.1",
12+
"@salesforce/core": "^3.23.3",
1313
"chalk": "^4.1.0",
1414
"tslib": "^1"
1515
},
@@ -60,7 +60,7 @@
6060
],
6161
"license": "BSD-3-Clause",
6262
"oclif": {
63-
"commands": "./lib/src/commands",
63+
"commands": "./lib/commands",
6464
"topics": {
6565
"force": {
6666
"external": true,
@@ -96,16 +96,14 @@
9696
"repository": "salesforcecli/plugin-apex",
9797
"scripts": {
9898
"build": "shx rm -rf lib && tsc -b",
99-
"compile": "yarn build",
100-
"format": "npx prettier --config ./.prettierrc.json --write './{src,test,scripts}/**/*.{ts,js,json}'",
99+
"format": "prettier --config ../../.prettierrc --write './{src,test,scripts}/**/*.{ts,js,json}'",
101100
"lint": "eslint -c .eslintrc.json --ext .ts ./src ./test",
102101
"manifest:generate": "yarn build && oclif manifest",
103102
"postpack": "shx rm -f oclif.manifest.json",
104-
"test": "cross-env FORCE_COLOR=true mocha --recursive \"./lib/**/*.test.js\" --full-trace",
103+
"test": "cross-env FORCE_COLOR=true mocha --recursive \"./test/**/*.test.ts\" --full-trace",
105104
"version": "oclif readme && git add README.md",
106105
"test:deprecation-policy": "./bin/run snapshot:compare",
107106
"test:command-reference": "./bin/run commandreference:generate -p apex --erroronwarnings",
108-
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
109107
"package": "npm pack"
110108
},
111109
"husky": {

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

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ import {
1818
import { flags, SfdxCommand } from '@salesforce/command';
1919
import { Messages, SfError } from '@salesforce/core';
2020
import { AnyJson } from '@salesforce/ts-types';
21-
import { buildOutputDirConfig, CliJsonFormat, JsonReporter } from '../../../../reporters';
22-
import { buildDescription, logLevels, resultFormat, FAILURE_EXIT_CODE } from '../../../../utils';
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';
2332

2433
Messages.importMessagesDirectory(__dirname);
2534
const messages = Messages.load('@salesforce/plugin-apex', 'run', [
@@ -51,7 +60,11 @@ const messages = Messages.load('@salesforce/plugin-apex', 'run', [
5160
'warningMessage'
5261
]);
5362

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

138151
// add listener for errors
139152
process.on('uncaughtException', err => {
140-
const formattedErr = this.formatError(new SfError(messages.getMessage('apexLibErr', [err.message])));
153+
const formattedErr = this.formatError(
154+
new SfError(messages.getMessage('apexLibErr', [err.message]))
155+
);
141156
this.ux.error(...formattedErr);
142157
process.exit();
143158
});
@@ -163,7 +178,11 @@ export default class Run extends SfdxCommand {
163178
// This was re-introduced due to https://github.com/forcedotcom/salesforcedx-vscode/issues/3154
164179
// Address with W-9163533
165180
if (this.flags.synchronous && testLevel === TestLevel.RunSpecifiedTests) {
166-
const payload = await testService.buildSyncPayload(testLevel, this.flags.tests, this.flags.classnames);
181+
const payload = await testService.buildSyncPayload(
182+
testLevel,
183+
this.flags.tests,
184+
this.flags.classnames
185+
);
167186
payload.skipCodeCoverage = this.flags.codecoverage ? false : true;
168187
result = (await testService.runTestSynchronous(
169188
payload,
@@ -204,19 +223,28 @@ export default class Run extends SfdxCommand {
204223
this.flags.synchronous
205224
);
206225

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

210233
try {
211234
if (
212235
result.hasOwnProperty('summary') &&
213-
(result as TestResult).summary.outcome === ApexTestRunResultStatus.Failed
236+
(result as TestResult).summary.outcome ===
237+
ApexTestRunResultStatus.Failed
214238
) {
215239
process.exitCode = FAILURE_EXIT_CODE;
216240
}
217241
switch (this.flags.resultformat) {
218242
case 'human':
219-
this.logHuman(result as TestResult, this.flags.detailedcoverage, this.flags.outputdir);
243+
this.logHuman(
244+
result as TestResult,
245+
this.flags.detailedcoverage,
246+
this.flags.outputdir
247+
);
220248
break;
221249
case 'tap':
222250
this.logTap(result as TestResult);
@@ -235,15 +263,26 @@ export default class Run extends SfdxCommand {
235263
break;
236264
default:
237265
if (this.flags.synchronous || this.flags.wait) {
238-
this.logHuman(result as TestResult, this.flags.detailedcoverage, this.flags.outputdir);
266+
this.logHuman(
267+
result as TestResult,
268+
this.flags.detailedcoverage,
269+
this.flags.outputdir
270+
);
239271
} else {
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()]));
272+
const id = (result as TestRunIdResult).testRunId;
273+
this.ux.log(
274+
messages.getMessage('runTestReportCommand', [
275+
id,
276+
this.org?.getUsername()
277+
])
278+
);
242279
}
243280
}
244281
} catch (e) {
245282
this.ux.logJson(result);
246-
const msg = messages.getMessage('testResultProcessErr', [(e as Error).message]);
283+
const msg = messages.getMessage('testResultProcessErr', [
284+
(e as Error).message
285+
]);
247286
this.ux.error(msg);
248287
}
249288

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

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

258299
if (
259300
(this.flags.classnames && (this.flags.suitenames || this.flags.tests)) ||
260301
(this.flags.suitenames && this.flags.tests)
261302
) {
262-
return Promise.reject(new Error(messages.getMessage('classSuiteTestErr')));
303+
return Promise.reject(
304+
new Error(messages.getMessage('classSuiteTestErr'))
305+
);
263306
}
264307

265308
if (
266309
this.flags.synchronous &&
267-
(this.flags.suitenames || (this.flags.classnames && this.flags.classnames.split(',').length > 1))
310+
(this.flags.suitenames ||
311+
(this.flags.classnames && this.flags.classnames.split(',').length > 1))
268312
) {
269313
return Promise.reject(new Error(messages.getMessage('syncClassErr')));
270314
}
@@ -282,7 +326,11 @@ export default class Run extends SfdxCommand {
282326
let testLevel: TestLevel;
283327
if (this.flags.testlevel) {
284328
testLevel = this.flags.testlevel;
285-
} else if (this.flags.classnames || this.flags.suitenames || this.flags.tests) {
329+
} else if (
330+
this.flags.classnames ||
331+
this.flags.suitenames ||
332+
this.flags.tests
333+
) {
286334
testLevel = TestLevel.RunSpecifiedTests;
287335
} else {
288336
testLevel = TestLevel.RunLocalTests;
@@ -291,7 +339,11 @@ export default class Run extends SfdxCommand {
291339
return testLevel;
292340
}
293341

294-
private logHuman(result: TestResult, detailedCoverage: boolean, outputDir: string): void {
342+
private logHuman(
343+
result: TestResult,
344+
detailedCoverage: boolean,
345+
outputDir: string
346+
): void {
295347
if (outputDir) {
296348
this.ux.log(messages.getMessage('outputDirHint', [outputDir]));
297349
}
@@ -311,20 +363,26 @@ export default class Run extends SfdxCommand {
311363
this.ux.log(reporter.format(result));
312364
}
313365

314-
private formatResultInJson(result: TestResult | TestRunIdResult): CliJsonFormat | TestRunIdResult {
366+
private formatResultInJson(
367+
result: TestResult | TestRunIdResult
368+
): CliJsonFormat | TestRunIdResult {
315369
try {
316370
const reporter = new JsonReporter();
317-
return result.hasOwnProperty('summary') ? reporter.format(result as TestResult) : (result as TestRunIdResult);
371+
return result.hasOwnProperty('summary')
372+
? reporter.format(result as TestResult)
373+
: (result as TestRunIdResult);
318374
} catch (e) {
319375
this.ux.logJson(result);
320-
const msg = messages.getMessage('testResultProcessErr', [(e as Error).message]);
376+
const msg = messages.getMessage('testResultProcessErr', [
377+
(e as Error).message
378+
]);
321379
this.ux.error(msg);
322380
throw e;
323381
}
324382
}
325383

326384
private formatReportHint(result: TestResult): string {
327-
let reportArgs = `-i ${result.summary?.testRunId}`;
385+
let reportArgs = `-i ${result.summary.testRunId}`;
328386
if (this.flags.targetusername) {
329387
reportArgs += ` -u ${this.flags.targetusername}`;
330388
}

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

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

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

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

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

100102
sandboxStub.stub(Org, 'create').resolves(Org.prototype);
101-
sandboxStub.stub(Org.prototype, 'getConnection').returns(Connection.prototype);
103+
sandboxStub
104+
.stub(Org.prototype, 'getConnection')
105+
.returns(Connection.prototype);
102106
sandboxStub.stub(Org.prototype, 'getUsername').returns(TEST_USERNAME);
103107
sandboxStub.stub(Org.prototype, 'getOrgId').returns('abc123');
104108
});
@@ -112,12 +116,21 @@ describe('force:apex:execute', () => {
112116
.withConnectionRequest(() => {
113117
return Promise.resolve(soapResponse);
114118
})
115-
.stub(ExecuteService.prototype, 'readApexFile', () => 'System.assert(true);')
119+
.stub(
120+
ExecuteService.prototype,
121+
'readApexFile',
122+
() => 'System.assert(true);'
123+
)
116124
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
117125
'fakeData';
118126
})
119127
.stdout()
120-
.command(['force:apex:execute', '--apexcodefile', path.join('Users', 'test', 'path', 'to', 'file'), '--json'])
128+
.command([
129+
'force:apex:execute',
130+
'--apexcodefile',
131+
path.join('Users', 'test', 'path', 'to', 'file'),
132+
'--json'
133+
])
121134
.it('runs command with filepath flag and successful result', ctx => {
122135
const result = ctx.stdout;
123136
expect(result).to.not.be.empty;
@@ -133,12 +146,21 @@ describe('force:apex:execute', () => {
133146
.withConnectionRequest(() => {
134147
return Promise.resolve(soapResponse);
135148
})
136-
.stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true);')
149+
.stub(
150+
ExecuteService.prototype,
151+
'getUserInput',
152+
() => 'System.assert(true);'
153+
)
137154
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
138155
'fakeData';
139156
})
140157
.stdout()
141-
.command(['force:apex:execute', '--targetusername', '[email protected]', '--json'])
158+
.command([
159+
'force:apex:execute',
160+
'--targetusername',
161+
162+
'--json'
163+
])
142164
.it('runs default command with json flag and successful result', ctx => {
143165
const result = ctx.stdout;
144166
expect(result).to.not.be.empty;
@@ -159,7 +181,12 @@ describe('force:apex:execute', () => {
159181
'fakeData';
160182
})
161183
.stdout()
162-
.command(['force:apex:execute', '--targetusername', '[email protected]', '--json'])
184+
.command([
185+
'force:apex:execute',
186+
'--targetusername',
187+
188+
'--json'
189+
])
163190
.it('runs default command with json flag and compile problem', ctx => {
164191
const result = ctx.stdout;
165192
expect(result).to.not.be.empty;
@@ -173,10 +200,10 @@ describe('force:apex:execute', () => {
173200
.withConnectionRequest(() => {
174201
return Promise.resolve(soapResponse);
175202
})
176-
// .stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true)')
177-
// .stub(ExecuteService.prototype, 'buildExecRequest', () => {
178-
// 'fakeData';
179-
// })
203+
.stub(ExecuteService.prototype, 'getUserInput', () => 'System.assert(true)')
204+
.stub(ExecuteService.prototype, 'buildExecRequest', () => {
205+
'fakeData';
206+
})
180207
.stdout()
181208
.command(['force:apex:execute', '--targetusername', '[email protected]'])
182209
.it('runs default command successfully with human readable output', ctx => {
@@ -196,11 +223,14 @@ describe('force:apex:execute', () => {
196223
})
197224
.stdout()
198225
.command(['force:apex:execute', '--targetusername', '[email protected]'])
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-
});
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+
);
204234

205235
test
206236
.withOrg({ username: '[email protected]' }, true)
@@ -213,9 +243,12 @@ describe('force:apex:execute', () => {
213243
})
214244
.stdout()
215245
.command(['force:apex:execute', '--targetusername', '[email protected]'])
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-
});
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+
);
221254
});

0 commit comments

Comments
 (0)