Skip to content

Commit f5250bb

Browse files
test: add test:get NUT
1 parent dfa1800 commit f5250bb

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

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

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import * as path from 'path';
8+
import * as fs from 'fs';
9+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
10+
import { expect } from 'chai';
11+
import { TestRunIdResult } from '@salesforce/apex-node/lib/src/tests/types';
12+
import { RunResult } from '../../../../src/reporters';
13+
14+
describe('apex get test', () => {
15+
let session: TestSession;
16+
let testId: string | undefined;
17+
before(async () => {
18+
session = await TestSession.create({
19+
project: {
20+
gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
21+
},
22+
devhubAuthStrategy: 'AUTO',
23+
scratchOrgs: [
24+
{
25+
config: path.join('config', 'project-scratch-def.json'),
26+
setDefault: true,
27+
alias: 'org',
28+
},
29+
],
30+
});
31+
32+
execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0 });
33+
testId = execCmd<RunResult>('apex:test:run', { ensureExitCode: 0 }).jsonOutput?.result?.summary?.testRunId;
34+
expect(testId).to.be.a('string');
35+
});
36+
37+
after(async () => {
38+
await session?.zip(undefined, 'artifacts');
39+
await session?.clean();
40+
});
41+
42+
describe('--result-format', () => {
43+
it('will print tap format', async () => {
44+
const result = execCmd(`apex:get:test --result-format tap --test-run-id ${testId}`, { ensureExitCode: 0 })
45+
.shellOutput.stdout;
46+
expect(result).to.include('1..1');
47+
expect(result).to.include('ok 1');
48+
expect(result).to.include('--result-format <format>" to retrieve test results in a different format.');
49+
});
50+
it('will print junit format', async () => {
51+
const result = execCmd(`apex:get:test --result-format junit --test-run-id ${testId}`, { ensureExitCode: 0 })
52+
.shellOutput.stdout;
53+
expect(result).to.include('<?xml version="1.0" encoding="UTF-8"?>');
54+
expect(result).to.include('<testsuites>');
55+
expect(result).to.include('<testsuite name="force.apex" timestamp="');
56+
expect(result).to.include(
57+
'<testcase name="testGetPicturesWithResults" classname="TestPropertyController" time="'
58+
);
59+
});
60+
});
61+
62+
it('will run report on test', async () => {
63+
const result = execCmd(`apex:get:test --test-run-id ${testId}`, { ensureExitCode: 0 }).shellOutput.stdout;
64+
expect(result).to.include('=== Test Summary');
65+
expect(result).to.include('=== Test Results');
66+
});
67+
68+
it('will get tests --json', async () => {
69+
const result = execCmd<RunResult>(`apex:get:test ${testId} --json`, { ensureExitCode: 0 }).jsonOutput?.result;
70+
expect(result?.tests).length.to.equal(11);
71+
expect(result?.summary.outcome).to.equal('Passed');
72+
expect(result?.summary.testsRan).to.equal(11);
73+
expect(result?.summary).to.have.all.keys(
74+
'outcome',
75+
'testsRan',
76+
'passing',
77+
'failing',
78+
'skipped',
79+
'passRate',
80+
'failRate',
81+
'testStartTime',
82+
'testExecutionTime',
83+
'testTotalTime',
84+
'commandTime',
85+
'hostname',
86+
'orgId',
87+
'username',
88+
'testRunId',
89+
'userId'
90+
);
91+
expect(result?.tests[0]).to.have.all.keys(
92+
'Id',
93+
'QueueItemId',
94+
'StackTrace',
95+
'Message',
96+
'AsyncApexJobId',
97+
'MethodName',
98+
'Outcome',
99+
'ApexClass',
100+
'RunTime',
101+
'FullName'
102+
);
103+
});
104+
105+
describe('--code-coverage', () => {
106+
it('will run default tests sync with --code-coverage', async () => {
107+
const result = execCmd(`apex:get:test --test-run-id ${testId} --code-coverage`, { ensureExitCode: 0 }).shellOutput
108+
.stdout;
109+
expect(result).to.include('=== Apex Code Coverage by Class');
110+
expect(result).to.include(/CLASSES\w+PERCENT\w+UNCOVERED LINES/);
111+
expect(result).to.include('SampleDataController 100%');
112+
});
113+
it('will run default tests sync with --code-coverage --json', async () => {
114+
const result = execCmd<RunResult>(`apex:get:test --test-run-id ${testId} --code-coverage --json`, {
115+
ensureExitCode: 0,
116+
}).jsonOutput?.result;
117+
expect(result?.summary).to.have.all.keys('totalLines', 'coveredLines', 'orgWideCoverage', 'testRunCoverage');
118+
expect(result?.coverage?.coverage).to.have.all.keys(
119+
'id',
120+
'name',
121+
'lines',
122+
'totalLines',
123+
'totalCovered',
124+
'coveredPercent'
125+
);
126+
});
127+
it('will run default tests sync with --code-coverage --detailed-coverage', async () => {
128+
const result = execCmd(`apex:get:test --test-run-id ${testId} --code-coverage --detailed-coverage`, {
129+
ensureExitCode: 0,
130+
}).shellOutput.stdout;
131+
expect(result).to.include('=== Apex Code Coverage for Test Run 707');
132+
expect(result).to.include(/TEST NAME\w+CLASS BEING TESTED\w+OUTCOME\w+PERCENT\w+MESSAGE\w+RUNTIME (MS)/);
133+
});
134+
});
135+
136+
it('will create --output-dir', () => {
137+
const result = execCmd(`apex:get:test --output-dir testresults --code-coverage --test-run-id ${testId}`, {
138+
ensureExitCode: 0,
139+
}).shellOutput.stdout;
140+
expect(result).to.include('Test result files written to testresults');
141+
const outputDir = path.join(session.project.dir, 'testresults');
142+
expect(fs.statSync(outputDir).isDirectory()).to.be.true;
143+
expect(fs.readdirSync(outputDir)).length.to.equal(6);
144+
expect(fs.existsSync(path.join(outputDir, 'test-result-codecoverage.json'))).to.be.true;
145+
expect(fs.existsSync(path.join(outputDir, 'test-result.txt'))).to.be.true;
146+
expect(fs.existsSync(path.join(outputDir, 'test-run-id.txt'))).to.be.true;
147+
});
148+
});

0 commit comments

Comments
 (0)