Skip to content

Commit

Permalink
Handles the case where test methods is falsy or empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoliveira committed Sep 7, 2024
1 parent 4acdef2 commit 94e74d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions samples/classes/Sample3.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @Tests:
// A sample where someone forgot to specify the tests
public class Sample2 {
public void say(String msg) {
System.debug(msg);
}
}
11 changes: 8 additions & 3 deletions src/commands/apextests/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ export default class ApextestsList extends SfCommand<ApextestsListResult> {
// TODO: add manifest flag
};

private static parseTestsNames(data: string): string[] {
private static parseTestsNames(testNames: string[]): string[] {
if (!testNames || testNames.length === 0) {
return [];
}

// remove the prefix @Tests or @TestSuites
return data
return testNames
.join(',')
.split(',')
.map((line) => line.replace(/(@Tests|@TestSuites):/, ''))
.map((line) => line.trim())
Expand Down Expand Up @@ -66,7 +71,7 @@ export default class ApextestsList extends SfCommand<ApextestsListResult> {
// file with @Tests or @TestSuites
const testMethods = data.match(TEST_NAME_REGEX);
// for each entry, parse the names
testMethodsNames.push(...(testMethods ? ApextestsList.parseTestsNames(testMethods.join(',')) : []));
testMethodsNames.push(...(testMethods ? ApextestsList.parseTestsNames(testMethods) : []));
} catch (error) {
throw new Error('Invalid file.');
}
Expand Down

0 comments on commit 94e74d6

Please sign in to comment.