Skip to content

Commit

Permalink
Feat/custom test scene (#225)
Browse files Browse the repository at this point in the history
* feat(core): adds custom test scene support

* add docs

* change TestsScene name

* Fix test
  • Loading branch information
georgejecook authored May 12, 2023
1 parent 1f6a108 commit 169dc9d
Show file tree
Hide file tree
Showing 10 changed files with 1,605 additions and 357 deletions.
2 changes: 1 addition & 1 deletion bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class FileFactory {
dest: s`${this.targetCompsPath}/RooibosScene.xml`
};
this.addedFrameworkFiles.push(
program.setFile(entry, this.createTestXML('TestsScene', 'Scene'))
program.setFile(entry, this.createTestXML('RooibosScene', 'Scene'))
);
}

Expand Down
1 change: 1 addition & 0 deletions bsc-plugin/src/lib/rooibos/RooibosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface RooibosConfig {
catchCrashes?: boolean;
sendHomeOnFinish?: boolean;
keepAppOpen?: boolean;
testSceneName?: string;

/**
* The path to the folder where the rooibos framework roku files reside.
Expand Down
4 changes: 2 additions & 2 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class RooibosSession {
}
}
if (mainFunction) {
editor.addToArray(mainFunction.func.body.statements, 0, new RawCodeStatement(`Rooibos_init()`));
editor.addToArray(mainFunction.func.body.statements, 0, new RawCodeStatement(`Rooibos_init("${this.config?.testSceneName ?? 'RooibosScene'}")`));
}
}
public addLaunchHookFileIfNotPresent() {
Expand All @@ -80,7 +80,7 @@ export class RooibosSession {
diagnosticNoStagingDir(files[0]);
} else {
const filePath = path.join(this._builder.options.stagingDir ?? this._builder.options.stagingFolderPath, 'source/rooibosMain.brs');
fsExtra.writeFileSync(filePath, `function main()\n Rooibos_init()\nend function`);
fsExtra.writeFileSync(filePath, `function main()\n Rooibos_init("${this.config?.testSceneName ?? 'RooibosScene'}")\nend function`);

}
}
Expand Down
53 changes: 50 additions & 3 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('RooibosPlugin', () => {
getContents('rooibosMain.brs')
).to.eql(undent`
function main()
Rooibos_init()
Rooibos_init("RooibosScene")
end function
`);
expect(
Expand Down Expand Up @@ -501,7 +501,7 @@ describe('RooibosPlugin', () => {
getContents('rooibosMain.brs')
).to.eql(undent`
function main()
Rooibos_init()
Rooibos_init("RooibosScene")
end function
`);
});
Expand All @@ -521,7 +521,54 @@ describe('RooibosPlugin', () => {
getContents('main.brs')
).to.eql(undent`
sub main()
Rooibos_init()
Rooibos_init("RooibosScene")
print "main"
end sub
`);
//the AST should not have been permanently modified
const statements = (file.parser.statements[0] as FunctionStatement).func.body.statements;
expect(statements).to.be.lengthOf(1);
expect(statements[0]).to.be.instanceof(PrintStatement);
});


it('adds launch hook with custom scene', async () => {
options = {
rootDir: _rootDir,
stagingFolderPath: _stagingFolderPath,
stagingDir: _stagingFolderPath,
rooibos: {
testSceneName: 'CustomRooibosScene'
}
};
plugin = new RooibosPlugin();
fsExtra.ensureDirSync(_stagingFolderPath);
fsExtra.ensureDirSync(_rootDir);
fsExtra.ensureDirSync(tmpPath);

builder = new ProgramBuilder();
builder.options = util.normalizeAndResolveConfig(options);
builder.program = new Program(builder.options);
program = builder.program;
program.plugins.add(plugin);
program.createSourceScope(); //ensure source scope is created
plugin.beforeProgramCreate(builder);
plugin.fileFactory['options'].frameworkSourcePath = path.resolve(path.join('../framework/src/source'));
plugin.afterProgramCreate(program);
// program.validate();
const file = program.setFile<BrsFile>('source/main.bs', `
sub main()
print "main"
end sub
`);
program.validate();
await builder.transpile();

expect(
getContents('main.brs')
).to.eql(undent`
sub main()
Rooibos_init("CustomRooibosScene")
print "main"
end sub
`);
Expand Down
3 changes: 3 additions & 0 deletions bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class RooibosPlugin implements CompilerPlugin {
if (config.keepAppOpen === undefined) {
config.keepAppOpen = true;
}
if (config.testSceneName === undefined) {
config.testSceneName = 'RooibosScene';
}
//ignore roku modules by default
if (config.includeFilters === undefined) {
config.includeFilters = [
Expand Down
Loading

0 comments on commit 169dc9d

Please sign in to comment.