Skip to content

Commit a3a14c6

Browse files
Merge pull request #143 from salesforcecli/wr/NUTs
test: add NUTs
2 parents 26ac1e6 + e6f7f37 commit a3a14c6

File tree

8 files changed

+1249
-298
lines changed

8 files changed

+1249
-298
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
windows-unit-tests:
1515
needs: linux-unit-tests
1616
uses: salesforcecli/github-workflows/.github/workflows/unitTestsWindows.yml@main
17-
# nuts:
18-
# needs: linux-unit-tests
19-
# uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main
20-
# secrets: inherit
21-
# strategy:
22-
# matrix:
23-
# os: [ubuntu-latest, windows-latest]
24-
# fail-fast: false
25-
# with:
26-
# os: ${{ matrix.os }}
17+
nuts:
18+
needs: linux-unit-tests
19+
uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main
20+
secrets: inherit
21+
strategy:
22+
matrix:
23+
os: [ubuntu-latest, windows-latest]
24+
fail-fast: false
25+
with:
26+
os: ${{ matrix.os }}

CHANGELOG.md

Lines changed: 76 additions & 179 deletions
Large diffs are not rendered by default.

command-snapshot.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
{
33
"command": "apex:get:log",
44
"plugin": "@salesforce/plugin-apex",
5-
"flags": ["api-version", "log-id", "loglevel", "number", "output-dir", "target-org"],
5+
"flags": ["api-version", "json", "log-id", "loglevel", "number", "output-dir", "target-org"],
66
"alias": ["force:apex:log:get"],
77
"flagChars": ["d", "i", "n", "o"],
88
"flagAliases": ["apiversion", "logid", "output-directory", "outputdir", "targetusername", "u"]
99
},
1010
{
1111
"command": "apex:get:test",
1212
"plugin": "@salesforce/plugin-apex",
13-
"flags": ["api-version", "code-coverage", "loglevel", "output-dir", "result-format", "target-org", "test-run-id"],
13+
"flags": [
14+
"api-version",
15+
"code-coverage",
16+
"json",
17+
"loglevel",
18+
"output-dir",
19+
"result-format",
20+
"target-org",
21+
"test-run-id"
22+
],
1423
"alias": ["force:apex:test:report"],
1524
"flagChars": ["c", "d", "i", "o", "r"],
1625
"flagAliases": [
@@ -27,15 +36,15 @@
2736
{
2837
"command": "apex:list:log",
2938
"plugin": "@salesforce/plugin-apex",
30-
"flags": ["api-version", "loglevel", "target-org"],
39+
"flags": ["api-version", "json", "loglevel", "target-org"],
3140
"alias": ["force:apex:log:list"],
3241
"flagChars": ["o"],
3342
"flagAliases": ["apiversion", "targetusername", "u"]
3443
},
3544
{
3645
"command": "apex:run",
3746
"plugin": "@salesforce/plugin-apex",
38-
"flags": ["api-version", "file", "loglevel", "target-org"],
47+
"flags": ["api-version", "file", "json", "loglevel", "target-org"],
3948
"alias": ["force:apex:execute"],
4049
"flagChars": ["f", "o"],
4150
"flagAliases": ["apexcodefile", "apiversion", "targetusername", "u"]
@@ -48,6 +57,7 @@
4857
"class-names",
4958
"code-coverage",
5059
"detailed-coverage",
60+
"json",
5161
"loglevel",
5262
"output-dir",
5363
"result-format",
@@ -77,7 +87,7 @@
7787
{
7888
"command": "apex:tail:log",
7989
"plugin": "@salesforce/plugin-apex",
80-
"flags": ["api-version", "color", "debug-level", "loglevel", "skip-trace-flag", "target-org"],
90+
"flags": ["api-version", "color", "debug-level", "json", "loglevel", "skip-trace-flag", "target-org"],
8191
"alias": ["force:apex:log:tail"],
8292
"flagChars": ["c", "d", "o", "s"],
8393
"flagAliases": ["apiversion", "debuglevel", "skiptraceflag", "targetusername", "u"]

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
"devDependencies": {
1717
"@oclif/plugin-command-snapshot": "^4.0.2",
1818
"@oclif/plugin-help": "^5",
19+
"@salesforce/cli-plugins-testkit": "^4.0.1",
1920
"@salesforce/dev-config": "^4.0.1",
2021
"@salesforce/dev-scripts": "^5.4.2",
2122
"@salesforce/plugin-command-reference": "^3.0.2",
23+
"@salesforce/plugin-deploy-retrieve": "^1.11.3",
2224
"@salesforce/prettier-config": "^0.0.3",
2325
"@salesforce/ts-sinon": "^1.4.8",
2426
"@salesforce/ts-types": "^2.0.3",
25-
"@swc/core": "^1.3.60",
27+
"@swc/core": "1.3.30",
2628
"@typescript-eslint/eslint-plugin": "^5.59.8",
2729
"@typescript-eslint/parser": "^5.59.7",
2830
"chai": "^4.3.7",
@@ -97,7 +99,8 @@
9799
"devPlugins": [
98100
"@oclif/plugin-help",
99101
"@oclif/plugin-command-snapshot",
100-
"@salesforce/plugin-command-reference"
102+
"@salesforce/plugin-command-reference",
103+
"@salesforce/plugin-deploy-retrieve"
101104
]
102105
},
103106
"repository": "salesforcecli/plugin-apex",
@@ -228,4 +231,4 @@
228231
"output": []
229232
}
230233
}
231-
}
234+
}

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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 { config, expect } from 'chai';
11+
import { TestRunIdResult } from '@salesforce/apex-node';
12+
import { RunResult } from '../../../../src/reporters';
13+
config.truncateThreshold = 0;
14+
15+
describe('apex get test', () => {
16+
let session: TestSession;
17+
let testId: string | undefined;
18+
before(async () => {
19+
session = await TestSession.create({
20+
project: {
21+
gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
22+
},
23+
devhubAuthStrategy: 'AUTO',
24+
scratchOrgs: [
25+
{
26+
config: path.join('config', 'project-scratch-def.json'),
27+
setDefault: true,
28+
alias: 'org',
29+
},
30+
],
31+
});
32+
33+
execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0 });
34+
testId = execCmd<TestRunIdResult>('apex:run:test --json', {
35+
ensureExitCode: 0,
36+
}).jsonOutput?.result.testRunId.trim();
37+
expect(testId).to.be.a('string');
38+
});
39+
40+
after(async () => {
41+
await session?.zip(undefined, 'artifacts');
42+
await session?.clean();
43+
});
44+
45+
describe('--result-format', () => {
46+
it('will print tap format', async () => {
47+
const result = execCmd(`apex:get:test --result-format tap --test-run-id ${testId}`, { ensureExitCode: 0 })
48+
.shellOutput.stdout;
49+
expect(result).to.include('1..1');
50+
expect(result).to.include('ok 1');
51+
expect(result).to.include('--result-format <format>" to retrieve test results in a different format.');
52+
});
53+
it('will print junit format', async () => {
54+
const result = execCmd(`apex:get:test --result-format junit --test-run-id ${testId}`, { ensureExitCode: 0 })
55+
.shellOutput.stdout;
56+
expect(result).to.include('<?xml version="1.0" encoding="UTF-8"?>');
57+
expect(result).to.include('<testsuites>');
58+
expect(result).to.include('<testsuite name="force.apex" timestamp="');
59+
expect(result).to.include(
60+
'<testcase name="testGetPicturesWithResults" classname="TestPropertyController" time="'
61+
);
62+
});
63+
});
64+
65+
it('will run report on test', async () => {
66+
const result = execCmd(`apex:get:test --test-run-id ${testId}`, { ensureExitCode: 0 }).shellOutput.stdout;
67+
expect(result).to.include('=== Test Summary');
68+
expect(result).to.include('=== Test Results');
69+
});
70+
71+
it('will get tests --json', async () => {
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);
75+
expect(result?.summary.outcome).to.equal('Passed');
76+
expect(result?.summary.testsRan).to.equal(11);
77+
expect(result?.summary).to.have.all.keys(
78+
'outcome',
79+
'testsRan',
80+
'passing',
81+
'failing',
82+
'skipped',
83+
'passRate',
84+
'failRate',
85+
'testStartTime',
86+
'testExecutionTime',
87+
'testTotalTime',
88+
'commandTime',
89+
'hostname',
90+
'orgId',
91+
'username',
92+
'testRunId',
93+
'userId'
94+
);
95+
expect(result?.tests[0]).to.have.all.keys(
96+
'Id',
97+
'QueueItemId',
98+
'StackTrace',
99+
'Message',
100+
'AsyncApexJobId',
101+
'MethodName',
102+
'Outcome',
103+
'ApexClass',
104+
'RunTime',
105+
'FullName'
106+
);
107+
});
108+
109+
describe('--code-coverage', () => {
110+
it('will run default tests sync with --code-coverage', async () => {
111+
const result = execCmd(`apex:get:test --test-run-id ${testId} --code-coverage`, { ensureExitCode: 0 }).shellOutput
112+
.stdout;
113+
expect(result).to.include('=== Apex Code Coverage by Class');
114+
expect(result).to.match(/TEST NAME\s+OUTCOME\s+MESSAGE\s+RUNTIME \(MS\)/);
115+
});
116+
it('will run default tests sync with --code-coverage --json', async () => {
117+
const result = execCmd<RunResult>(`apex:get:test --test-run-id ${testId} --code-coverage --json`, {
118+
ensureExitCode: 0,
119+
}).jsonOutput?.result;
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'
139+
);
140+
});
141+
});
142+
143+
it('will create --output-dir', () => {
144+
const result = execCmd(`apex:get:test --output-dir testresults --code-coverage --test-run-id ${testId}`, {
145+
ensureExitCode: 0,
146+
}).shellOutput.stdout;
147+
expect(result).to.include('Test result files written to testresults');
148+
const outputDir = path.join(session.project.dir, 'testresults');
149+
expect(fs.statSync(outputDir).isDirectory()).to.be.true;
150+
expect(fs.readdirSync(outputDir).length).to.equal(6);
151+
expect(fs.existsSync(path.join(outputDir, 'test-result-codecoverage.json'))).to.be.true;
152+
expect(fs.existsSync(path.join(outputDir, 'test-result.txt'))).to.be.true;
153+
expect(fs.existsSync(path.join(outputDir, 'test-run-id.txt'))).to.be.true;
154+
});
155+
});

0 commit comments

Comments
 (0)