Skip to content

Commit

Permalink
Review Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-carter-at-sf committed May 28, 2024
1 parent 78bd1d2 commit 82cf0dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 9 additions & 3 deletions packages/code-analyzer-core/src/code-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ export class CodeAnalyzer {

const runResults: RunResultsImpl = new RunResultsImpl();
for (const engineName of ruleSelection.getEngineNames()) {
this.emitEvent<EngineProgressEvent>({
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);
const apiEngineRunResults: engApi.EngineRunResults = engine.runRules(rulesToRun, engineRunOptions);
validateEngineRunResults(engineName, apiEngineRunResults, ruleSelection);
const engineRunResults: EngineRunResults = new EngineRunResultsImpl(engineName, apiEngineRunResults, ruleSelection);
runResults.addEngineRunResults(engineRunResults);

this.emitEvent<EngineProgressEvent>({
type: EventType.EngineProgressEvent, timestamp: this.clock.now(), engineName: engineName, percentComplete: 100
});
this.emitEvent<EngineResultsEvent>({
type: EventType.EngineResultsEvent,
timestamp: this.clock.now(),
results: engineRunResults
type: EventType.EngineResultsEvent, timestamp: this.clock.now(), results: engineRunResults
});
}

Expand Down
12 changes: 6 additions & 6 deletions packages/code-analyzer-core/test/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions packages/code-analyzer-core/test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<engApi.ProgressEvent>({
type: engApi.EventType.ProgressEvent,
percentComplete: 0
Expand All @@ -113,7 +114,6 @@ export class StubEngine1 extends engApi.Engine {
type: engApi.EventType.ProgressEvent,
percentComplete: 50
});
this.runRulesCallHistory.push({ruleNames, runOptions});
this.emitEvent<engApi.ProgressEvent>({
type: engApi.EventType.ProgressEvent,
percentComplete: 100
Expand Down Expand Up @@ -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<engApi.LogEvent>({
type: engApi.EventType.LogEvent,
message: "someMiscInfoMessageFromStubEngine2",
Expand All @@ -182,11 +183,6 @@ export class StubEngine2 extends engApi.Engine {
type: engApi.EventType.ProgressEvent,
percentComplete: 63
});
this.runRulesCallHistory.push({ruleNames, runOptions});
this.emitEvent<engApi.ProgressEvent>({
type: engApi.EventType.ProgressEvent,
percentComplete: 100
});
return this.resultsToReturn;
}
}
Expand Down

0 comments on commit 82cf0dc

Please sign in to comment.