apextestlist 1.0.0

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 ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2024 Renato Oliveira
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Apex Test List
2
+
3
+ [![NPM](https://img.shields.io/npm/v/apextestlist.svg?label=apextestlist)](https://www.npmjs.com/package/apextestlist) [![Downloads/week](https://img.shields.io/npm/dw/apextestlist.svg)](https://npmjs.org/package/apextestlist) [![License](https://img.shields.io/badge/License-BSD%203--Clause-brightgreen.svg)](https://raw.githubusercontent.com/salesforcecli/apextestlist/main/LICENSE.txt)
4
+
5
+ A plugin that generates a list of tests that your, ideally, automated process should run, so you can save time by not running all tests in your Salesforce org and also save time by not specifying them manually.
6
+
7
+ ## Usage
8
+
9
+ List all files specified in the classes of a certain directory (and subfolders) and have the result be in the format for the CLI.
10
+
11
+ ```sh
12
+ sf apextests list --directory samples --format sf
13
+ $ --tests SampleTest SuperSampleTest Sample2Test SuperSample2Test
14
+ ```
@@ -0,0 +1,18 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ export type ApextestsListResult = {
3
+ tests: string[];
4
+ command: string;
5
+ };
6
+ export default class ApextestsList extends SfCommand<ApextestsListResult> {
7
+ static readonly summary: string;
8
+ static readonly description: string;
9
+ static readonly examples: string[];
10
+ static readonly flags: {
11
+ directory: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ format: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ };
14
+ private static parseTestsNames;
15
+ private static listTestsInDirectory;
16
+ private static formatList;
17
+ run(): Promise<ApextestsListResult>;
18
+ }
@@ -0,0 +1,94 @@
1
+ import * as fs from 'node:fs';
2
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
3
+ import { Messages } from '@salesforce/core';
4
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
5
+ const messages = Messages.loadMessages('apextestlist', 'apextests.list');
6
+ export default class ApextestsList extends SfCommand {
7
+ static summary = messages.getMessage('summary');
8
+ static description = messages.getMessage('description');
9
+ static examples = messages.getMessages('examples');
10
+ static flags = {
11
+ directory: Flags.string({
12
+ summary: messages.getMessage('flags.directory.summary'),
13
+ description: messages.getMessage('flags.directory.description'),
14
+ char: 'd',
15
+ required: false,
16
+ }),
17
+ format: Flags.string({
18
+ summary: messages.getMessage('flags.format.summary'),
19
+ description: messages.getMessage('flags.format.description'),
20
+ char: 'f',
21
+ required: false,
22
+ }),
23
+ // TODO: add manifest flag
24
+ };
25
+ static parseTestsNames(data) {
26
+ // remove the prefix @Tests or @TestSuites
27
+ return data
28
+ .split(',')
29
+ .map((line) => line.replace(/(@Tests|@TestSuites)/, ''))
30
+ .map((line) => line.replace(':', ''))
31
+ .map((line) => line.trim())
32
+ .filter((line) => line.trim().length > 0);
33
+ }
34
+ static listTestsInDirectory(directory) {
35
+ // check if the provided directory exists
36
+ if (!directory) {
37
+ throw new Error('Invalid directory.');
38
+ }
39
+ let readDir;
40
+ try {
41
+ readDir = fs.readdirSync(directory, { recursive: true });
42
+ }
43
+ catch (error) {
44
+ throw new Error('Invalid directory.');
45
+ }
46
+ const files = readDir.filter((file) => file.endsWith('.cls') || file.endsWith('.trigger'));
47
+ const testMethodsNames = [];
48
+ // read each file and check for the test methods at the top
49
+ files.map((file) => {
50
+ const data = fs.readFileSync(`${directory}/${file}`, 'utf8');
51
+ // try to find, with a RegEx, the test methods listed at the top of the
52
+ // file with @Tests or @TestSuites
53
+ const testMethods = data.match(/(@(Tests|TestSuites)).+/g);
54
+ // for each entry, parse the names
55
+ // const testMethodsNames = testMethods ? ApextestsList.parseTestsNames(testMethods.join(',')) : [];
56
+ testMethodsNames.push(...(testMethods ? ApextestsList.parseTestsNames(testMethods.join(',')) : []));
57
+ });
58
+ return testMethodsNames;
59
+ }
60
+ static async formatList(format, tests) {
61
+ switch (format) {
62
+ case 'sf':
63
+ return Promise.resolve({
64
+ tests,
65
+ command: '--tests ' + tests.join(' '),
66
+ });
67
+ case 'csv':
68
+ return Promise.resolve({
69
+ tests,
70
+ command: tests.join(','),
71
+ });
72
+ default:
73
+ throw new Error('Invalid format.');
74
+ }
75
+ }
76
+ async run() {
77
+ const { flags } = await this.parse(ApextestsList);
78
+ const directory = flags.directory ?? '.';
79
+ const format = flags.format ?? 'sf';
80
+ if (!directory) {
81
+ throw new Error('Directory must be provided.');
82
+ }
83
+ let result = null;
84
+ if (directory) {
85
+ result = ApextestsList.formatList(format, ApextestsList.listTestsInDirectory(directory));
86
+ }
87
+ if (!result) {
88
+ throw new Error('No directory or manifest provided');
89
+ }
90
+ this.log((await result).command);
91
+ return result;
92
+ }
93
+ }
94
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/apextests/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAQzE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,SAA8B;IAChE,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,yBAAyB,CAAC;YACvD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,6BAA6B,CAAC;YAC/D,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;YACnB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;Y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,IAAI,IAAI,CAAC;QAEpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,MAAM,GAAwC,IAAI,CAAC;QAEvD,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3F,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QAEjC,OAAO,MAAM,CAAC;IAChB,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export default {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ # summary
2
+
3
+ List
4
+
5
+ # description
6
+
7
+ Lists tests in a package.xml file or from a directory.
8
+
9
+ # flags.directory.summary
10
+
11
+ Directory name. Defaults to the current working directory.
12
+
13
+ # flags.directory.description
14
+
15
+ Usually, if you run this command at the root of your Salesforce DX project, it means that the directory points to the original "force-app" folder (even if you have renamed it to something else). If you wish to limit the usage to a specific module, specify the folder with this flag.
16
+
17
+ # flags.format.summary
18
+
19
+ Format of the output.
20
+
21
+ # flags.format.description
22
+
23
+ By default, the format being returned is a list in the format that can be merged with the test flags of the Salesforce CLI deploy and validate commands. Available formats are `sf` (default) and `csv`.
24
+
25
+ # examples
26
+
27
+ - <%= config.bin %> <%= command.id %> --format csv
28
+ - <%= config.bin %> <%= command.id %> --format sf --directory force-app