apextestlist 1.0.0 → 1.0.2
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 +28 -1
- package/lib/commands/apextests/list.d.ts +1 -0
- package/lib/commands/apextests/list.js +35 -21
- package/lib/commands/apextests/list.js.map +1 -1
- package/npm-shrinkwrap.json +3207 -2048
- package/oclif.lock +565 -1446
- package/oclif.manifest.json +1 -1
- package/package.json +9 -6
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,34 @@ A plugin that generates a list of tests that your, ideally, automated process sh
|
|
|
8
8
|
|
|
9
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
10
|
|
|
11
|
+
The classes should have a comment starting with `@Tests` somewhere. This is what the tool reads to return the tests. For example, the `Sample.cls` file in the `samples` folder contains a comment like this:
|
|
12
|
+
|
|
13
|
+
```java
|
|
14
|
+
// @Tests: SampleTest,SuperSampleTest
|
|
15
|
+
public class Sample {
|
|
16
|
+
// ...
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
In the context of this plugin, this annotation/comment on the class means that _the tests that should cover this test class are called `SampleTest` and `SuperSampleTest`_.
|
|
21
|
+
|
|
22
|
+
> Note: The tool does not check if those classes exist within your project, so make sure to keep the annotations up-to-date.
|
|
23
|
+
|
|
24
|
+
Then, assuming you want to run only the tests provided at the top level of your classes, use the command as follows:
|
|
25
|
+
|
|
11
26
|
```sh
|
|
12
|
-
sf apextests list --directory
|
|
27
|
+
sf apextests list --directory force-app --format sf
|
|
13
28
|
$ --tests SampleTest SuperSampleTest Sample2Test SuperSample2Test
|
|
14
29
|
```
|
|
30
|
+
|
|
31
|
+
This commnad is originally designed to be used in the context of a CI/CD pipeline. So that when your pipeline has a commnad to validate or deploy code to a Salesforce org, it will dynamically build the list of classes, like so:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
sf project deploy start $(sf apextests list)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This then becomes the full command to deploy and run only the tests that you - in theory - deem to be necessary:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
sf project deploy start --tests SampleTest SuperSampleTest Sample2Test SuperSample2Test SampleTriggerTest
|
|
41
|
+
```
|
|
@@ -11,6 +11,7 @@ export default class ApextestsList extends SfCommand<ApextestsListResult> {
|
|
|
11
11
|
directory: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
12
|
format: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
13
|
};
|
|
14
|
+
protected static getConcurrencyThreshold(): number;
|
|
14
15
|
private static parseTestsNames;
|
|
15
16
|
private static listTestsInDirectory;
|
|
16
17
|
private static formatList;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
+
import { availableParallelism } from 'node:os';
|
|
2
3
|
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
3
4
|
import { Messages } from '@salesforce/core';
|
|
5
|
+
import { queue } from 'async';
|
|
4
6
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
5
7
|
const messages = Messages.loadMessages('apextestlist', 'apextests.list');
|
|
8
|
+
const TEST_NAME_REGEX = /(@(Tests|TestSuites)).+/g;
|
|
6
9
|
export default class ApextestsList extends SfCommand {
|
|
7
10
|
static summary = messages.getMessage('summary');
|
|
8
11
|
static description = messages.getMessage('description');
|
|
@@ -22,16 +25,24 @@ export default class ApextestsList extends SfCommand {
|
|
|
22
25
|
}),
|
|
23
26
|
// TODO: add manifest flag
|
|
24
27
|
};
|
|
25
|
-
static
|
|
28
|
+
static getConcurrencyThreshold() {
|
|
29
|
+
const AVAILABLE_PARALLELISM = availableParallelism ? availableParallelism() : Infinity;
|
|
30
|
+
return Math.min(AVAILABLE_PARALLELISM, 6);
|
|
31
|
+
}
|
|
32
|
+
static parseTestsNames(testNames) {
|
|
33
|
+
if (!testNames || testNames.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
26
36
|
// remove the prefix @Tests or @TestSuites
|
|
27
|
-
return
|
|
37
|
+
return testNames
|
|
38
|
+
.join(',')
|
|
28
39
|
.split(',')
|
|
29
|
-
.map((line) => line.replace(/(@Tests|@TestSuites)
|
|
30
|
-
.map((line) => line.replace(':', ''))
|
|
40
|
+
.map((line) => line.replace(/(@Tests|@TestSuites):/, ''))
|
|
31
41
|
.map((line) => line.trim())
|
|
32
|
-
.filter((line) => line
|
|
42
|
+
.filter((line) => line);
|
|
33
43
|
}
|
|
34
|
-
static listTestsInDirectory(directory) {
|
|
44
|
+
static async listTestsInDirectory(directory) {
|
|
45
|
+
const testMethodsNames = [];
|
|
35
46
|
// check if the provided directory exists
|
|
36
47
|
if (!directory) {
|
|
37
48
|
throw new Error('Invalid directory.');
|
|
@@ -43,21 +54,24 @@ export default class ApextestsList extends SfCommand {
|
|
|
43
54
|
catch (error) {
|
|
44
55
|
throw new Error('Invalid directory.');
|
|
45
56
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const localFiles = readDir.filter((file) => file.endsWith('.cls') || file.endsWith('.trigger'));
|
|
58
|
+
const handler = (fileName) => {
|
|
59
|
+
const path = `${directory}/${fileName}`;
|
|
60
|
+
const data = fs.readFileSync(path, 'utf-8');
|
|
61
|
+
const testMethods = data.match(TEST_NAME_REGEX);
|
|
62
|
+
testMethodsNames.push(...ApextestsList.parseTestsNames(testMethods));
|
|
63
|
+
};
|
|
64
|
+
const processor = queue((f, cb) => {
|
|
65
|
+
handler(f);
|
|
66
|
+
cb();
|
|
67
|
+
}, this.getConcurrencyThreshold());
|
|
68
|
+
await processor.push(localFiles);
|
|
69
|
+
if (processor.length() > 0) {
|
|
70
|
+
await processor.drain();
|
|
71
|
+
}
|
|
72
|
+
return testMethodsNames.sort();
|
|
59
73
|
}
|
|
60
|
-
static
|
|
74
|
+
static formatList(format, tests) {
|
|
61
75
|
switch (format) {
|
|
62
76
|
case 'sf':
|
|
63
77
|
return Promise.resolve({
|
|
@@ -82,7 +96,7 @@ export default class ApextestsList extends SfCommand {
|
|
|
82
96
|
}
|
|
83
97
|
let result = null;
|
|
84
98
|
if (directory) {
|
|
85
|
-
result = ApextestsList.formatList(format, ApextestsList.listTestsInDirectory(directory));
|
|
99
|
+
result = ApextestsList.formatList(format, await ApextestsList.listTestsInDirectory(directory));
|
|
86
100
|
}
|
|
87
101
|
if (!result) {
|
|
88
102
|
throw new Error('No directory or manifest provided');
|
|
@@ -1 +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;
|
|
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,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MA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