Skip to content

Commit

Permalink
Merge pull request #439 from SalesforceLabs/437-nb-asserts-not-availa…
Browse files Browse the repository at this point in the history
…ble-in-the-beryllium-version

fix: add nb assert count, and also include the use of Assert.Xxx() me…
  • Loading branch information
VinceFINET authored Sep 12, 2024
2 parents 028765a + 6229a6c commit 2c8ac66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const REGEX_COMMENTS_AND_NEWLINES = new RegExp('(\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*
const REGEX_ISINTERFACE = new RegExp("(?:public|global)\\s+(?:interface)\\s+\\w+(\\s+(?:extends)\\s+\\w+)?\\s*\\{", 'i');
const REGEX_ISENUM = new RegExp("(?:public|global)\\s+(?:enum)\\s+\\w+\\s*\\{", 'i');
const REGEX_ISTESTSEEALLDATA = new RegExp("@IsTest\\(.*SeeAllData=true.*\\)", 'i');
const REGEX_TESTNBASSERTS = new RegExp("System.assert(?:Equals|NotEquals|)\\(", 'ig');
const REGEX_TESTNBASSERTS = new RegExp("(System.assert(Equals|NotEquals|)\\(|Assert\\.[a-zA-Z]*\\()", 'ig');

export class OrgCheckDatasetApexClasses extends OrgCheckDataset {

Expand Down Expand Up @@ -83,15 +83,7 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset {
allDependencies: dependencies
});

// Get information directly from the source code (if available)
if (record.Body) {
const sourceCode = record.Body.replaceAll(REGEX_COMMENTS_AND_NEWLINES, ' ');
apexClass.isInterface = sourceCode.match(REGEX_ISINTERFACE) !== null;
apexClass.isEnum = sourceCode.match(REGEX_ISENUM) !== null;
apexClass.isClass = (apexClass.isInterface === false && apexClass.isEnum === false);
}

// If the apex class compiled we will get information from compilation
// Get information from the compilation output information by the Apex compiler on salesforce side (if available)
if (record.SymbolTable) {
apexClass.innerClassesCount = record.SymbolTable.innerClasses.length || 0;
apexClass.interfaces = record.SymbolTable.interfaces;
Expand All @@ -116,8 +108,22 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset {
});
}
}

// Get information directly from the source code (if available)
if (record.Body) {
const sourceCode = record.Body.replaceAll(REGEX_COMMENTS_AND_NEWLINES, ' ');
apexClass.isInterface = sourceCode.match(REGEX_ISINTERFACE) !== null;
apexClass.isEnum = sourceCode.match(REGEX_ISENUM) !== null;
apexClass.isClass = (apexClass.isInterface === false && apexClass.isEnum === false);

// Specific scanning for Test Classes
if (apexClass.isTest === true) { // this is defined only from the SymbolTable!
apexClass.isTestSeeAllData = sourceCode.match(REGEX_ISTESTSEEALLDATA) !== null;
apexClass.nbSystemAsserts = sourceCode.match(REGEX_TESTNBASSERTS)?.length || 0;
}
}

// Defin type
// Define type
if (apexClass.isTest === true) {
apexClass.type = 'test';
} else if (apexClass.isInterface === true) {
Expand All @@ -134,12 +140,6 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset {
apexClass.isSharingMissing = true;
}

// Specific scanning for Test Classes
if (apexClass.isTest === true) {
apexClass.isTestSeeAllData = record.Body.match(REGEX_ISTESTSEEALLDATA) !== null;
apexClass.nbSystemAsserts = record.Body.match(REGEX_TESTNBASSERTS)?.length || 0;
}

// Add it to the map
return [ apexClass.id, apexClass ];
}));
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/lwc/orgcheckApp/orgcheckApp.html
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ <h1 class="slds-text-heading_medium">Relationships</h1>
</lightning-layout-item>
<template if:true={apexUncompiledTableData}>
<lightning-layout-item>
<lightning-button label="Compile when needed" title="Compile when needed" variant="brand-outline" class="slds-var-m-left_x-small" icon-name="utility:refresh" onclick={handleClickRecompile}></lightning-button>
<lightning-button label="You have uncompiled classes, ask for recompilation!" title="You have uncompiled classes, ask for recompilation!" variant="brand-outline" class="slds-var-m-left_x-small" icon-name="utility:refresh" onclick={handleClickRecompile}></lightning-button>
</lightning-layout-item>
</template>
<lightning-layout-item>
Expand Down
1 change: 1 addition & 0 deletions force-app/main/default/lwc/orgcheckApp/orgcheckApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ export default class OrgCheckApp extends LightningElement {
{ label: 'API Version', type: 'numeric', data: { value: 'apiVersion' }, modifier: { valueIfEmpty: 'No version.' }},
{ label: 'Package', type: 'text', data: { value: 'package' }},
{ label: 'Size', type: 'numeric', data: { value: 'length' }},
{ label: 'Nb Asserts', type: 'numeric', data: { value: 'nbSystemAsserts' }, modifier: { valueIfEmpty: 'No direct usage of Assert.Xxx() or System.assertXxx().' }},
{ label: 'Methods', type: 'numeric', data: { value: 'methodsCount' }},
{ label: 'Inner Classes', type: 'numeric', data: { value: 'innerClassesCount' }},
{ label: 'Sharing', type: 'text', data: { value: 'specifiedSharing' }, modifier: { valueIfEmpty: 'Not specified.' }},
Expand Down

0 comments on commit 2c8ac66

Please sign in to comment.