Skip to content

Commit fc15cbe

Browse files
Merge pull request #178 from salesforcecli/sm/restore-testrunid-text-file
fix: call testService method to store testRunId
2 parents caefe77 + 00881d8 commit fc15cbe

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/commands/apex/run/test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ export default class Test extends SfCommand<RunCommandResult> {
160160
// Log the proper 'apex get test' command for the user to run later
161161
this.log(messages.getMessage('runTestReportCommand', [this.config.bin, result.testRunId, conn.getUsername()]));
162162
this.info(messages.getMessage('runTestSyncInstructions'));
163+
164+
if (flags['output-dir']) {
165+
// testService writes a file with just the test run id in it to test-run-id.txt
166+
// github.com/forcedotcom/salesforcedx-apex/blob/c986abfabee3edf12f396f1d2e43720988fa3911/src/tests/testService.ts#L245-L246
167+
await testService.writeResultFiles(result, { dirPath: flags['output-dir'] }, flags['code-coverage']);
168+
}
169+
163170
return result;
164171
}
165172
}

test/commands/apex/run/test.nut.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ describe('apex run test', () => {
206206
execCmd(`apex:get:test -i ${result?.testRunId}`, { ensureExitCode: 0 });
207207
});
208208

209+
it('will save test-run-id file for async', async () => {
210+
const resultDir = 'asyncResults';
211+
const result = execCmd<TestRunIdResult>(`apex:run:test --json --output-dir ${resultDir}`, { ensureExitCode: 0 })
212+
.jsonOutput?.result;
213+
expect(result?.testRunId).to.be.a('string');
214+
expect(result?.testRunId.startsWith('707')).to.be.true;
215+
const outputDir = path.join(session.project.dir, resultDir);
216+
const testRunIdFile = path.join(outputDir, 'test-run-id.txt');
217+
expect(fs.existsSync(testRunIdFile)).to.be.true;
218+
expect(await fs.promises.readFile(testRunIdFile, 'utf-8')).equal(result?.testRunId);
219+
// get the test results to make sure it's not 'ALREADY IN PROGRESS' or 'QUEUED' for the next test
220+
execCmd(`apex:get:test -i ${result?.testRunId}`, { ensureExitCode: 0 });
221+
});
222+
209223
it('will run default tests and default async', async () => {
210224
const result = execCmd('apex:run:test', { ensureExitCode: 0 }).shellOutput.stdout;
211225
expect(result).to.include('apex get test -i 707');

0 commit comments

Comments
 (0)