Skip to content

Commit

Permalink
Fix Rooibos_init injection causing duplicate calls (#247)
Browse files Browse the repository at this point in the history
* Remove unused imports

* Introduce init call search and check
  • Loading branch information
luis-soares-sky authored Jan 7, 2024
1 parent 9eea489 commit fc4065a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import type { BrsFile, BscFile, ClassStatement, FunctionStatement, NamespaceStatement, Program, ProgramBuilder, Scope, Statement } from 'brighterscript';
import { isBrsFile, ParseMode, util } from 'brighterscript';
import { isBrsFile, isCallExpression, isVariableExpression, ParseMode, WalkMode } from 'brighterscript';
import type { AstEditor } from 'brighterscript/dist/astUtils/AstEditor';
import type { RooibosConfig } from './RooibosConfig';
import { SessionInfo } from './RooibosSessionInfo';
Expand All @@ -10,7 +10,6 @@ import type { FileFactory } from './FileFactory';
import type { TestSuite } from './TestSuite';
import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir } from '../utils/Diagnostics';
import undent from 'undent';
import { BrsTranspileState } from 'brighterscript/dist/parser/BrsTranspileState';
import * as fsExtra from 'fs-extra';
import type { MockUtil } from './MockUtil';

Expand Down Expand Up @@ -89,7 +88,12 @@ export class RooibosSession {
}
}
if (mainFunction) {
editor.addToArray(mainFunction.func.body.statements, 0, new RawCodeStatement(`Rooibos_init("${this.config?.testSceneName ?? 'RooibosScene'}")`));
const initCall = mainFunction.func.body.findChild(f => isCallExpression(f) && isVariableExpression(f.callee) && f.callee.name.text.toLowerCase() === 'rooibos_init', {
walkMode: WalkMode.visitAllRecursive
});
if (!initCall) {
editor.addToArray(mainFunction.func.body.statements, 0, new RawCodeStatement(`Rooibos_init("${this.config?.testSceneName ?? 'RooibosScene'}")`));
}
}
}
addLaunchHookFileIfNotPresent() {
Expand Down

0 comments on commit fc4065a

Please sign in to comment.