Skip to content

Commit ea1222f

Browse files
chore: fix NUTs, bump apex-node
1 parent a8b9b94 commit ea1222f

File tree

6 files changed

+168
-122
lines changed

6 files changed

+168
-122
lines changed

.idea/vcs.xml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"main": "lib/index.js",
88
"dependencies": {
99
"@oclif/core": "^2.8.2",
10-
"@salesforce/apex-node": "^1.6.1",
10+
"@salesforce/apex-node": "^1.6.2",
1111
"@salesforce/core": "^3.36.0",
1212
"@salesforce/sf-plugins-core": "^2.4.2",
1313
"chalk": "^4.1.0",
@@ -24,7 +24,7 @@
2424
"@salesforce/prettier-config": "^0.0.3",
2525
"@salesforce/ts-sinon": "^1.4.4",
2626
"@salesforce/ts-types": "^2.0.1",
27-
"@swc/core": "^1.3.60",
27+
"@swc/core": "1.3.30",
2828
"@typescript-eslint/eslint-plugin": "^5.59.5",
2929
"@typescript-eslint/parser": "^5.59.7",
3030
"chai": "^4.2.0",

src/commands/apex/run/test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ export default class Test extends SfCommand<RunCommandResult> {
148148
? await this.runTest(testService, flags, testLevel)
149149
: await this.runTestAsynchronous(testService, flags, testLevel);
150150

151-
//
152-
153-
//
154-
155151
if (this.cancellationTokenSource.token.isCancellationRequested) {
156152
throw new SfError('Cancelled');
157153
}

test/commands/apex/get/test.nut.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import * as path from 'path';
88
import * as fs from 'fs';
99
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
10-
import { expect } from 'chai';
10+
import { config, expect } from 'chai';
11+
import { TestRunIdResult } from '@salesforce/apex-node';
1112
import { RunResult } from '../../../../src/reporters';
13+
config.truncateThreshold = 0;
1214

1315
describe('apex get test', () => {
1416
let session: TestSession;
@@ -29,7 +31,9 @@ describe('apex get test', () => {
2931
});
3032

3133
execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0 });
32-
testId = execCmd<RunResult>('apex:test:run', { ensureExitCode: 0 }).jsonOutput?.result?.summary?.testRunId;
34+
testId = execCmd<TestRunIdResult>('apex:run:test --json', {
35+
ensureExitCode: 0,
36+
}).jsonOutput?.result.testRunId.trim();
3337
expect(testId).to.be.a('string');
3438
});
3539

@@ -65,8 +69,9 @@ describe('apex get test', () => {
6569
});
6670

6771
it('will get tests --json', async () => {
68-
const result = execCmd<RunResult>(`apex:get:test ${testId} --json`, { ensureExitCode: 0 }).jsonOutput?.result;
69-
expect(result?.tests).length.to.equal(11);
72+
const result = execCmd<RunResult>(`apex:get:test --test-run-id ${testId} --json`, { ensureExitCode: 0 }).jsonOutput
73+
?.result;
74+
expect(result?.tests.length).to.equal(11);
7075
expect(result?.summary.outcome).to.equal('Passed');
7176
expect(result?.summary.testsRan).to.equal(11);
7277
expect(result?.summary).to.have.all.keys(
@@ -106,30 +111,33 @@ describe('apex get test', () => {
106111
const result = execCmd(`apex:get:test --test-run-id ${testId} --code-coverage`, { ensureExitCode: 0 }).shellOutput
107112
.stdout;
108113
expect(result).to.include('=== Apex Code Coverage by Class');
109-
expect(result).to.include(/CLASSES\w+PERCENT\w+UNCOVERED LINES/);
110-
expect(result).to.include('SampleDataController 100%');
114+
expect(result).to.match(/TEST NAME\s+OUTCOME\s+MESSAGE\s+RUNTIME \(MS\)/);
111115
});
112116
it('will run default tests sync with --code-coverage --json', async () => {
113117
const result = execCmd<RunResult>(`apex:get:test --test-run-id ${testId} --code-coverage --json`, {
114118
ensureExitCode: 0,
115119
}).jsonOutput?.result;
116-
expect(result?.summary).to.have.all.keys('totalLines', 'coveredLines', 'orgWideCoverage', 'testRunCoverage');
117-
expect(result?.coverage?.coverage).to.have.all.keys(
118-
'id',
119-
'name',
120-
'lines',
121-
'totalLines',
122-
'totalCovered',
123-
'coveredPercent'
120+
expect(result?.summary).to.have.all.keys(
121+
'commandTime',
122+
'failRate',
123+
'passRate',
124+
'failing',
125+
'hostname',
126+
'orgId',
127+
'outcome',
128+
'passing',
129+
'skipped',
130+
'orgWideCoverage',
131+
'testRunCoverage',
132+
'testExecutionTime',
133+
'testRunId',
134+
'testStartTime',
135+
'testTotalTime',
136+
'testsRan',
137+
'userId',
138+
'username'
124139
);
125140
});
126-
it('will run default tests sync with --code-coverage --detailed-coverage', async () => {
127-
const result = execCmd(`apex:get:test --test-run-id ${testId} --code-coverage --detailed-coverage`, {
128-
ensureExitCode: 0,
129-
}).shellOutput.stdout;
130-
expect(result).to.include('=== Apex Code Coverage for Test Run 707');
131-
expect(result).to.include(/TEST NAME\w+CLASS BEING TESTED\w+OUTCOME\w+PERCENT\w+MESSAGE\w+RUNTIME (MS)/);
132-
});
133141
});
134142

135143
it('will create --output-dir', () => {
@@ -139,7 +147,7 @@ describe('apex get test', () => {
139147
expect(result).to.include('Test result files written to testresults');
140148
const outputDir = path.join(session.project.dir, 'testresults');
141149
expect(fs.statSync(outputDir).isDirectory()).to.be.true;
142-
expect(fs.readdirSync(outputDir)).length.to.equal(6);
150+
expect(fs.readdirSync(outputDir).length).to.equal(6);
143151
expect(fs.existsSync(path.join(outputDir, 'test-result-codecoverage.json'))).to.be.true;
144152
expect(fs.existsSync(path.join(outputDir, 'test-result.txt'))).to.be.true;
145153
expect(fs.existsSync(path.join(outputDir, 'test-run-id.txt'))).to.be.true;

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

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import * as path from 'path';
88
import * as fs from 'fs';
99
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
10-
import { expect } from 'chai';
10+
import { expect, config } from 'chai';
1111
import { TestRunIdResult } from '@salesforce/apex-node/lib/src/tests/types';
1212
import { RunResult } from '../../../../src/reporters';
1313

14+
config.truncateThreshold = 0;
15+
1416
describe('apex run test', () => {
1517
let session: TestSession;
1618
before(async () => {
@@ -54,31 +56,38 @@ describe('apex run test', () => {
5456
});
5557
});
5658

57-
it('will run default tests and default async', async () => {
58-
const result = execCmd('apex:run:test', { ensureExitCode: 0 }).shellOutput.stdout;
59-
expect(result).to.include('Run "sf apex get test -i 707');
60-
expect(result).to.include('-o');
61-
expect(result).to.include('" to retrieve test results');
62-
});
63-
64-
it('will run default tests and default async --json', async () => {
65-
const result = execCmd<TestRunIdResult>('apex:run:test', { ensureExitCode: 0 }).jsonOutput?.result;
66-
expect(result?.testRunId).to.be.a('string');
67-
expect(result?.testRunId.startsWith('707')).to.be.true;
68-
});
69-
7059
describe('--code-coverage', () => {
7160
it('will run default tests sync with --code-coverage', async () => {
7261
const result = execCmd('apex:run:test --wait 10 --code-coverage', { ensureExitCode: 0 }).shellOutput.stdout;
7362
expect(result).to.include('=== Apex Code Coverage by Class');
74-
expect(result).to.include(/CLASSES\w+PERCENT\w+UNCOVERED LINES/);
63+
expect(result).to.match(/CLASSES\s+PERCENT\s+UNCOVERED LINES/);
7564
expect(result).to.include('SampleDataController 100%');
7665
});
7766
it('will run default tests sync with --code-coverage --json', async () => {
7867
const result = execCmd<RunResult>('apex:run:test --wait 10 --code-coverage --json', { ensureExitCode: 0 })
7968
.jsonOutput?.result;
80-
expect(result?.summary).to.have.all.keys('totalLines', 'coveredLines', 'orgWideCoverage', 'testRunCoverage');
81-
expect(result?.coverage?.coverage).to.have.all.keys(
69+
expect(result?.summary).to.have.all.keys(
70+
'outcome',
71+
'testsRan',
72+
'passing',
73+
'failing',
74+
'skipped',
75+
'passRate',
76+
'failRate',
77+
'testStartTime',
78+
'testExecutionTime',
79+
'testTotalTime',
80+
'commandTime',
81+
'hostname',
82+
'orgId',
83+
'username',
84+
'testRunId',
85+
'userId',
86+
'orgWideCoverage',
87+
'testRunCoverage'
88+
);
89+
90+
expect(result?.coverage?.coverage[0]).to.have.all.keys(
8291
'id',
8392
'name',
8493
'lines',
@@ -91,7 +100,7 @@ describe('apex run test', () => {
91100
const result = execCmd('apex:run:test --wait 10 --code-coverage --detailed-coverage', { ensureExitCode: 0 })
92101
.shellOutput.stdout;
93102
expect(result).to.include('=== Apex Code Coverage for Test Run 707');
94-
expect(result).to.include(/TEST NAME\w+CLASS BEING TESTED\w+OUTCOME\w+PERCENT\w+MESSAGE\w+RUNTIME (MS)/);
103+
expect(result).to.match(/TEST NAME\s+CLASS BEING TESTED\s+OUTCOME\s+PERCENT\s+MESSAGE\s+RUNTIME \(MS\)/);
95104
});
96105
});
97106

@@ -101,7 +110,7 @@ describe('apex run test', () => {
101110
expect(result).to.include('Test result files written to testresults');
102111
const outputDir = path.join(session.project.dir, 'testresults');
103112
expect(fs.statSync(outputDir).isDirectory()).to.be.true;
104-
expect(fs.readdirSync(outputDir)).length.to.equal(6);
113+
expect(fs.readdirSync(outputDir).length).to.equal(6);
105114
expect(fs.existsSync(path.join(outputDir, 'test-result-codecoverage.json'))).to.be.true;
106115
expect(fs.existsSync(path.join(outputDir, 'test-result.txt'))).to.be.true;
107116
expect(fs.existsSync(path.join(outputDir, 'test-run-id.txt'))).to.be.true;
@@ -116,7 +125,7 @@ describe('apex run test', () => {
116125

117126
it('will run default tests and wait --json', async () => {
118127
const result = execCmd<RunResult>('apex:run:test --wait 10 --json', { ensureExitCode: 0 }).jsonOutput?.result;
119-
expect(result?.tests).length.to.equal(11);
128+
expect(result?.tests.length).to.equal(11);
120129
expect(result?.summary.outcome).to.equal('Passed');
121130
expect(result?.summary.testsRan).to.equal(11);
122131
expect(result?.summary).to.have.all.keys(
@@ -154,38 +163,58 @@ describe('apex run test', () => {
154163
it('will run specified classes --class-names', async () => {
155164
const result = execCmd('apex:run:test -w 10 --class-names TestPropertyController', { ensureExitCode: 0 })
156165
.shellOutput.stdout;
157-
expect(result).to.include(/Tests Ran\w+3/);
166+
expect(result).to.match(/Tests Ran\s+3/);
158167

159168
const result1 = execCmd('apex:run:test -w 10 --class-names TestPropertyController -n GeocodingServiceTest', {
160169
ensureExitCode: 0,
161170
}).shellOutput.stdout;
162-
expect(result1).to.include(/Tests Ran\w+6/);
171+
expect(result1).to.match(/Tests Ran\s+6/);
163172

164173
const result2 = execCmd(
165174
'apex:run:test -w 10 --class-names TestPropertyController -n GeocodingServiceTest,FileUtilitiesTest',
166175
{
167176
ensureExitCode: 0,
168177
}
169178
).shellOutput.stdout;
170-
expect(result2).to.include(/Tests Ran\w+10/);
179+
expect(result2).to.match(/Tests Ran\s+10/);
171180
});
172181

173182
it('will run specified tests --tests', async () => {
174183
const result = execCmd('apex:run:test -w 10 --tests TestPropertyController', { ensureExitCode: 0 }).shellOutput
175184
.stdout;
176-
expect(result).to.include(/Tests Ran\w+3/);
185+
expect(result).to.match(/Tests Ran\s+3/);
177186

178187
const result1 = execCmd('apex:run:test -w 10 --tests TestPropertyController -t GeocodingServiceTest', {
179188
ensureExitCode: 0,
180189
}).shellOutput.stdout;
181-
expect(result1).to.include(/Tests Ran\w+6/);
190+
expect(result1).to.match(/Tests Ran\s+6/);
182191

183192
const result2 = execCmd(
184193
'apex:run:test -w 10 --tests TestPropertyController -t GeocodingServiceTest,FileUtilitiesTest',
185194
{
186195
ensureExitCode: 0,
187196
}
188197
).shellOutput.stdout;
189-
expect(result2).to.include(/Tests Ran\w+10/);
198+
expect(result2).to.match(/Tests Ran\s+10/);
199+
});
200+
201+
it('will run default tests and default async --json', async () => {
202+
const result = execCmd<TestRunIdResult>('apex:run:test --json', { ensureExitCode: 0 }).jsonOutput?.result;
203+
expect(result?.testRunId).to.be.a('string');
204+
expect(result?.testRunId.startsWith('707')).to.be.true;
205+
// get the test results to make sure it's not 'ALREADY IN PROGRESS' or 'QUEUED' for the next test
206+
execCmd(`apex:get:test -i ${result?.testRunId}`, { ensureExitCode: 0 });
207+
});
208+
209+
it('will run default tests and default async', async () => {
210+
const result = execCmd('apex:run:test', { ensureExitCode: 0 }).shellOutput.stdout;
211+
expect(result).to.include('apex get test -i 707');
212+
expect(result).to.include('-o');
213+
expect(result).to.include('" to retrieve test results');
214+
// .match returns RegExpArray | undefined, and typing ?[0] makes TS think it's a ternary, not an undefined array accessor
215+
// and we can't use ?.at yet
216+
const id = result.match(/707[\d\w]+\s/)?.find((i) => i);
217+
// get the test results to make sure it's not 'ALREADY IN PROGRESS' or 'QUEUED' for the next test
218+
execCmd(`apex:get:test -i ${id}`, { ensureExitCode: 0 });
190219
});
191220
});

0 commit comments

Comments
 (0)