Skip to content

Commit

Permalink
A few updates to simplify config (#292)
Browse files Browse the repository at this point in the history
* simplifies some config files

* using logger instead of console.log
  • Loading branch information
markwpearce authored Aug 19, 2024
1 parent 96d2167 commit e4f8614
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bsc-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RawCodeStatement } from './RawCodeStatement';
import { BrsTranspileState } from 'brighterscript/dist/parser/BrsTranspileState';
import { RawCodeExpression } from './RawCodeExpression';
import type { FileFactory } from './FileFactory';
import { RooibosLogPrefix } from '../utils/Diagnostics';

export enum CodeCoverageLineType {
noCode = 0,
Expand Down Expand Up @@ -44,7 +45,7 @@ export class CodeCoverageProcessor {
this.fileFactory = fileFactory;
try {
} catch (e) {
console.log('Error:', e.stack);
builder.logger.error(RooibosLogPrefix, 'Error:', e.stack);
}
}

Expand Down Expand Up @@ -76,7 +77,7 @@ export class CodeCoverageProcessor {
this.executableLines = new Map<number, Statement>();
this.processedStatements = new Set<Statement>();
this.astEditor = astEditor;
console.log('Processing file:', this.fileId, file.pkgPath);
file.program.logger.info(RooibosLogPrefix, 'Processing file for code coverage:', this.fileId, file.pkgPath);

file.ast.walk(createVisitor({
ForStatement: (ds, parent, owner, key) => {
Expand Down
6 changes: 3 additions & 3 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import type { TestSuite } from './TestSuite';
import { RooibosLogPrefix } from '../utils/Diagnostics';

export class FileFactory {
private coverageComponentXmlTemplate: string;
Expand All @@ -24,7 +25,6 @@ export class FileFactory {
this.options.frameworkSourcePath = s`${__dirname}/../framework`;
}
}

this.coverageComponentXmlTemplate = fs.readFileSync(path.join(this.options.frameworkSourcePath, 'CodeCoverage.xml'), 'utf8');
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.options.frameworkSourcePath, 'CodeCoverage.brs'), 'utf8');
}
Expand Down Expand Up @@ -136,7 +136,7 @@ export class FileFactory {
this.addedFrameworkFiles.push(file);
return file;
} catch (error) {
program.logger.error(`Error adding framework file: ${entry.dest} : ${error.message}`);
program.logger.error(RooibosLogPrefix, `Error adding framework file: ${entry.dest} : ${error.message}`);
}
}

Expand All @@ -147,7 +147,7 @@ export class FileFactory {
contents
);
} catch (error) {
program.logger.error(`Error adding framework file: ${path} : ${error.message}`);
program.logger.error(RooibosLogPrefix, `Error adding framework file: ${path} : ${error.message}`);
}
}
}
4 changes: 2 additions & 2 deletions bsc-plugin/src/lib/rooibos/MockUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { RooibosConfig } from './RooibosConfig';
import type { FileFactory } from './FileFactory';
import undent from 'undent';
import type { RooibosSession } from './RooibosSession';
import { diagnosticErrorProcessingFile } from '../utils/Diagnostics';
import { diagnosticErrorProcessingFile, RooibosLogPrefix } from '../utils/Diagnostics';
import type { TestCase } from './TestCase';
import type { TestSuite } from './TestSuite';
import { functionRequiresReturnValue, getAllDottedGetParts, getFileLookups, getScopeForSuite } from './Utils';
Expand Down Expand Up @@ -167,7 +167,7 @@ export class MockUtil {
walkMode: brighterscript.WalkMode.visitStatementsRecursive
});
} catch (e) {
this.builder.program.logger.error('Error processing global method mocks', e);
this.builder.program.logger.error(RooibosLogPrefix, 'Error processing global method mocks', e);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
diagnosticErrorProcessingFile(testSuite.file, e.message);
}
Expand Down
6 changes: 3 additions & 3 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SessionInfo } from './RooibosSessionInfo';
import { TestSuiteBuilder } from './TestSuiteBuilder';
import type { FileFactory } from './FileFactory';
import type { TestSuite } from './TestSuite';
import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir } from '../utils/Diagnostics';
import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir, RooibosLogPrefix } from '../utils/Diagnostics';
import undent from 'undent';
import * as fsExtra from 'fs-extra';
import type { MockUtil } from './MockUtil';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class RooibosSession {
const resultFiles = this.createNodeFiles(program);

if (this.config.isGlobalMethodMockingEnabled && this.config.isGlobalMethodMockingEfficientMode) {
program.logger.info('Efficient global stubbing is enabled');
program.logger.info(RooibosLogPrefix, 'Efficient global stubbing is enabled');
this.namespaceLookup = this.getNamespaces(program);
for (let testSuite of this.sessionInfo.testSuitesToRun) {
mockUtil.gatherGlobalMethodMocks(testSuite);
Expand Down Expand Up @@ -121,7 +121,7 @@ export class RooibosSession {
if (!mainFunction) {
diagnosticWarnNoMainFound(files[0] as BrsFile);
if (!this._builder.options.stagingDir) {
this._builder.program.logger.error('Rooibos requires that stagingDir bsconfig option is set');
this._builder.program.logger.error(RooibosLogPrefix, 'Rooibos requires that stagingDir bsconfig option is set');
diagnosticNoStagingDir(files[0] as BrsFile);
} else {
const filePath = path.join(this._builder.options.stagingDir, 'source/rooibosMain.brs');
Expand Down
3 changes: 3 additions & 0 deletions bsc-plugin/src/lib/utils/Diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { DiagnosticSeverity, Range, util } from 'brighterscript';

import type { AnnotationType, RooibosAnnotation } from '../rooibos/Annotation';


export const RooibosLogPrefix = '[Rooibos]';

function addDiagnostic(
file: BrsFile,
code: number,
Expand Down
5 changes: 0 additions & 5 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('a');
Expand All @@ -1950,7 +1949,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('b');
Expand All @@ -1961,7 +1959,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('b');
Expand All @@ -1973,7 +1970,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.be.empty;
});
Expand All @@ -1983,7 +1979,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('a');
Expand Down
8 changes: 3 additions & 5 deletions bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as minimatch from 'minimatch';
import * as path from 'path';
import { MockUtil } from './lib/rooibos/MockUtil';
import { getScopeForSuite } from './lib/rooibos/Utils';
import { RooibosLogPrefix } from './lib/utils/Diagnostics';

export class RooibosPlugin implements CompilerPlugin {

Expand Down Expand Up @@ -137,15 +138,14 @@ export class RooibosPlugin implements CompilerPlugin {
if (!(isBrsFile(file) || isXmlFile(file)) || this.shouldSkipFile(file)) {
continue;
}
// console.log('afp', file.pkgPath);
if (util.pathToUri(file.srcPath).includes('/rooibos/bsc-plugin/dist/framework')) {
// eslint-disable-next-line @typescript-eslint/dot-notation
return;
}
if (this.fileFactory.isIgnoredFile(file) || !this.shouldSearchInFileForTests(file)) {
return;
}
console.log('processing ', file.pkgPath);
event.program.logger.log(RooibosLogPrefix, 'Processing test file', file.pkgPath);

if (isBrsFile(file)) {
// Add the node test component so brighter script can validate the test files
Expand Down Expand Up @@ -178,7 +178,7 @@ export class RooibosPlugin implements CompilerPlugin {
const scope = getScopeForSuite(testSuite);
let noEarlyExit = testSuite.annotation.noEarlyExit;
if (noEarlyExit) {
event.program.logger.warn(`TestSuite "${testSuite.name}" is marked as noEarlyExit`);
event.program.logger.warn(RooibosLogPrefix, `TestSuite "${testSuite.name}" is marked as noEarlyExit`);
}

const modifiedTestCases = new Set();
Expand Down Expand Up @@ -211,7 +211,6 @@ export class RooibosPlugin implements CompilerPlugin {
}

afterProgramValidate(event: AfterProgramValidateEvent) {
// console.log('bpv');
this.session.updateSessionStats();
for (let testSuite of [...this.session.sessionInfo.testSuites.values()]) {
testSuite.validate();
Expand All @@ -233,7 +232,6 @@ export class RooibosPlugin implements CompilerPlugin {
}
}
}
// console.log('including ', file.pkgPath);
return true;
}
shouldAddCodeCoverageToFile(file: BscFile) {
Expand Down
1 change: 0 additions & 1 deletion framework/bslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"condition-style": "no-group",
"named-function-style": "off",
"anon-function-style": "off",
"type-annotations": "off",
"assign-all-paths": "off",
"unsafe-path-loop": "error",
"unsafe-iterators": "error",
Expand Down
11 changes: 4 additions & 7 deletions framework/src/source/TestGroup.bs
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,24 @@ namespace rooibos
m.testSuite.testGroupDone()
end function

private function runSuiteFunction(methodName, defaultMethodName, test = invalid)
private function runSuiteFunction(methodName as string, defaultMethodName as string, testInstance = invalid as Test) as boolean

if methodName = invalid or methodName = ""
methodName = defaultMethodName
end if
if m.testSuite.catchCrashes and not m.testSuite.noCatch and not (test <> invalid and test.noCatch)
if m.testSuite.catchCrashes and not m.testSuite.noCatch and not (testInstance <> invalid and testInstance.noCatch)
try
m.testSuite[methodName]()
return true
catch error
if test <> invalid
'bs:disable-next-line
test.result.crash("function " + methodName + "crashed!", error)
if testInstance <> invalid
testInstance.result.crash("function " + methodName + "crashed!", error)
end if
end try
else
m.testSuite[methodName]()
return true
end if

'bs:disable-next-line
return false
end function

Expand Down
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"description": "simple, flexible, fun brightscript test framework for roku scenegraph apps",
"scripts": {
"postinstall": "npm --prefix ./bsc-plugin install && npm --prefix ./tests install",
"build": "cd bsc-plugin && npm run build",
"test": "cd bsc-plugin && npm run test",
"rokutest": "cd tests && npm run test"
"clean": "npm --prefix ./bsc-plugin run clean && npm --prefix ./tests run clean",
"build": "npm --prefix ./bsc-plugin run build",
"test": "npm --prefix ./bsc-plugin run test",
"rokutest": "npm --prefix ./tests run test"
},
"files": [
"dist/**/!(manifest)*"
],
"devDependencies": {
"@rokucommunity/bslint": "^1.0.0-alpha.36",
"@types/chai": "^4.1.2",
Expand Down Expand Up @@ -38,9 +36,5 @@
"bugs": {
"url": "https://github.com/rokucommunity/rooibos/issues"
},
"ropm": {
"rootDir": "src",
"packageRootDir": "dist"
},
"homepage": "https://github.com/rokucommunity/rooibos#readme"
}
1 change: 0 additions & 1 deletion rooibos.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"titleBar.inactiveBackground": "#f1ee2f",
"titleBar.inactiveForeground": "#000000"
},
"cSpell.words": ["Inifnite"],
"brightscript.bsdk": "node_modules/brighterscript"
}
}
4 changes: 1 addition & 3 deletions tests/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"files": [
"manifest",
"source/**/*.*",
"components/**/*.*",
{ "src": "../../framework/src/source/**/*", "dest": "source/rooibos" },
{ "src": "../../framework/src/source/RooibosScene.xml", "dest": "components/rooibos/RooibosScene.xml" }
"components/**/*.*"
],
"autoImportComponentScript": true,
"createPackage": false,
Expand Down
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "simple, flexible, fun brightscript test framework for roku scenegraph apps - tests",
"scripts": {
"build": "bsc",
"clean": "rm -rf build && rm -rf out",
"watch": "npx bsc --project bsconfig.json --watch",
"test": "npm run build && npx ts-node ./scripts/runRooibosTests.ts --verbose"
},
Expand Down

0 comments on commit e4f8614

Please sign in to comment.