diff --git a/packages/code-analyzer-core/src/code-analyzer.ts b/packages/code-analyzer-core/src/code-analyzer.ts index 5b05f6b4..cdd66a8d 100644 --- a/packages/code-analyzer-core/src/code-analyzer.ts +++ b/packages/code-analyzer-core/src/code-analyzer.ts @@ -64,6 +64,10 @@ export class CodeAnalyzer { const runResults: RunResultsImpl = new RunResultsImpl(); for (const engineName of ruleSelection.getEngineNames()) { + this.emitEvent({ + type: EventType.EngineProgressEvent, timestamp: this.clock.now(), engineName: engineName, percentComplete: 0 + }); + const rulesToRun: string[] = ruleSelection.getRulesFor(engineName).map(r => r.getName()); this.emitLogEvent(LogLevel.Debug, getMessage('RunningEngineWithRules', engineName, JSON.stringify(rulesToRun))); const engine: engApi.Engine = this.getEngine(engineName); @@ -71,10 +75,12 @@ export class CodeAnalyzer { validateEngineRunResults(engineName, apiEngineRunResults, ruleSelection); const engineRunResults: EngineRunResults = new EngineRunResultsImpl(engineName, apiEngineRunResults, ruleSelection); runResults.addEngineRunResults(engineRunResults); + + this.emitEvent({ + type: EventType.EngineProgressEvent, timestamp: this.clock.now(), engineName: engineName, percentComplete: 100 + }); this.emitEvent({ - type: EventType.EngineResultsEvent, - timestamp: this.clock.now(), - results: engineRunResults + type: EventType.EngineResultsEvent, timestamp: this.clock.now(), results: engineRunResults }); } diff --git a/packages/code-analyzer-core/test/run.test.ts b/packages/code-analyzer-core/test/run.test.ts index bb61a471..531a224c 100644 --- a/packages/code-analyzer-core/test/run.test.ts +++ b/packages/code-analyzer-core/test/run.test.ts @@ -549,18 +549,18 @@ describe("Tests for the run method of CodeAnalyzer", () => { message: "someMiscInfoMessageFromStubEngine2" }); - - expect(engineProgressEvents).toHaveLength(6); - for (const expectedPercentComplete of [0, 50, 100]) { - expect(engineProgressEvents).toContainEqual({ + expect(engineProgressEvents).toHaveLength(9); + let i = 0; // Using this to ensure the order of events + for (const expectedPercentComplete of [0, 0, 50, 100, 100]) { // Core and stubEngine1 both give us 0 and 100 + expect(engineProgressEvents[i++]).toEqual({ type: EventType.EngineProgressEvent, timestamp: sampleTimestamp, engineName: "stubEngine1", percentComplete: expectedPercentComplete }); } - for (const expectedPercentComplete of [5, 63, 100]) { - expect(engineProgressEvents).toContainEqual({ + for (const expectedPercentComplete of [0, 5, 63, 100]) { // Only Core gives us 0 and 100 + expect(engineProgressEvents[i++]).toEqual({ type: EventType.EngineProgressEvent, timestamp: sampleTimestamp, engineName: "stubEngine2", diff --git a/packages/code-analyzer-core/test/stubs.ts b/packages/code-analyzer-core/test/stubs.ts index 32e7b835..0fc57c49 100644 --- a/packages/code-analyzer-core/test/stubs.ts +++ b/packages/code-analyzer-core/test/stubs.ts @@ -100,6 +100,7 @@ export class StubEngine1 extends engApi.Engine { } runRules(ruleNames: string[], runOptions: engApi.RunOptions): engApi.EngineRunResults { + this.runRulesCallHistory.push({ruleNames, runOptions}); this.emitEvent({ type: engApi.EventType.ProgressEvent, percentComplete: 0 @@ -113,7 +114,6 @@ export class StubEngine1 extends engApi.Engine { type: engApi.EventType.ProgressEvent, percentComplete: 50 }); - this.runRulesCallHistory.push({ruleNames, runOptions}); this.emitEvent({ type: engApi.EventType.ProgressEvent, percentComplete: 100 @@ -169,6 +169,7 @@ export class StubEngine2 extends engApi.Engine { } runRules(ruleNames: string[], runOptions: engApi.RunOptions): engApi.EngineRunResults { + this.runRulesCallHistory.push({ruleNames, runOptions}); this.emitEvent({ type: engApi.EventType.LogEvent, message: "someMiscInfoMessageFromStubEngine2", @@ -182,11 +183,6 @@ export class StubEngine2 extends engApi.Engine { type: engApi.EventType.ProgressEvent, percentComplete: 63 }); - this.runRulesCallHistory.push({ruleNames, runOptions}); - this.emitEvent({ - type: engApi.EventType.ProgressEvent, - percentComplete: 100 - }); return this.resultsToReturn; } }