sf-delta-tests 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/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # sf-delta-tests
2
+
3
+ [![NPM](https://img.shields.io/npm/v/focus-tests.svg?label=focus-tests)](https://www.npmjs.com/package/focus-tests) [![Downloads/week](https://img.shields.io/npm/dw/focus-tests.svg)](https://npmjs.org/package/focus-tests) [![License](https://img.shields.io/badge/License-BSD%203--Clause-brightgreen.svg)](https://raw.githubusercontent.com/salesforcecli/focus-tests/main/LICENSE.txt)
4
+
5
+ ## Using the template
6
+
7
+ This repository provides a template for creating a plugin for the Salesforce CLI. To convert this template to a working plugin:
8
+
9
+ 1. Please get in touch with the Platform CLI team. We want to help you develop your plugin.
10
+ 2. Generate your plugin:
11
+
12
+ ```
13
+ sf plugins install dev
14
+ sf dev generate plugin
15
+
16
+ git init -b main
17
+ git add . && git commit -m "chore: initial commit"
18
+ ```
19
+
20
+ 3. Create your plugin's repo in the salesforcecli github org
21
+ 4. When you're ready, replace the contents of this README with the information you want.
22
+
23
+ ## Learn about `sf` plugins
24
+
25
+ Salesforce CLI plugins are based on the [oclif plugin framework](<(https://oclif.io/docs/introduction.html)>). Read the [plugin developer guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins_architecture_sf_cli.htm) to learn about Salesforce CLI plugin development.
26
+
27
+ This repository contains a lot of additional scripts and tools to help with general Salesforce node development and enforce coding standards. You should familiarize yourself with some of the [node developer packages](#tooling) used by Salesforce.
28
+
29
+ Additionally, there are some additional tests that the Salesforce CLI will enforce if this plugin is ever bundled with the CLI. These test are included by default under the `posttest` script and it is required to keep these tests active in your plugin if you plan to have it bundled.
30
+
31
+ ### Tooling
32
+
33
+ - [@salesforce/core](https://github.com/forcedotcom/sfdx-core)
34
+ - [@salesforce/kit](https://github.com/forcedotcom/kit)
35
+ - [@salesforce/sf-plugins-core](https://github.com/salesforcecli/sf-plugins-core)
36
+ - [@salesforce/ts-types](https://github.com/forcedotcom/ts-types)
37
+ - [@salesforce/ts-sinon](https://github.com/forcedotcom/ts-sinon)
38
+ - [@salesforce/dev-config](https://github.com/forcedotcom/dev-config)
39
+ - [@salesforce/dev-scripts](https://github.com/forcedotcom/dev-scripts)
40
+
41
+ ### Hooks
42
+
43
+ For cross clouds commands, e.g. `sf env list`, we utilize [oclif hooks](https://oclif.io/docs/hooks) to get the relevant information from installed plugins.
44
+
45
+ This plugin includes sample hooks in the [src/hooks directory](src/hooks). You'll just need to add the appropriate logic. You can also delete any of the hooks if they aren't required for your plugin.
46
+
47
+ # Everything past here is only a suggestion as to what should be in your specific plugin's description
48
+
49
+ This plugin is bundled with the [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli). For more information on the CLI, read the [getting started guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm).
50
+
51
+ We always recommend using the latest version of these commands bundled with the CLI, however, you can install a specific version or tag if needed.
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ sf plugins install focus-tests@x.y.z
57
+ ```
58
+
59
+ ## Issues
60
+
61
+ Please report any issues at https://github.com/forcedotcom/cli/issues
62
+
63
+ ## Contributing
64
+
65
+ 1. Please read our [Code of Conduct](CODE_OF_CONDUCT.md)
66
+ 2. Create a new issue before starting your project so that we can keep track of
67
+ what you are trying to add/fix. That way, we can also offer suggestions or
68
+ let you know if there is already an effort in progress.
69
+ 3. Fork this repository.
70
+ 4. [Build the plugin locally](#build)
71
+ 5. Create a _topic_ branch in your fork. Note, this step is recommended but technically not required if contributing using a fork.
72
+ 6. Edit the code in your fork.
73
+ 7. Write appropriate tests for your changes. Try to achieve at least 95% code coverage on any new code. No pull request will be accepted without unit tests.
74
+ 8. Sign CLA (see [CLA](#cla) below).
75
+ 9. Send us a pull request when you are done. We'll review your code, suggest any needed changes, and merge it in.
76
+
77
+ ### CLA
78
+
79
+ External contributors will be required to sign a Contributor's License
80
+ Agreement. You can do so by going to https://cla.salesforce.com/sign-cla.
81
+
82
+ ### Build
83
+
84
+ To build the plugin locally, make sure to have yarn installed and run the following commands:
85
+
86
+ ```bash
87
+ # Clone the repository
88
+ git clone git@github.com:salesforcecli/focus-tests
89
+
90
+ # Install the dependencies and compile
91
+ yarn && yarn build
92
+ ```
93
+
94
+ To use your plugin, run using the local `./bin/dev` or `./bin/dev.cmd` file.
95
+
96
+ ```bash
97
+ # Run using local run file.
98
+ ./bin/dev hello world
99
+ ```
100
+
101
+ There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.
102
+
103
+ ```bash
104
+ # Link your plugin to the sf cli
105
+ sf plugins link .
106
+ # To verify
107
+ sf plugins
108
+ ```
109
+
110
+ ## Commands
111
+
112
+ <!-- commands -->
113
+
114
+ - [`sf hello world`](#sf-hello-world)
115
+
116
+ ## `sf hello world`
117
+
118
+ Say hello either to the world or someone you know.
119
+
120
+ ```
121
+ USAGE
122
+ $ sf hello world [--json] [-n <value>]
123
+
124
+ FLAGS
125
+ -n, --name=<value> [default: World] The name of the person you'd like to say hello to.
126
+
127
+ GLOBAL FLAGS
128
+ --json Format output as json.
129
+
130
+ DESCRIPTION
131
+ Say hello either to the world or someone you know.
132
+
133
+ Say hello either to the world or someone you know.
134
+
135
+ EXAMPLES
136
+ Say hello to the world:
137
+
138
+ $ sf hello world
139
+
140
+ Say hello to someone you know:
141
+
142
+ $ sf hello world --name Astro
143
+ ```
144
+
145
+ <!-- commandsstop -->
@@ -0,0 +1,21 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { Config } from '@oclif/core';
3
+ import { DependencyService } from '../../services/dependency-service';
4
+ import { ApexClassService } from '../../services/apex-class-service';
5
+ export type DeltaTestClassesResult = {
6
+ testFiles: string[];
7
+ };
8
+ export default class TestClasses extends SfCommand<DeltaTestClassesResult> {
9
+ static readonly summary: string;
10
+ static readonly description: string;
11
+ static readonly examples: string[];
12
+ static readonly flags: {
13
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ 'target-org': import("@oclif/core/lib/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ 'changed-metadata': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ };
17
+ private dependencyService;
18
+ private apexClassService;
19
+ constructor(argv: string[], config: Config, dependencyService?: DependencyService, apexClassService?: ApexClassService);
20
+ run(): Promise<DeltaTestClassesResult>;
21
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
4
+ const core_1 = require("@salesforce/core");
5
+ const dependency_service_1 = require("../../services/dependency-service");
6
+ const apex_class_service_1 = require("../../services/apex-class-service");
7
+ core_1.Messages.importMessagesDirectory(__dirname);
8
+ const messages = core_1.Messages.loadMessages('sf-delta-tests', 'delta.test-classes');
9
+ class TestClasses extends sf_plugins_core_1.SfCommand {
10
+ constructor(argv, config, dependencyService = new dependency_service_1.DependencyService(), apexClassService = new apex_class_service_1.ApexClassService()) {
11
+ super(argv, config);
12
+ this.dependencyService = dependencyService;
13
+ this.apexClassService = apexClassService;
14
+ }
15
+ async run() {
16
+ const { flags } = await this.parse(TestClasses);
17
+ const org = flags['target-org'];
18
+ const conn = org.getConnection(undefined);
19
+ this.dependencyService.connect(conn);
20
+ const combinedApexClassData = await this.dependencyService.getDependenciesByObjects();
21
+ const changedFiles = flags['changed-metadata'].split(',').map((metadata) => metadata.trim());
22
+ const results = this.dependencyService.getRelatedApexClasses(combinedApexClassData, changedFiles);
23
+ this.debug({ results });
24
+ const testFiles = await this.apexClassService.filterApexTest(results);
25
+ const simpleTestFiles = this.apexClassService.filterApexTestSimple(results);
26
+ this.debug({ testFiles, simpleTestFiles });
27
+ this.log(simpleTestFiles.join(','));
28
+ return {
29
+ testFiles,
30
+ };
31
+ }
32
+ }
33
+ TestClasses.summary = messages.getMessage('summary');
34
+ TestClasses.description = messages.getMessage('description');
35
+ TestClasses.examples = messages.getMessages('examples');
36
+ TestClasses.flags = {
37
+ name: sf_plugins_core_1.Flags.string({
38
+ summary: messages.getMessage('flags.name.summary'),
39
+ description: messages.getMessage('flags.name.description'),
40
+ char: 'n',
41
+ required: false,
42
+ }),
43
+ 'target-org': sf_plugins_core_1.Flags.requiredOrg({
44
+ summary: messages.getMessage('flags.target-org.summary'),
45
+ char: 'o',
46
+ required: true,
47
+ }),
48
+ 'changed-metadata': sf_plugins_core_1.Flags.string({
49
+ summary: messages.getMessage('flags.changed-metadata.summary'),
50
+ char: 'c',
51
+ required: true,
52
+ }),
53
+ };
54
+ exports.default = TestClasses;
55
+ //# sourceMappingURL=test-classes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-classes.js","sourceRoot":"","sources":["../../../src/commands/delta/test-classes.ts"],"names":[],"mappings":";;AAAA,iEAA+D;AAC/D,2CAA4C;AAE5C,0EAAsE;AACtE,0EAAqE;AAErE,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;AAM/E,MAAqB,WAAY,SAAQ,2BAAiC;IA2BxE,YACE,IAAc,EACd,MAAc,EACd,iBAAiB,GAAG,IAAI,sCAAiB,EAAE,EAC3C,gBAAgB,GAAG,IAAI,qCAAgB,EAAE;QAEzC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,GAAG;QACd,MAAM,EAAE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K,GAAG;IAC7B,IAAI,EAAE,uBAAK,CAAC,MAAM,CAAC;QACjB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,oBAAoB,CAAC;QAClD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC;QAC1D,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,YAAY,EAAE,uBAAK,CAAC,WAAW,CAAC;QAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC;QACxD,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,IAAI;KACf,CAAC;IACF,kBAAkB,EAAE,uBAAK,CAAC,MAAM,CAAC;QAC/B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QAC9D,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,IAAI;KACf,CAAC;CACH,CAAC;kBAtBiB,WAAW"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export = _default;
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ module.exports = {};
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iBAAS,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare class ApexClassService {
2
+ filterApexTestSimple(classList: string[]): string[];
3
+ filterApexTest(classList: string[], rootPath?: string): Promise<string[]>;
4
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApexClassService = void 0;
4
+ const path_1 = require("path");
5
+ const promises_1 = require("fs/promises");
6
+ const glob_1 = require("glob");
7
+ class ApexClassService {
8
+ // eslint-disable-next-line class-methods-use-this
9
+ filterApexTestSimple(classList) {
10
+ return classList.filter((className) => className.toLowerCase().includes('test'));
11
+ }
12
+ // eslint-disable-next-line class-methods-use-this
13
+ async filterApexTest(classList, rootPath = 'force-app/main/default/classes') {
14
+ // Get all Apex Classes with the filenames `${className}.cls` in the root directory and all subdirectories
15
+ const globPattern = `**/{${classList.join(',')}}.cls`;
16
+ const apexClassPaths = await (0, glob_1.glob)(globPattern, { cwd: rootPath });
17
+ const apexClassTests = [];
18
+ const regexIsTest = /@istest/i;
19
+ // Open each file, check to see if it is a test and add to apexClassTests
20
+ for (const apexClassPath of apexClassPaths) {
21
+ const joinedPath = (0, path_1.join)(rootPath, apexClassPath);
22
+ const parsedPath = (0, path_1.parse)(joinedPath);
23
+ // eslint-disable-next-line no-await-in-loop
24
+ const fileContent = (await (0, promises_1.readFile)(joinedPath)).toString();
25
+ if (fileContent.search(regexIsTest) !== -1) {
26
+ apexClassTests.push(parsedPath.name.replace('.cls', ''));
27
+ }
28
+ }
29
+ return apexClassTests;
30
+ }
31
+ }
32
+ exports.ApexClassService = ApexClassService;
33
+ //# sourceMappingURL=apex-class-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apex-class-service.js","sourceRoot":"","sources":["../../src/services/apex-class-service.ts"],"names":[],"mappings":";;;AAAA,+BAA4D;AAC5D,0CAAuC;AACvC,+BAA4B;AAE5B,MAAa,gBAAgB;IAC3B,kDAAkD;IAC3C,oBAAoB,CAAC,SAAmB;QAC7C,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,cAAc,CAAC,SAAmB,EAAE,QAAQ,GAAG,gCAAgC;QAC1F,0GAA0G;QAC1G,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;QACtD,MAAM,cAAc,GAAG,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QAElE,MAAM,cAAc,GAAa,EAAE,CAAC;QACpC,MAAM,WAAW,GAAG,UAAU,CAAC;QAE/B,yEAAyE;QACzE,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;YAC1C,MAAM,UAAU,GAAG,IAAA,WAAQ,EAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YACrD,MAAM,UAAU,GAAG,IAAA,YAAS,EAAC,UAAU,CAAC,CAAC;YACzC,4CAA4C;YAC5C,MAAM,WAAW,GAAG,CAAC,MAAM,IAAA,mBAAQ,EAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5D,IAAI,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC1C,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;aAC1D;SACF;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA5BD,4CA4BC"}
@@ -0,0 +1,18 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type MetadataComponentDependency = {
3
+ MetadataComponentName: string;
4
+ MetadataComponentType: string;
5
+ RefMetadataComponentName: string;
6
+ RefMetadataComponentType: string;
7
+ };
8
+ export declare class DependencyService {
9
+ private connection;
10
+ connect(connection: Connection): void;
11
+ getDependenciesByObjects(additionalObjects?: string[]): Promise<MetadataComponentDependency[]>;
12
+ getRelatedApexClasses(dependencyList: MetadataComponentDependency[], changedMetadata: string[]): string[];
13
+ private isApexClass;
14
+ private getRelations;
15
+ private getDependencyByObject;
16
+ private getDependencySoql;
17
+ private getRefDependencySoql;
18
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DependencyService = void 0;
4
+ const kit_1 = require("@salesforce/kit");
5
+ class DependencyService {
6
+ connect(connection) {
7
+ this.connection = connection;
8
+ }
9
+ async getDependenciesByObjects(additionalObjects) {
10
+ const objects = new Set([
11
+ 'ApexClass',
12
+ 'ApexTrigger',
13
+ 'CustomObject',
14
+ 'Flow',
15
+ 'LightningComponentBundle',
16
+ 'AuraDefinitionBundle',
17
+ ]);
18
+ if (additionalObjects) {
19
+ additionalObjects.forEach((object) => objects.add(object));
20
+ }
21
+ const promises = [];
22
+ objects.forEach((object) => promises.push(this.getDependencyByObject(object)));
23
+ const results = await Promise.all(promises);
24
+ return results.flat();
25
+ }
26
+ getRelatedApexClasses(dependencyList, changedMetadata) {
27
+ const directDependencies = new Set();
28
+ for (const depData of dependencyList) {
29
+ if (changedMetadata.includes(depData.RefMetadataComponentName)) {
30
+ directDependencies.add(depData.MetadataComponentName);
31
+ }
32
+ }
33
+ const dependencies = Array.from(this.getRelations(dependencyList, directDependencies));
34
+ return dependencies.filter((dependency) => this.isApexClass(dependencyList, dependency));
35
+ }
36
+ // eslint-disable-next-line class-methods-use-this
37
+ isApexClass(dependencyList, dependency) {
38
+ for (const metadata of dependencyList) {
39
+ if ((metadata.MetadataComponentType === 'ApexClass' && metadata.MetadataComponentName === dependency) ||
40
+ (metadata.RefMetadataComponentType === 'ApexClass' && metadata.RefMetadataComponentName === dependency)) {
41
+ return true;
42
+ }
43
+ }
44
+ return false;
45
+ }
46
+ getRelations(dependencyList, dependencies) {
47
+ const newDependencies = new Set(dependencies);
48
+ for (const depData of dependencyList) {
49
+ if (newDependencies.has(depData.RefMetadataComponentName)) {
50
+ newDependencies.add(depData.MetadataComponentName);
51
+ }
52
+ }
53
+ if (newDependencies.size !== dependencies.size) {
54
+ return this.getRelations(dependencyList, newDependencies);
55
+ }
56
+ return newDependencies;
57
+ }
58
+ async getDependencyByObject(objectType) {
59
+ if (!this.connection) {
60
+ throw Error('Run connection() first');
61
+ }
62
+ const dependencies = await this.connection.tooling.query(this.getDependencySoql(objectType));
63
+ const refDependencies = await this.connection.tooling.query(this.getRefDependencySoql(objectType));
64
+ return (0, kit_1.sortBy)([...dependencies.records, ...refDependencies.records], ['MetadataComponentType', 'RefMetadataComponentType']);
65
+ }
66
+ // eslint-disable-next-line class-methods-use-this
67
+ getDependencySoql(objectType) {
68
+ return `SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName, RefMetadataComponentType
69
+ FROM MetadataComponentDependency
70
+ WHERE MetadataComponentType = '${objectType}'
71
+ AND MetadataComponentNamespace = NULL
72
+ AND RefMetadataComponentNamespace = NULL`;
73
+ }
74
+ // eslint-disable-next-line class-methods-use-this
75
+ getRefDependencySoql(objectType) {
76
+ return `SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName, RefMetadataComponentType
77
+ FROM MetadataComponentDependency
78
+ WHERE RefMetadataComponentType = '${objectType}'
79
+ AND MetadataComponentNamespace = NULL
80
+ AND RefMetadataComponentNamespace = NULL`;
81
+ }
82
+ }
83
+ exports.DependencyService = DependencyService;
84
+ //# sourceMappingURL=dependency-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-service.js","sourceRoot":"","sources":["../../src/services/dependency-service.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AAQzC,MAAa,iBAAiB;IAGrB,OAAO,CAAC,UAAsB;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,iBAA4B;QAChE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS;YAC9B,WAAW;YACX,aAAa;YACb,cAAc;YACd,MAAM;YACN,0BAA0B;YAC1B,sBAAsB;SACvB,CAAC,CAAC;QACH,IAAI,iBAAiB,EAAE;YACrB,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;SAC5D;QACD,MAAM,QAAQ,GAAkD,EAAE,CAAC;QACnE,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI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e,CAAC,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE;gBACzD,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;aACpD;SACF;QAED,IAAI,eAAe,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,EAAE;YAC9C,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;SAC3D;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAAC,UAAkB;QACpD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAC;SACvC;QACD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CACtD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CACnC,CAAC;QACF,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CACzD,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CACtC,CAAC;QAEF,OAAO,IAAA,YAAM,EACX,CAAC,GAAG,YAAY,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,EACrD,CAAC,uBAAuB,EAAE,0BAA0B,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,kDAAkD;IAC1C,iBAAiB,CAAC,UAAkB;QAC1C,OAAO;;uCAE4B,UAAU;;iDAEA,CAAC;IAChD,CAAC;IAED,kDAAkD;IAC1C,oBAAoB,CAAC,UAAkB;QAC7C,OAAO;;0CAE+B,UAAU;;iDAEH,CAAC;IAChD,CAAC;CACF;AAtGD,8CAsGC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // import { TestContext } from '@salesforce/core/lib/testSetup';
4
+ // import { expect } from 'chai';
5
+ // import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
6
+ // import World from '../../../src/commands/hello/world';
7
+ const fs_1 = require("fs");
8
+ const mocha_1 = require("mocha");
9
+ const chai_1 = require("chai");
10
+ const dependency_service_1 = require("./dependency-service");
11
+ describe('dependency-services', () => {
12
+ let dependencyService;
13
+ let dependencyList;
14
+ before(() => {
15
+ dependencyList = JSON.parse((0, fs_1.readFileSync)('test/fixtures/dependency-exploration-sf.json').toString());
16
+ });
17
+ (0, mocha_1.beforeEach)(() => {
18
+ dependencyService = new dependency_service_1.DependencyService();
19
+ });
20
+ describe('getRelatedApexClasses', () => {
21
+ it('test', () => {
22
+ const results = dependencyService.getRelatedApexClasses(dependencyList, ['APIUsers']);
23
+ (0, chai_1.expect)(results).to.deep.eq(['APIUsersTest']);
24
+ });
25
+ });
26
+ });
27
+ //# sourceMappingURL=dependency-services.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-services.test.js","sourceRoot":"","sources":["../../src/services/dependency-services.test.ts"],"names":[],"mappings":";;AAAA,gEAAgE;AAChE,iCAAiC;AACjC,iEAAiE;AACjE,yDAAyD;AACzD,2BAAkC;AAClC,iCAAmC;AACnC,+BAA8B;AAC9B,6DAAsF;AAEtF,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,iBAAoC,CAAC;IACzC,IAAI,cAA6C,CAAC;IAElD,MAAM,CAAC,GAAG,EAAE;QACV,cAAc,GAAG,IAAI,CAAC,KAAK,CACzB,IAAA,iBAAY,EAAC,8CAA8C,CAAC,CAAC,QAAQ,EAAE,CACvC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,IAAA,kBAAU,EAAC,GAAG,EAAE;QACd,iBAAiB,GAAG,IAAI,sCAAiB,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACd,MAAM,OAAO,GAAG,iBAAiB,CAAC,qBAAqB,CAAC,cAAc,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YACtF,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ # summary
2
+
3
+ Calculates the tests needed to be ran based on the changed metadata given using the Salesforce Dependency API
4
+
5
+ # description
6
+
7
+ Calculates the tests needed to be ran based on the changed metadata given using the Salesforce Dependency API
8
+
9
+ # flags.name.summary
10
+
11
+ Description of a flag.
12
+
13
+ # flags.name.description
14
+
15
+ More information about a flag. Don't repeat the summary.
16
+
17
+ # examples
18
+
19
+ - <%= config.bin %> <%= command.id %>
20
+
21
+
22
+ # flags.target-org.summary
23
+
24
+ The org you want to check the dependencies against.
25
+
26
+ # flags.changed-metadata.summary
27
+
28
+ Comma seperated list of changed metadata.
@@ -0,0 +1,54 @@
1
+ {
2
+ "version": "0.0.1",
3
+ "commands": {
4
+ "delta:test-classes": {
5
+ "id": "delta:test-classes",
6
+ "summary": "Calculates the tests needed to be ran based on the changed metadata given using the Salesforce Dependency API",
7
+ "description": "Calculates the tests needed to be ran based on the changed metadata given using the Salesforce Dependency API",
8
+ "strict": true,
9
+ "pluginName": "sf-delta-tests",
10
+ "pluginAlias": "sf-delta-tests",
11
+ "pluginType": "core",
12
+ "aliases": [],
13
+ "examples": [
14
+ "<%= config.bin %> <%= command.id %>"
15
+ ],
16
+ "flags": {
17
+ "json": {
18
+ "name": "json",
19
+ "type": "boolean",
20
+ "description": "Format output as json.",
21
+ "helpGroup": "GLOBAL",
22
+ "allowNo": false
23
+ },
24
+ "name": {
25
+ "name": "name",
26
+ "type": "option",
27
+ "char": "n",
28
+ "summary": "Description of a flag.",
29
+ "description": "More information about a flag. Don't repeat the summary.",
30
+ "required": false,
31
+ "multiple": false
32
+ },
33
+ "target-org": {
34
+ "name": "target-org",
35
+ "type": "option",
36
+ "char": "o",
37
+ "summary": "The org you want to check the dependencies against.",
38
+ "required": true,
39
+ "multiple": false
40
+ },
41
+ "changed-metadata": {
42
+ "name": "changed-metadata",
43
+ "type": "option",
44
+ "char": "c",
45
+ "summary": "Comma seperated list of changed metadata.",
46
+ "required": true,
47
+ "multiple": false
48
+ }
49
+ },
50
+ "args": {},
51
+ "hasDynamicHelp": true
52
+ }
53
+ }
54
+ }
package/package.json ADDED
@@ -0,0 +1,201 @@
1
+ {
2
+ "name": "sf-delta-tests",
3
+ "description": "Calculate dependencies and scope to relevant tests",
4
+ "version": "0.0.1",
5
+ "dependencies": {
6
+ "@oclif/core": "^2.11.8",
7
+ "@salesforce/core": "^5.2.0",
8
+ "@salesforce/kit": "^3.0.8",
9
+ "@salesforce/sf-plugins-core": "^3.1.14",
10
+ "glob": "^10.3.3",
11
+ "tslib": "^2"
12
+ },
13
+ "devDependencies": {
14
+ "@salesforce/dev-config": "^4.0.1",
15
+ "@salesforce/dev-scripts": "^5.7.0",
16
+ "@salesforce/prettier-config": "^0.0.3",
17
+ "@salesforce/ts-sinon": "^1.4.14",
18
+ "@swc/core": "^1.3.19",
19
+ "@types/inquirer": "^9.0.3",
20
+ "@typescript-eslint/eslint-plugin": "^5.59.8",
21
+ "@typescript-eslint/parser": "^5.62.0",
22
+ "chai": "^4.3.6",
23
+ "eslint": "^8.47.0",
24
+ "eslint-config-prettier": "^8.5.0",
25
+ "eslint-config-salesforce": "^2.0.1",
26
+ "eslint-config-salesforce-typescript": "^1.1.2",
27
+ "eslint-plugin-import": "2.27.5",
28
+ "eslint-plugin-jsdoc": "^46.4.6",
29
+ "eslint-plugin-sf-plugin": "^1.16.2",
30
+ "husky": "^7.0.4",
31
+ "mocha": "^9.2.2",
32
+ "nyc": "^15.1.0",
33
+ "oclif": "^3.9.1",
34
+ "prettier": "^2.8.8",
35
+ "pretty-quick": "^3.1.3",
36
+ "shx": "0.3.4",
37
+ "sinon": "10.0.0",
38
+ "ts-node": "^10.9.1",
39
+ "typescript": "^5.1.6",
40
+ "wireit": "^0.10.0"
41
+ },
42
+ "engines": {
43
+ "node": ">=16.0.0"
44
+ },
45
+ "files": [
46
+ "/lib",
47
+ "/messages",
48
+ "/oclif.manifest.json"
49
+ ],
50
+ "keywords": [
51
+ "force",
52
+ "salesforce",
53
+ "sfdx",
54
+ "salesforcedx",
55
+ "sfdx-plugin",
56
+ "sf-plugin",
57
+ "sf"
58
+ ],
59
+ "license": "BSD-3-Clause",
60
+ "main": "lib/index.js",
61
+ "oclif": {
62
+ "commands": "./lib/commands",
63
+ "bin": "sf",
64
+ "topicSeparator": " ",
65
+ "devPlugins": [
66
+ "@oclif/plugin-help"
67
+ ],
68
+ "topics": {
69
+ "hello": {
70
+ "description": "Commands to say hello."
71
+ }
72
+ }
73
+ },
74
+ "scripts": {
75
+ "build": "wireit",
76
+ "clean": "sf-clean",
77
+ "clean-all": "sf-clean all",
78
+ "clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json",
79
+ "compile": "wireit",
80
+ "docs": "sf-docs",
81
+ "format": "wireit",
82
+ "lint": "wireit",
83
+ "postinstall": "yarn husky install",
84
+ "postpack": "shx rm -f oclif.manifest.json",
85
+ "prepack": "sf-prepack",
86
+ "test": "wireit",
87
+ "test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
88
+ "test:only": "wireit",
89
+ "version": "oclif readme"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public"
93
+ },
94
+ "wireit": {
95
+ "build": {
96
+ "dependencies": [
97
+ "compile",
98
+ "lint"
99
+ ]
100
+ },
101
+ "compile": {
102
+ "command": "tsc -p . --pretty --incremental",
103
+ "files": [
104
+ "src/**/*.ts",
105
+ "**/tsconfig.json",
106
+ "messages/**"
107
+ ],
108
+ "output": [
109
+ "lib/**",
110
+ "*.tsbuildinfo"
111
+ ],
112
+ "clean": "if-file-deleted"
113
+ },
114
+ "format": {
115
+ "command": "prettier --write \"+(src|test|schemas)/**/*.+(ts|js|json)|command-snapshot.json\"",
116
+ "files": [
117
+ "src/**/*.ts",
118
+ "test/**/*.ts",
119
+ "schemas/**/*.json",
120
+ "command-snapshot.json",
121
+ ".prettier*"
122
+ ],
123
+ "output": []
124
+ },
125
+ "lint": {
126
+ "command": "eslint src test --color --cache --cache-location .eslintcache",
127
+ "files": [
128
+ "src/**/*.ts",
129
+ "test/**/*.ts",
130
+ "messages/**",
131
+ "**/.eslint*",
132
+ "**/tsconfig.json"
133
+ ],
134
+ "output": []
135
+ },
136
+ "test:compile": {
137
+ "command": "tsc -p \"./test\" --pretty",
138
+ "files": [
139
+ "test/**/*.ts",
140
+ "**/tsconfig.json"
141
+ ],
142
+ "output": []
143
+ },
144
+ "test": {
145
+ "dependencies": [
146
+ "test:compile",
147
+ "test:only",
148
+ "lint"
149
+ ]
150
+ },
151
+ "test:only": {
152
+ "command": "nyc mocha \"test/**/*.test.ts\"",
153
+ "env": {
154
+ "FORCE_COLOR": "2"
155
+ },
156
+ "files": [
157
+ "test/**/*.ts",
158
+ "src/**/*.ts",
159
+ "**/tsconfig.json",
160
+ ".mocha*",
161
+ "!*.nut.ts",
162
+ ".nycrc"
163
+ ],
164
+ "output": []
165
+ },
166
+ "test:command-reference": {
167
+ "command": "\"./bin/dev\" commandreference:generate --erroronwarnings",
168
+ "files": [
169
+ "src/**/*.ts",
170
+ "messages/**",
171
+ "package.json"
172
+ ],
173
+ "output": [
174
+ "tmp/root"
175
+ ]
176
+ },
177
+ "test:deprecation-policy": {
178
+ "command": "\"./bin/dev\" snapshot:compare",
179
+ "files": [
180
+ "src/**/*.ts"
181
+ ],
182
+ "output": [],
183
+ "dependencies": [
184
+ "compile"
185
+ ]
186
+ },
187
+ "test:json-schema": {
188
+ "command": "\"./bin/dev\" schema:compare",
189
+ "files": [
190
+ "src/**/*.ts",
191
+ "schemas"
192
+ ],
193
+ "output": []
194
+ }
195
+ },
196
+ "author": "matthew-gladman",
197
+ "volta": {
198
+ "node": "18.17.1",
199
+ "yarn": "1.22.19"
200
+ }
201
+ }