8
8
EventType ,
9
9
LogEvent ,
10
10
LogLevel ,
11
+ PathPoint ,
11
12
RuleDescription ,
12
13
RunOptions ,
13
14
RunRulesProgressEvent ,
@@ -182,10 +183,10 @@ describe('SfgeEngine', () => {
182
183
path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' , 'SomeOtherClass.cls' )
183
184
]
184
185
}
185
- ] ) ( 'When workspace is $case, those violations are returned' , async ( ) => {
186
+ ] ) ( 'When workspace is $case, those violations are returned' , async ( { workspacePaths } ) => {
186
187
// ====== SETUP ======
187
188
const engine : SfgeEngine = new SfgeEngine ( DEFAULT_SFGE_ENGINE_CONFIG , fixedClock ) ;
188
- const workspace : Workspace = new Workspace ( [ path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ] ) ;
189
+ const workspace : Workspace = new Workspace ( workspacePaths ) ;
189
190
const progressEvents : RunRulesProgressEvent [ ] = [ ] ;
190
191
engine . onEvent ( EventType . RunRulesProgressEvent , ( e : RunRulesProgressEvent ) => progressEvents . push ( e ) ) ;
191
192
const ruleNames : string [ ] = [ 'ApexFlsViolationRule' , 'UseWithSharingOnDatabaseOperation' , 'UnimplementedTypeRule' , 'RemoveUnusedMethod' ] ;
@@ -194,7 +195,46 @@ describe('SfgeEngine', () => {
194
195
const results : EngineRunResults = await engine . runRules ( ruleNames , createRunOptions ( workspace ) ) ;
195
196
196
197
// ====== ASSERTIONS ======
197
- await expectResultsToMatchGoldfile ( results , 'all_sampleRelevantWorkspace_violations.goldfile.json' , path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
198
+ await expectResultsToMatchGoldfile ( results , path . join ( 'sampleRelevantWorkspace' , 'all_violations.goldfile.json' ) , path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
199
+ const progressPercents : number [ ] = progressEvents . map ( pe => pe . percentComplete ) ;
200
+ expect ( progressPercents [ 0 ] ) . toEqual ( 2 ) ;
201
+ expect ( progressPercents [ progressPercents . length - 1 ] ) . toEqual ( 100 ) ;
202
+ expectProgressEventsToAscend ( progressPercents ) ;
203
+ } ) ;
204
+
205
+ it . each ( [
206
+ {
207
+ case : 'a file that violates the selected rules' ,
208
+ pathStartPoints : [
209
+ {
210
+ file : path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace2' , 'EntryClass1.cls' )
211
+ }
212
+ ] ,
213
+ goldfile : 'EntryClass1_violations.goldfile.json'
214
+ } ,
215
+ {
216
+ case : 'a single method that violates the selected rules' ,
217
+ pathStartPoints : [
218
+ {
219
+ file : path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace2' , 'EntryClass1.cls' ) ,
220
+ methodName : 'entryPointMethod1'
221
+ }
222
+ ] ,
223
+ goldfile : 'EntryClass1_entryPointMethod1_violations.goldfile.json'
224
+ }
225
+ ] ) ( 'When path start point is $case, the appropriate violations are returned' , async ( { pathStartPoints, goldfile} ) => {
226
+ // ====== SETUP ======
227
+ const engine : SfgeEngine = new SfgeEngine ( DEFAULT_SFGE_ENGINE_CONFIG , fixedClock ) ;
228
+ const workspace : Workspace = new Workspace ( [ path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace2' ) ] ) ;
229
+ const progressEvents : RunRulesProgressEvent [ ] = [ ] ;
230
+ engine . onEvent ( EventType . RunRulesProgressEvent , ( e : RunRulesProgressEvent ) => progressEvents . push ( e ) ) ;
231
+ const ruleNames : string [ ] = [ 'ApexFlsViolationRule' , 'UseWithSharingOnDatabaseOperation' , 'UnimplementedTypeRule' , 'RemoveUnusedMethod' ] ;
232
+
233
+ // ====== TESTED BEHAVIOR ======
234
+ const results : EngineRunResults = await engine . runRules ( ruleNames , createRunOptions ( workspace , pathStartPoints ) ) ;
235
+
236
+ // ====== ASSERTIONS ======
237
+ await expectResultsToMatchGoldfile ( results , path . join ( 'sampleRelevantWorkspace2' , goldfile ) , path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace2' ) ) ;
198
238
const progressPercents : number [ ] = progressEvents . map ( pe => pe . percentComplete ) ;
199
239
expect ( progressPercents [ 0 ] ) . toEqual ( 2 ) ;
200
240
expect ( progressPercents [ progressPercents . length - 1 ] ) . toEqual ( 100 ) ;
@@ -213,7 +253,7 @@ describe('SfgeEngine', () => {
213
253
const results : EngineRunResults = await engine . runRules ( ruleNames , createRunOptions ( workspace ) ) ;
214
254
215
255
// ====== ASSERTIONS ======
216
- await expectResultsToMatchGoldfile ( results , 'ApexFlsViolationRule_sampleRelevantWorkspace_violations .goldfile.json', path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
256
+ await expectResultsToMatchGoldfile ( results , path . join ( 'sampleRelevantWorkspace' , 'ApexFlsViolationRule_violations .goldfile.json') , path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
217
257
const expectedProgressDescriptors : { percent : number , message ?: string } [ ] = [
218
258
{ percent : 2 , message : undefined } ,
219
259
{ percent : 2.3 , message : undefined } ,
@@ -292,7 +332,7 @@ describe('SfgeEngine', () => {
292
332
const results : EngineRunResults = await engine . runRules ( ruleNames , createRunOptions ( workspace ) ) ;
293
333
294
334
// ====== ASSERTIONS ======
295
- await expectResultsToMatchGoldfile ( results , 'ApexFlsViolationRule_sampleRelevantWorkspace_violations .goldfile.json', path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
335
+ await expectResultsToMatchGoldfile ( results , path . join ( 'sampleRelevantWorkspace' , 'ApexFlsViolationRule_violations .goldfile.json') , path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ) ;
296
336
const warningLogEvents : LogEvent [ ] = logEvents . filter ( e => e . logLevel === LogLevel . Warn ) ;
297
337
expect ( warningLogEvents . length ) . toBeGreaterThanOrEqual ( 1 ) ;
298
338
expect ( warningLogEvents [ 0 ] . message ) . toContain ( `Specified workspace is missing 1 possibly-relevant file(s) from the folder ${ path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) } .` ) ;
@@ -333,9 +373,10 @@ function createDescribeOptions(workspace?: Workspace): DescribeOptions {
333
373
} ;
334
374
}
335
375
336
- function createRunOptions ( workspace : Workspace ) : RunOptions {
376
+ function createRunOptions ( workspace : Workspace , pathStartPoints ?: PathPoint [ ] ) : RunOptions {
337
377
return {
338
378
logFolder : os . tmpdir ( ) ,
339
- workspace
379
+ workspace,
380
+ pathStartPoints
340
381
} ;
341
382
}
0 commit comments