sf-flow-coverage 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +275 -2
- package/lib/commands/flowcov/gate.d.ts +17 -0
- package/lib/commands/flowcov/gate.js +82 -0
- package/lib/commands/flowcov/gate.js.map +1 -0
- package/lib/commands/flowcov/readiness.d.ts +17 -0
- package/lib/commands/flowcov/readiness.js +87 -0
- package/lib/commands/flowcov/readiness.js.map +1 -0
- package/lib/commands/flowcov/scaffold.d.ts +18 -0
- package/lib/commands/flowcov/scaffold.js +76 -0
- package/lib/commands/flowcov/scaffold.js.map +1 -0
- package/lib/core/apexTemplate.d.ts +18 -0
- package/lib/core/apexTemplate.js +310 -0
- package/lib/core/apexTemplate.js.map +1 -0
- package/lib/core/flowTypes.d.ts +16 -0
- package/lib/core/flowTypes.js +29 -0
- package/lib/core/flowTypes.js.map +1 -0
- package/lib/core/flowXml.d.ts +8 -0
- package/lib/core/flowXml.js +97 -0
- package/lib/core/flowXml.js.map +1 -0
- package/lib/core/gate.d.ts +20 -0
- package/lib/core/gate.js +92 -0
- package/lib/core/gate.js.map +1 -0
- package/lib/core/git.d.ts +13 -0
- package/lib/core/git.js +81 -0
- package/lib/core/git.js.map +1 -0
- package/lib/core/orgCoverageSource.d.ts +17 -0
- package/lib/core/orgCoverageSource.js +108 -0
- package/lib/core/orgCoverageSource.js.map +1 -0
- package/lib/core/projectFiles.d.ts +9 -0
- package/lib/core/projectFiles.js +48 -0
- package/lib/core/projectFiles.js.map +1 -0
- package/lib/core/readiness.d.ts +12 -0
- package/lib/core/readiness.js +37 -0
- package/lib/core/readiness.js.map +1 -0
- package/lib/core/requiredFields.d.ts +27 -0
- package/lib/core/requiredFields.js +75 -0
- package/lib/core/requiredFields.js.map +1 -0
- package/lib/core/scaffold.d.ts +18 -0
- package/lib/core/scaffold.js +79 -0
- package/lib/core/scaffold.js.map +1 -0
- package/lib/core/toolingQuery.d.ts +7 -0
- package/lib/core/toolingQuery.js +16 -0
- package/lib/core/toolingQuery.js.map +1 -0
- package/lib/core/types.d.ts +117 -0
- package/lib/core/types.js +2 -0
- package/lib/core/types.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/messages/flowcov.gate.md +49 -0
- package/messages/flowcov.readiness.md +39 -0
- package/messages/flowcov.scaffold.md +59 -0
- package/oclif.manifest.json +317 -0
- package/package.json +311 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matthew Carvin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,276 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sf-flow-coverage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/sf-flow-coverage)
|
|
4
|
+
[](https://npmjs.org/package/sf-flow-coverage)
|
|
5
|
+
[](https://raw.githubusercontent.com/mcarvin8/sf-flow-coverage/refs/heads/main/LICENSE.md)
|
|
6
|
+
|
|
7
|
+
Get your Salesforce org ready to deploy Flows as active.
|
|
8
|
+
|
|
9
|
+
Most production orgs deploy Flows as inactive and activate them by hand, because turning on **Deploy processes and flows as active** requires 75% Apex test coverage across every active autolaunched Flow and process, and few teams know how far they are from that bar. `sf-flow-coverage` shows you the gap and helps you close it: it reports your org-wide Flow coverage and which active Flows have none, generates starter Apex tests for uncovered Flows, and adds a per-Flow coverage gate to pull requests so you stay above the threshold once the setting is on. Salesforce only checks that the org-wide total stays above 75%, so a single Flow with no tests can still go live.
|
|
10
|
+
|
|
11
|
+
<!-- TABLE OF CONTENTS -->
|
|
12
|
+
<details>
|
|
13
|
+
<summary>Table of Contents</summary>
|
|
14
|
+
|
|
15
|
+
- [Install](#install)
|
|
16
|
+
- [Quick start](#quick-start)
|
|
17
|
+
- [How coverage is measured](#how-coverage-is-measured)
|
|
18
|
+
- [Readiness report](#readiness-report)
|
|
19
|
+
- [Pull request gate](#pull-request-gate)
|
|
20
|
+
- [Test scaffolding](#test-scaffolding)
|
|
21
|
+
- [CLI Command Reference](#cli-command-reference)
|
|
22
|
+
- [Programmatic API](#programmatic-api)
|
|
23
|
+
- [Issues](#issues)
|
|
24
|
+
- [License](#license)
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
Requires the [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli) and Node.js 22.19 or later.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
sf plugins install sf-flow-coverage@x.y.z
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 1. Run Apex tests so the org's Flow coverage is current
|
|
41
|
+
sf apex run test --test-level RunLocalTests --wait 60 --target-org prod
|
|
42
|
+
|
|
43
|
+
# 2. See how far you are from 75%, and which Flows to cover first
|
|
44
|
+
sf flowcov readiness --target-org prod --since "6 months ago"
|
|
45
|
+
|
|
46
|
+
# 3. Generate starter Apex tests for every uncovered Flow
|
|
47
|
+
sf flowcov scaffold --uncovered --target-org prod
|
|
48
|
+
|
|
49
|
+
# 4. In CI, after deploying the branch and running tests, require coverage for each changed Flow
|
|
50
|
+
sf flowcov gate --target-org ci-sandbox --from origin/main --to HEAD
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## How coverage is measured
|
|
54
|
+
|
|
55
|
+
- **What counts.** Active Flows with the process types Salesforce counts toward deploy-as-active: autolaunched Flows (including record-triggered, platform event and schedule-triggered Flows) and Process Builder processes. Screen Flows don't count.
|
|
56
|
+
- **Where it comes from.** Salesforce records which Flow versions each Apex test runs in the Tooling API `FlowTestCoverage` object when Apex tests run in the org. All three commands read it, so run your Apex tests before using them. Check-only deployments (`sf project deploy validate`) run tests but don't record Flow coverage, so use `sf apex run test` or a real deployment.
|
|
57
|
+
- **Only Apex counts.** Flow Builder tests and Flow Test Mode (Winter '27) don't count toward the 75% requirement, so `scaffold` generates Apex tests, not Flow test metadata. The coverage source is pluggable, so if Salesforce starts counting Test Mode coverage it can be added without changing the commands.
|
|
58
|
+
|
|
59
|
+
## Readiness report
|
|
60
|
+
|
|
61
|
+
`sf flowcov readiness` reports the org-wide percentage against the threshold and how many more Flows need a test to reach it. Uncovered Flows are ranked by how often their source file changed in git (run it from your Salesforce DX repo, or pass `--project-dir`), so the Flows most likely to be deployed next are at the top. Covered Flows list the Apex test methods that run them and their element coverage.
|
|
62
|
+
|
|
63
|
+
Pass `--fail-if-not-ready` to exit with code 1 below the threshold.
|
|
64
|
+
|
|
65
|
+
## Pull request gate
|
|
66
|
+
|
|
67
|
+
`sf flowcov gate` checks every active autolaunched Flow or process that changed between `--from` and `--to` and fails if no Apex test runs it. Add `--min-element-coverage` to also require a share of each Flow's elements to be covered. Flows that don't count (screen Flows, drafts) are skipped.
|
|
68
|
+
|
|
69
|
+
Coverage is read from the target org, so in CI:
|
|
70
|
+
|
|
71
|
+
1. Deploy the branch to a sandbox or scratch org.
|
|
72
|
+
2. Run Apex tests there.
|
|
73
|
+
3. Run the gate against that org.
|
|
74
|
+
|
|
75
|
+
The gate checks the Flow's active version in the org (or its latest version if none is active), and prints that version in the result.
|
|
76
|
+
|
|
77
|
+
## Test scaffolding
|
|
78
|
+
|
|
79
|
+
`sf flowcov scaffold` reads each Flow's `.flow-meta.xml` from your project and writes `<Flow>_FlowTest.cls` to your default package directory's `main/default/classes` folder (or `--output-dir`).
|
|
80
|
+
|
|
81
|
+
| Flow type | Generated test |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| Record-triggered (create, update, delete) | Builds a record of the trigger object, sets entry criteria that are simple `EqualTo` filters, and inserts, updates, or deletes it. Create-and-update Flows get one test method for each. |
|
|
84
|
+
| Autolaunched (no trigger) | Starts the Flow with `Flow.Interview.createInterview`, with a placeholder for every input variable and a read of every output variable. |
|
|
85
|
+
| Platform event | Publishes the event and delivers it with `Test.getEventBus().deliver()`. |
|
|
86
|
+
| Schedule-triggered | Starts the Flow directly, since Apex tests can't fire the schedule. |
|
|
87
|
+
| Process Builder | A placeholder test to fill in. |
|
|
88
|
+
|
|
89
|
+
With a target org (`--target-org` or your default org), the command describes each object the test creates and fills in its required fields: text, numbers, dates, and the default picklist value. Lookups it can't make up are left as TODOs. Without an org, only common standard objects (Account, Contact, Opportunity, and so on) get required fields.
|
|
90
|
+
|
|
91
|
+
Every generated test has TODOs for anything it couldn't fill in, entry criteria it couldn't set (formulas, cross-object fields), and real assertions. Expect some generated tests to fail until you fill these in: a failure from the Flow's own validation still shows the Flow ran. Existing classes aren't overwritten unless you pass `--force`.
|
|
92
|
+
|
|
93
|
+
## CLI Command Reference
|
|
94
|
+
|
|
95
|
+
<!-- commands -->
|
|
96
|
+
* [`sf flowcov gate`](#sf-flowcov-gate)
|
|
97
|
+
* [`sf flowcov readiness`](#sf-flowcov-readiness)
|
|
98
|
+
* [`sf flowcov scaffold`](#sf-flowcov-scaffold)
|
|
99
|
+
|
|
100
|
+
## `sf flowcov gate`
|
|
101
|
+
|
|
102
|
+
Require Apex test coverage for every Flow a pull request changes.
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
USAGE
|
|
106
|
+
$ sf flowcov gate -o <value> [--json] [--flags-dir <value>] [--api-version <value>] [--from <value> | --flow
|
|
107
|
+
<value>...] [--to <value>] [-d <value>] [--min-element-coverage <value>]
|
|
108
|
+
|
|
109
|
+
FLAGS
|
|
110
|
+
-d, --project-dir=<value> [default: .] Git repository to read changed Flows from.
|
|
111
|
+
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
|
|
112
|
+
configuration variable is already set.
|
|
113
|
+
--api-version=<value> Override the api version used for api requests made by this command
|
|
114
|
+
--flow=<value>... Flow API name to check. Use instead of --from to skip git.
|
|
115
|
+
--from=<value> Git ref the pull request merges into (the gate compares from the merge base of
|
|
116
|
+
this ref).
|
|
117
|
+
--min-element-coverage=<value> Minimum percentage of each Flow's elements that tests must run.
|
|
118
|
+
--to=<value> [default: HEAD] Git ref with the changes.
|
|
119
|
+
|
|
120
|
+
GLOBAL FLAGS
|
|
121
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
122
|
+
--json Format output as json.
|
|
123
|
+
|
|
124
|
+
DESCRIPTION
|
|
125
|
+
Require Apex test coverage for every Flow a pull request changes.
|
|
126
|
+
|
|
127
|
+
Salesforce only checks that the org-wide total stays at or above 75%, so a single Flow with no tests can still be
|
|
128
|
+
deployed as active. This gate checks each changed Flow on its own: every active autolaunched Flow or process changed
|
|
129
|
+
between --from and --to must be run by at least one Apex test, and optionally reach a minimum element coverage.
|
|
130
|
+
|
|
131
|
+
Coverage is read from FlowTestCoverage in the target org. Deploy the branch to the target org and run Apex tests there
|
|
132
|
+
before running the gate. Flows that don't count toward deploy-as-active (screen Flows, inactive Flows) are skipped.
|
|
133
|
+
|
|
134
|
+
Exits with code 1 when any Flow fails.
|
|
135
|
+
|
|
136
|
+
EXAMPLES
|
|
137
|
+
Check the Flows changed in a pull request:
|
|
138
|
+
|
|
139
|
+
$ sf flowcov gate --target-org ci-sandbox --from origin/main --to HEAD
|
|
140
|
+
|
|
141
|
+
Also require 60% element coverage per Flow:
|
|
142
|
+
|
|
143
|
+
$ sf flowcov gate --target-org ci-sandbox --from origin/main --min-element-coverage 60
|
|
144
|
+
|
|
145
|
+
Check named Flows without git:
|
|
146
|
+
|
|
147
|
+
$ sf flowcov gate --target-org ci-sandbox --flow Account_After_Save --flow Close_Cases
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
_See code: [src/commands/flowcov/gate.ts](https://github.com/mcarvin8/sf-flow-coverage/blob/main/src/commands/flowcov/gate.ts)_
|
|
151
|
+
|
|
152
|
+
## `sf flowcov readiness`
|
|
153
|
+
|
|
154
|
+
Report how close the org is to the coverage needed to deploy Flows as active.
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
USAGE
|
|
158
|
+
$ sf flowcov readiness -o <value> [--json] [--flags-dir <value>] [--api-version <value>] [-d <value>] [--since
|
|
159
|
+
<value>] [--threshold <value>] [--fail-if-not-ready]
|
|
160
|
+
|
|
161
|
+
FLAGS
|
|
162
|
+
-d, --project-dir=<value> [default: .] Git repository used to rank uncovered Flows by how often they change.
|
|
163
|
+
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
|
|
164
|
+
configuration variable is already set.
|
|
165
|
+
--api-version=<value> Override the api version used for api requests made by this command
|
|
166
|
+
--fail-if-not-ready Exit with code 1 when the org is below the threshold.
|
|
167
|
+
--since=<value> Only count commits after this date (any value `git log --since` accepts).
|
|
168
|
+
--threshold=<value> [default: 75] Coverage percentage the org must reach.
|
|
169
|
+
|
|
170
|
+
GLOBAL FLAGS
|
|
171
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
172
|
+
--json Format output as json.
|
|
173
|
+
|
|
174
|
+
DESCRIPTION
|
|
175
|
+
Report how close the org is to the coverage needed to deploy Flows as active.
|
|
176
|
+
|
|
177
|
+
Salesforce requires 75% of active autolaunched Flows and processes to be run by at least one Apex test before you can
|
|
178
|
+
turn on "Deploy processes and flows as active". This command reads FlowTestCoverage from the target org, reports the
|
|
179
|
+
org-wide percentage against the threshold, and lists the uncovered Flows (ranked by how often they change in git) and
|
|
180
|
+
the Apex tests that already run each covered Flow.
|
|
181
|
+
|
|
182
|
+
FlowTestCoverage is filled in when Apex tests run in the org. Run your Apex tests first (for example, `sf apex run
|
|
183
|
+
test --test-level RunLocalTests --wait 60`) so the report is current.
|
|
184
|
+
|
|
185
|
+
EXAMPLES
|
|
186
|
+
Report readiness for the default org:
|
|
187
|
+
|
|
188
|
+
$ sf flowcov readiness
|
|
189
|
+
|
|
190
|
+
Rank uncovered Flows by changes in the last 6 months:
|
|
191
|
+
|
|
192
|
+
$ sf flowcov readiness --target-org prod --since "6 months ago"
|
|
193
|
+
|
|
194
|
+
Fail a CI job unless the org is at or above 75%:
|
|
195
|
+
|
|
196
|
+
$ sf flowcov readiness --target-org prod --fail-if-not-ready
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
_See code: [src/commands/flowcov/readiness.ts](https://github.com/mcarvin8/sf-flow-coverage/blob/main/src/commands/flowcov/readiness.ts)_
|
|
200
|
+
|
|
201
|
+
## `sf flowcov scaffold`
|
|
202
|
+
|
|
203
|
+
Generate starter Apex tests for Flows.
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
USAGE
|
|
207
|
+
$ sf flowcov scaffold [--json] [--flags-dir <value>] [-f <value>...] [--uncovered] [-o <value>] [--api-version
|
|
208
|
+
<value>] [-d <value>] [-r <value>] [--force] [--dry-run]
|
|
209
|
+
|
|
210
|
+
FLAGS
|
|
211
|
+
-d, --project-dir=<value> [default: .] Salesforce DX project to read Flow metadata from.
|
|
212
|
+
-f, --flow=<value>... Flow API name to generate a test for.
|
|
213
|
+
-o, --target-org=<value> Org used to find uncovered Flows (--uncovered) and to describe objects so generated records
|
|
214
|
+
set their required fields.
|
|
215
|
+
-r, --output-dir=<value> Directory to write test classes to. Defaults to the default package directory's
|
|
216
|
+
main/default/classes.
|
|
217
|
+
--api-version=<value> Override the api version used for api requests made by this command
|
|
218
|
+
--dry-run Show what would be generated without writing files.
|
|
219
|
+
--force Overwrite test classes that already exist.
|
|
220
|
+
--uncovered Generate tests for every active Flow in the target org that no Apex test runs.
|
|
221
|
+
|
|
222
|
+
GLOBAL FLAGS
|
|
223
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
224
|
+
--json Format output as json.
|
|
225
|
+
|
|
226
|
+
DESCRIPTION
|
|
227
|
+
Generate starter Apex tests for Flows.
|
|
228
|
+
|
|
229
|
+
Reads each Flow's metadata file from the project and writes an Apex test class named `<Flow>_FlowTest` that runs it:
|
|
230
|
+
record-triggered Flows get a record built from the trigger object and entry criteria, autolaunched Flows are started
|
|
231
|
+
with Flow.Interview and their input variables, and platform event Flows publish the event. When a target org is
|
|
232
|
+
available (--target-org or a default org), the command describes each object the test creates and fills in its
|
|
233
|
+
required fields. The generated tests have TODOs for anything it can't fill in and placeholder assertions.
|
|
234
|
+
|
|
235
|
+
Only Apex tests count toward deploying Flows as active, so this command generates Apex, not Flow Builder tests.
|
|
236
|
+
|
|
237
|
+
EXAMPLES
|
|
238
|
+
Generate a test for one Flow:
|
|
239
|
+
|
|
240
|
+
$ sf flowcov scaffold --flow Account_After_Save
|
|
241
|
+
|
|
242
|
+
Generate tests for every active Flow the org has no coverage for:
|
|
243
|
+
|
|
244
|
+
$ sf flowcov scaffold --uncovered --target-org prod
|
|
245
|
+
|
|
246
|
+
Preview without writing files:
|
|
247
|
+
|
|
248
|
+
$ sf flowcov scaffold --flow Account_After_Save --dry-run
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
_See code: [src/commands/flowcov/scaffold.ts](https://github.com/mcarvin8/sf-flow-coverage/blob/main/src/commands/flowcov/scaffold.ts)_
|
|
252
|
+
<!-- commandsstop -->
|
|
253
|
+
|
|
254
|
+
## Programmatic API
|
|
255
|
+
|
|
256
|
+
The core logic is exported for use in your own scripts:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { OrgCoverageSource, buildReadinessReport, toolingQuery } from 'sf-flow-coverage';
|
|
260
|
+
import { Org } from '@salesforce/core';
|
|
261
|
+
|
|
262
|
+
const org = await Org.create({ aliasOrUsername: 'prod' });
|
|
263
|
+
const source = new OrgCoverageSource(toolingQuery(org.getConnection()));
|
|
264
|
+
const report = await buildReadinessReport({ source });
|
|
265
|
+
console.log(`${report.coveragePercent}% of active Flows are covered`);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Issues
|
|
269
|
+
|
|
270
|
+
Bugs or feature requests? Submit an [issue](https://github.com/mcarvin8/sf-flow-coverage/issues).
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
[MIT](LICENSE.md)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import type { GateResult } from '../../core/types.js';
|
|
3
|
+
export default class FlowcovGate extends SfCommand<GateResult> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {
|
|
8
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
from: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
to: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
flow: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'project-dir': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'min-element-coverage': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<GateResult>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Messages, SfError } from '@salesforce/core';
|
|
2
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { collectChangedFlows, evaluateGate } from '../../core/gate.js';
|
|
4
|
+
import { OrgCoverageSource } from '../../core/orgCoverageSource.js';
|
|
5
|
+
import { toolingQuery } from '../../core/toolingQuery.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('sf-flow-coverage', 'flowcov.gate');
|
|
8
|
+
export default class FlowcovGate extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
'target-org': Flags.requiredOrg(),
|
|
14
|
+
'api-version': Flags.orgApiVersion(),
|
|
15
|
+
from: Flags.string({
|
|
16
|
+
summary: messages.getMessage('flags.from.summary'),
|
|
17
|
+
exclusive: ['flow'],
|
|
18
|
+
}),
|
|
19
|
+
to: Flags.string({
|
|
20
|
+
summary: messages.getMessage('flags.to.summary'),
|
|
21
|
+
default: 'HEAD',
|
|
22
|
+
}),
|
|
23
|
+
flow: Flags.string({
|
|
24
|
+
summary: messages.getMessage('flags.flow.summary'),
|
|
25
|
+
multiple: true,
|
|
26
|
+
exclusive: ['from'],
|
|
27
|
+
}),
|
|
28
|
+
'project-dir': Flags.directory({
|
|
29
|
+
summary: messages.getMessage('flags.project-dir.summary'),
|
|
30
|
+
char: 'd',
|
|
31
|
+
default: '.',
|
|
32
|
+
exists: true,
|
|
33
|
+
}),
|
|
34
|
+
'min-element-coverage': Flags.integer({
|
|
35
|
+
summary: messages.getMessage('flags.min-element-coverage.summary'),
|
|
36
|
+
default: 0,
|
|
37
|
+
min: 0,
|
|
38
|
+
max: 100,
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
async run() {
|
|
42
|
+
const { flags } = await this.parse(FlowcovGate);
|
|
43
|
+
let candidates;
|
|
44
|
+
if (flags.flow) {
|
|
45
|
+
candidates = flags.flow.map((flowName) => ({ flowName }));
|
|
46
|
+
}
|
|
47
|
+
else if (flags.from) {
|
|
48
|
+
candidates = await collectChangedFlows(flags['project-dir'], flags.from, flags.to);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new SfError(messages.getMessage('error.noInput'));
|
|
52
|
+
}
|
|
53
|
+
if (candidates.length === 0) {
|
|
54
|
+
this.log('No Flows changed. Nothing to check.');
|
|
55
|
+
return { passed: true, minElementCoverage: flags['min-element-coverage'], flows: [] };
|
|
56
|
+
}
|
|
57
|
+
const connection = flags['target-org'].getConnection(flags['api-version']);
|
|
58
|
+
const result = await evaluateGate({
|
|
59
|
+
source: new OrgCoverageSource(toolingQuery(connection)),
|
|
60
|
+
candidates,
|
|
61
|
+
minElementCoverage: flags['min-element-coverage'],
|
|
62
|
+
});
|
|
63
|
+
this.table({
|
|
64
|
+
data: result.flows.map((f) => ({
|
|
65
|
+
Flow: f.flowName,
|
|
66
|
+
Result: f.status.toUpperCase(),
|
|
67
|
+
'Element Coverage': f.elementCoveragePercent === undefined ? '' : `${f.elementCoveragePercent}%`,
|
|
68
|
+
Reason: f.reason,
|
|
69
|
+
})),
|
|
70
|
+
});
|
|
71
|
+
if (result.passed) {
|
|
72
|
+
this.logSuccess(`Flow coverage gate passed for ${result.flows.length} Flow(s).`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const failed = result.flows.filter((f) => f.status === 'fail').length;
|
|
76
|
+
this.warn(`Flow coverage gate failed: ${failed} Flow(s) need Apex test coverage.`);
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../../../src/commands/flowcov/gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,QAAQ,CAAC,kCAAkC,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;AAE3E,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAAqB;IACrD,MAAM,CAAmB,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAClE,MAAM,CAAmB,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1E,MAAM,CAAmB,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAErE,MAAM,CAAmB,KAAK,GAAG;QACtC,YAAY,EAAE,KAAK,CAAC,WAAW,EAAE;QACjC,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE;QACpC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;YACjB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,oBAAoB,CAAC;YA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AAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;YACtE,IAAI,CAAC,IAAI,CAAC,8BAA8B,MAAM,mCAAmC,CAAC,CAAC;YACnF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import type { ReadinessResult } from '../../core/types.js';
|
|
3
|
+
export default class FlowcovReadiness extends SfCommand<ReadinessResult> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {
|
|
8
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'project-dir': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
since: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
threshold: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'fail-if-not-ready': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<ReadinessResult>;
|
|
16
|
+
private logReport;
|
|
17
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Messages } from '@salesforce/core';
|
|
2
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { DEFAULT_THRESHOLD } from '../../core/flowTypes.js';
|
|
4
|
+
import { getFlowChurn } from '../../core/git.js';
|
|
5
|
+
import { OrgCoverageSource } from '../../core/orgCoverageSource.js';
|
|
6
|
+
import { buildReadinessReport } from '../../core/readiness.js';
|
|
7
|
+
import { toolingQuery } from '../../core/toolingQuery.js';
|
|
8
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
9
|
+
const messages = Messages.loadMessages('sf-flow-coverage', 'flowcov.readiness');
|
|
10
|
+
export default class FlowcovReadiness extends SfCommand {
|
|
11
|
+
static summary = messages.getMessage('summary');
|
|
12
|
+
static description = messages.getMessage('description');
|
|
13
|
+
static examples = messages.getMessages('examples');
|
|
14
|
+
static flags = {
|
|
15
|
+
'target-org': Flags.requiredOrg(),
|
|
16
|
+
'api-version': Flags.orgApiVersion(),
|
|
17
|
+
'project-dir': Flags.directory({
|
|
18
|
+
summary: messages.getMessage('flags.project-dir.summary'),
|
|
19
|
+
char: 'd',
|
|
20
|
+
default: '.',
|
|
21
|
+
exists: true,
|
|
22
|
+
}),
|
|
23
|
+
since: Flags.string({
|
|
24
|
+
summary: messages.getMessage('flags.since.summary'),
|
|
25
|
+
}),
|
|
26
|
+
threshold: Flags.integer({
|
|
27
|
+
summary: messages.getMessage('flags.threshold.summary'),
|
|
28
|
+
default: DEFAULT_THRESHOLD,
|
|
29
|
+
min: 0,
|
|
30
|
+
max: 100,
|
|
31
|
+
}),
|
|
32
|
+
'fail-if-not-ready': Flags.boolean({
|
|
33
|
+
summary: messages.getMessage('flags.fail-if-not-ready.summary'),
|
|
34
|
+
default: false,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
async run() {
|
|
38
|
+
const { flags } = await this.parse(FlowcovReadiness);
|
|
39
|
+
const connection = flags['target-org'].getConnection(flags['api-version']);
|
|
40
|
+
this.spinner.start('Reading Flow coverage');
|
|
41
|
+
const churn = await getFlowChurn(flags['project-dir'], flags.since);
|
|
42
|
+
const result = await buildReadinessReport({
|
|
43
|
+
source: new OrgCoverageSource(toolingQuery(connection)),
|
|
44
|
+
churn,
|
|
45
|
+
threshold: flags.threshold,
|
|
46
|
+
});
|
|
47
|
+
this.spinner.stop();
|
|
48
|
+
this.logReport(result);
|
|
49
|
+
if (flags['fail-if-not-ready'] && !result.ready)
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
logReport(result) {
|
|
54
|
+
this.log(`Flow coverage: ${result.coveragePercent}% (${result.coveredFlows} of ${result.totalFlows} active Flows and processes have a test). Threshold: ${result.threshold}%.`);
|
|
55
|
+
if (result.ready) {
|
|
56
|
+
this.logSuccess('Ready: the org meets the coverage needed to deploy Flows as active.');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.warn(`Not ready: add Apex tests for ${result.flowsNeeded} more Flow(s) to reach ${result.threshold}%.`);
|
|
60
|
+
}
|
|
61
|
+
const showChanges = result.flows.some((f) => f.changes !== undefined);
|
|
62
|
+
const uncovered = result.flows.filter((f) => !f.covered);
|
|
63
|
+
if (uncovered.length > 0) {
|
|
64
|
+
this.table({
|
|
65
|
+
title: 'Uncovered Flows',
|
|
66
|
+
data: uncovered.map((f) => ({
|
|
67
|
+
Flow: f.flowName,
|
|
68
|
+
Type: f.processType,
|
|
69
|
+
Version: f.versionNumber ?? '',
|
|
70
|
+
...(showChanges ? { Changes: f.changes ?? 0 } : {}),
|
|
71
|
+
})),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const covered = result.flows.filter((f) => f.covered);
|
|
75
|
+
if (covered.length > 0) {
|
|
76
|
+
this.table({
|
|
77
|
+
title: 'Covered Flows',
|
|
78
|
+
data: covered.map((f) => ({
|
|
79
|
+
Flow: f.flowName,
|
|
80
|
+
'Element Coverage': `${f.elementCoveragePercent}%`,
|
|
81
|
+
Tests: [...new Set(f.tests.map((t) => `${t.className}.${t.methodName}`))].join(', '),
|
|
82
|
+
})),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=readiness.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AC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC;gBACT,KAAK,EAAE,eAAe;gBACtB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACxB,IAAI,EAAE,CAAC,CAAC,QAAQ;oBAChB,kBAAkB,EAAE,GAAG,CAAC,CAAC,sBAAsB,GAAG;oBAClD,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBACrF,CAAC,CAAC;aACJ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import type { ScaffoldResult } from '../../core/types.js';
|
|
3
|
+
export default class FlowcovScaffold extends SfCommand<ScaffoldResult> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {
|
|
8
|
+
flow: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
uncovered: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'project-dir': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<ScaffoldResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Messages, SfError } from '@salesforce/core';
|
|
2
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { OrgCoverageSource } from '../../core/orgCoverageSource.js';
|
|
4
|
+
import { scaffoldTests } from '../../core/scaffold.js';
|
|
5
|
+
import { describeObject, toolingQuery } from '../../core/toolingQuery.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('sf-flow-coverage', 'flowcov.scaffold');
|
|
8
|
+
export default class FlowcovScaffold extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
flow: Flags.string({
|
|
14
|
+
summary: messages.getMessage('flags.flow.summary'),
|
|
15
|
+
char: 'f',
|
|
16
|
+
multiple: true,
|
|
17
|
+
}),
|
|
18
|
+
uncovered: Flags.boolean({
|
|
19
|
+
summary: messages.getMessage('flags.uncovered.summary'),
|
|
20
|
+
default: false,
|
|
21
|
+
}),
|
|
22
|
+
'target-org': Flags.optionalOrg({ summary: messages.getMessage('flags.target-org.summary') }),
|
|
23
|
+
'api-version': Flags.orgApiVersion(),
|
|
24
|
+
'project-dir': Flags.directory({
|
|
25
|
+
summary: messages.getMessage('flags.project-dir.summary'),
|
|
26
|
+
char: 'd',
|
|
27
|
+
default: '.',
|
|
28
|
+
exists: true,
|
|
29
|
+
}),
|
|
30
|
+
'output-dir': Flags.directory({
|
|
31
|
+
summary: messages.getMessage('flags.output-dir.summary'),
|
|
32
|
+
char: 'r',
|
|
33
|
+
}),
|
|
34
|
+
force: Flags.boolean({
|
|
35
|
+
summary: messages.getMessage('flags.force.summary'),
|
|
36
|
+
default: false,
|
|
37
|
+
}),
|
|
38
|
+
'dry-run': Flags.boolean({
|
|
39
|
+
summary: messages.getMessage('flags.dry-run.summary'),
|
|
40
|
+
default: false,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
async run() {
|
|
44
|
+
const { flags } = await this.parse(FlowcovScaffold);
|
|
45
|
+
const flowNames = [...(flags.flow ?? [])];
|
|
46
|
+
const connection = flags['target-org']?.getConnection(flags['api-version']);
|
|
47
|
+
if (flags.uncovered) {
|
|
48
|
+
if (!connection)
|
|
49
|
+
throw new SfError(messages.getMessage('error.uncoveredNeedsOrg'));
|
|
50
|
+
const source = new OrgCoverageSource(toolingQuery(connection));
|
|
51
|
+
const flows = await source.listActiveCountedFlows();
|
|
52
|
+
// Managed (namespaced) Flows are not in the project, so only local names are useful.
|
|
53
|
+
flowNames.push(...flows.filter((f) => !f.covered && !f.flowName.includes('__')).map((f) => f.flowName));
|
|
54
|
+
}
|
|
55
|
+
else if (flowNames.length === 0) {
|
|
56
|
+
throw new SfError(messages.getMessage('error.noInput'));
|
|
57
|
+
}
|
|
58
|
+
const result = await scaffoldTests({
|
|
59
|
+
flowNames,
|
|
60
|
+
projectDir: flags['project-dir'],
|
|
61
|
+
outputDir: flags['output-dir'],
|
|
62
|
+
force: flags.force,
|
|
63
|
+
dryRun: flags['dry-run'],
|
|
64
|
+
describe: connection ? describeObject(connection) : undefined,
|
|
65
|
+
});
|
|
66
|
+
const verb = flags['dry-run'] ? 'Would create' : 'Created';
|
|
67
|
+
for (const test of result.created)
|
|
68
|
+
this.log(`${verb} ${test.className} for ${test.flowName}: ${test.path}`);
|
|
69
|
+
for (const skip of result.skipped)
|
|
70
|
+
this.warn(`Skipped ${skip.flowName}: ${skip.reason}`);
|
|
71
|
+
if (result.created.length === 0 && result.skipped.length === 0)
|
|
72
|
+
this.log('No uncovered Flows to scaffold.');
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../../src/commands/flowcov/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1E,QAAQ,CAAC,kCAAkC,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AAE/E,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,SAAyB;IAC7D,MAAM,CAAmB,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAClE,MAAM,CAAmB,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1E,MAAM,CAAmB,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAErE,MAAM,CAAmB,KAAK,GAAG;QACtC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;YACjB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,oBAAoB,CAAC;YAClD,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,KAAK,CAAC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KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5G,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO;YAAE,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACzF,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAC5G,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RequiredFieldMap } from './requiredFields.js';
|
|
2
|
+
import type { FlowMetadata } from './types.js';
|
|
3
|
+
export type GeneratedApexTest = {
|
|
4
|
+
className: string;
|
|
5
|
+
body: string;
|
|
6
|
+
kind: FlowKind;
|
|
7
|
+
};
|
|
8
|
+
export type FlowKind = 'record' | 'platformEvent' | 'scheduled' | 'autolaunched' | 'process';
|
|
9
|
+
/** Builds a valid Apex class name `<Flow>_FlowTest`, at most 40 characters. */
|
|
10
|
+
export declare function apexTestClassName(flowName: string): string;
|
|
11
|
+
export declare function flowKind(flow: FlowMetadata): FlowKind;
|
|
12
|
+
export type GenerateOptions = {
|
|
13
|
+
/** Required fields per object from an org describe. Falls back to a built-in list for common standard objects. */
|
|
14
|
+
requiredFields?: RequiredFieldMap;
|
|
15
|
+
};
|
|
16
|
+
/** Generates a starter Apex test class for a Flow from its metadata. */
|
|
17
|
+
export declare function generateApexTest(flow: FlowMetadata, options?: GenerateOptions): GeneratedApexTest;
|
|
18
|
+
export declare function apexClassMetaXml(apiVersion: string): string;
|