diff --git a/samples/classes/Sample3.cls b/samples/classes/Sample3.cls new file mode 100644 index 0000000..908272b --- /dev/null +++ b/samples/classes/Sample3.cls @@ -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); + } +} \ No newline at end of file diff --git a/src/commands/apextests/list.ts b/src/commands/apextests/list.ts index 741ed08..e8cf395 100644 --- a/src/commands/apextests/list.ts +++ b/src/commands/apextests/list.ts @@ -33,9 +33,14 @@ export default class ApextestsList extends SfCommand { // 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()) @@ -66,7 +71,7 @@ export default class ApextestsList extends SfCommand { // 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.'); }