Skip to content

Commit 6dcb32e

Browse files
authored
Merge pull request #91 from salesforcecli/wr/asyncByDefault
fix: restore run tests async by default
2 parents 1b921db + 74a11d5 commit 6dcb32e

File tree

6 files changed

+19
-53
lines changed

6 files changed

+19
-53
lines changed

src/commands/apex/get/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class Test extends SfCommand<RunResult> {
8080
'output-dir': flags['output-dir'],
8181
'result-format': flags['result-format'],
8282
json: flags.json,
83-
codeCoverage: flags['code-coverage'],
83+
'code-coverage': flags['code-coverage'],
8484
});
8585
}
8686
}

src/commands/apex/run/test.ts

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,15 @@ export default class Test extends SfCommand<RunCommandResult> {
148148

149149
if ('summary' in result) {
150150
const testReporter = new TestReporter(new Ux({ jsonEnabled: this.jsonEnabled() }), conn, this.config.bin);
151-
152-
return testReporter.report(result, {
153-
wait: flags.wait,
154-
'output-dir': flags['output-dir'],
155-
'result-format': flags['result-format'],
156-
'detailed-coverage': flags['detailed-coverage'],
157-
synchronous: flags.synchronous,
158-
json: flags.json,
159-
codeCoverage: flags['code-coverage'],
160-
});
151+
return testReporter.report(result, flags);
161152
} else {
162153
// async test run
163154
this.log(messages.getMessage('runTestReportCommand', [this.config.bin, result.testRunId, conn.getUsername()]));
164155
return result;
165156
}
166157
}
167158

168-
// eslint-disable-next-line class-methods-use-this,complexity
159+
// eslint-disable-next-line class-methods-use-this
169160
public async validateFlags(
170161
codeCoverage?: boolean,
171162
resultFormatFlag?: string,
@@ -187,16 +178,13 @@ export default class Test extends SfCommand<RunCommandResult> {
187178
return Promise.reject(new Error(messages.getMessage('testLevelErr')));
188179
}
189180

190-
let test: TestLevel;
191181
if (testLevel) {
192-
test = testLevel;
193-
} else if (classNames || suiteNames || tests) {
194-
test = TestLevel.RunSpecifiedTests;
195-
} else {
196-
test = TestLevel.RunLocalTests;
182+
return testLevel;
197183
}
198-
199-
return test;
184+
if (classNames || suiteNames || tests) {
185+
return TestLevel.RunSpecifiedTests;
186+
}
187+
return TestLevel.RunLocalTests;
200188
}
201189

202190
private async runTest(
@@ -212,11 +200,11 @@ export default class Test extends SfCommand<RunCommandResult> {
212200
...(await testService.buildSyncPayload(testLevel, flags.tests, flags['class-names'])),
213201
skipCodeCoverage: !flags['code-coverage'],
214202
};
215-
return (await testService.runTestSynchronous(
203+
return testService.runTestSynchronous(
216204
payload,
217205
flags['code-coverage'],
218206
this.cancellationTokenSource.token
219-
)) as TestResult;
207+
) as Promise<TestResult>;
220208
}
221209

222210
private async runTestAsynchronous(
@@ -239,34 +227,12 @@ export default class Test extends SfCommand<RunCommandResult> {
239227
};
240228

241229
// cast as TestRunIdResult because we're building an async payload which will return an async result
242-
return (await testService.runTestAsynchronous(
230+
return testService.runTestAsynchronous(
243231
payload,
244232
flags['code-coverage'],
245-
shouldImmediatelyReturn(flags.synchronous, flags['result-format'], flags.json, flags.wait),
233+
flags.wait && flags.wait.minutes > 0 ? false : !(flags.synchronous && !this.jsonEnabled()),
246234
undefined,
247235
this.cancellationTokenSource.token
248-
)) as TestRunIdResult;
236+
) as Promise<TestRunIdResult>;
249237
}
250238
}
251-
/**
252-
* Handles special exceptions where we don't want to return early
253-
* with the testRunId.
254-
**/
255-
const shouldImmediatelyReturn = (
256-
synchronous?: boolean,
257-
resultFormatFlag?: string,
258-
json?: boolean,
259-
wait?: Duration
260-
): boolean => {
261-
if (resultFormatFlag !== undefined) {
262-
return false;
263-
}
264-
265-
// when the user has explictly asked to wait for results, but didn't give a format
266-
if (wait) {
267-
return false;
268-
}
269-
270-
// historical expectation to wait for results from a synchronous test run
271-
return !(synchronous && !json);
272-
};

src/commands/apex/tail/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class Log extends SfCommand<void> {
6161
await logService.prepareTraceFlag(flags['debug-level'] ?? '');
6262
}
6363

64-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-misused-promises
6565
await logService.tail(flags['target-org'], this.logTailer.bind(this));
6666
this.log(messages.getMessage('finishedTailing'));
6767
}

src/reporters/testReporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class TestReporter {
4444
'detailed-coverage'?: boolean;
4545
synchronous?: boolean;
4646
json?: boolean;
47-
codeCoverage?: boolean;
47+
'code-coverage'?: boolean;
4848
}
4949
): Promise<RunResult> {
5050
if (options['output-dir']) {
@@ -54,13 +54,13 @@ export class TestReporter {
5454
jsonOutput,
5555
options['output-dir'],
5656
options['result-format'] as Optional<ResultFormat>,
57-
options['detailed-coverage'] as boolean,
57+
Boolean(options['detailed-coverage']),
5858
options.synchronous
5959
);
6060

6161
const testService = new TestService(this.connection);
6262

63-
await testService.writeResultFiles(result, outputDirConfig, options['code-coverage'] as boolean);
63+
await testService.writeResultFiles(result, outputDirConfig, options['code-coverage']);
6464
}
6565

6666
try {

test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "@salesforce/dev-config/tsconfig-test",
2+
"extends": "@salesforce/dev-config/tsconfig-test-strict",
33
"include": ["./**/*.ts"],
44
"compilerOptions": {
55
"skipLibCheck": true,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "@salesforce/dev-config/tsconfig",
2+
"extends": "@salesforce/dev-config/tsconfig-strict",
33
"compilerOptions": {
44
"outDir": "lib",
55
"rootDir": "src",

0 commit comments

Comments
 (0)