From e4f86141e17c84031c88aa17c0c869a573258c10 Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Mon, 19 Aug 2024 10:16:00 -0300 Subject: [PATCH] A few updates to simplify config (#292) * simplifies some config files * using logger instead of console.log --- bsc-plugin/package-lock.json | 4 ++-- .../src/lib/rooibos/CodeCoverageProcessor.ts | 5 +++-- bsc-plugin/src/lib/rooibos/FileFactory.ts | 6 +++--- bsc-plugin/src/lib/rooibos/MockUtil.ts | 4 ++-- bsc-plugin/src/lib/rooibos/RooibosSession.ts | 6 +++--- bsc-plugin/src/lib/utils/Diagnostics.ts | 3 +++ bsc-plugin/src/plugin.spec.ts | 5 ----- bsc-plugin/src/plugin.ts | 8 +++----- framework/bslint.json | 1 - framework/src/source/TestGroup.bs | 11 ++++------- package.json | 14 ++++---------- rooibos.code-workspace | 1 - tests/bsconfig.json | 4 +--- tests/package.json | 1 + 14 files changed, 29 insertions(+), 44 deletions(-) diff --git a/bsc-plugin/package-lock.json b/bsc-plugin/package-lock.json index 75b624e..c3a4ea5 100644 --- a/bsc-plugin/package-lock.json +++ b/bsc-plugin/package-lock.json @@ -1,12 +1,12 @@ { "name": "rooibos-roku", - "version": "5.12.0", + "version": "6.0.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rooibos-roku", - "version": "5.12.0", + "version": "6.0.0-alpha.1", "license": "ISC", "dependencies": { "source-map": "^0.7.3", diff --git a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts index e07ec47..ff10764 100644 --- a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts +++ b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts @@ -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, @@ -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); } } @@ -76,7 +77,7 @@ export class CodeCoverageProcessor { this.executableLines = new Map(); this.processedStatements = new Set(); 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) => { diff --git a/bsc-plugin/src/lib/rooibos/FileFactory.ts b/bsc-plugin/src/lib/rooibos/FileFactory.ts index 1da8151..6ea7fbd 100644 --- a/bsc-plugin/src/lib/rooibos/FileFactory.ts +++ b/bsc-plugin/src/lib/rooibos/FileFactory.ts @@ -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; @@ -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'); } @@ -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}`); } } @@ -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}`); } } } diff --git a/bsc-plugin/src/lib/rooibos/MockUtil.ts b/bsc-plugin/src/lib/rooibos/MockUtil.ts index c816022..2346715 100644 --- a/bsc-plugin/src/lib/rooibos/MockUtil.ts +++ b/bsc-plugin/src/lib/rooibos/MockUtil.ts @@ -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'; @@ -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); } diff --git a/bsc-plugin/src/lib/rooibos/RooibosSession.ts b/bsc-plugin/src/lib/rooibos/RooibosSession.ts index e0a4070..2c2957e 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSession.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSession.ts @@ -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'; @@ -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); @@ -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'); diff --git a/bsc-plugin/src/lib/utils/Diagnostics.ts b/bsc-plugin/src/lib/utils/Diagnostics.ts index bed264a..f090a75 100644 --- a/bsc-plugin/src/lib/utils/Diagnostics.ts +++ b/bsc-plugin/src/lib/utils/Diagnostics.ts @@ -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, diff --git a/bsc-plugin/src/plugin.spec.ts b/bsc-plugin/src/plugin.spec.ts index 3f1de8f..2d06dfc 100644 --- a/bsc-plugin/src/plugin.spec.ts +++ b/bsc-plugin/src/plugin.spec.ts @@ -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'); @@ -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'); @@ -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'); @@ -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; }); @@ -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'); diff --git a/bsc-plugin/src/plugin.ts b/bsc-plugin/src/plugin.ts index 6161aff..1969be9 100644 --- a/bsc-plugin/src/plugin.ts +++ b/bsc-plugin/src/plugin.ts @@ -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 { @@ -137,7 +138,6 @@ 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; @@ -145,7 +145,7 @@ export class RooibosPlugin implements CompilerPlugin { 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 @@ -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(); @@ -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(); @@ -233,7 +232,6 @@ export class RooibosPlugin implements CompilerPlugin { } } } - // console.log('including ', file.pkgPath); return true; } shouldAddCodeCoverageToFile(file: BscFile) { diff --git a/framework/bslint.json b/framework/bslint.json index 222f31d..d4cef1d 100644 --- a/framework/bslint.json +++ b/framework/bslint.json @@ -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", diff --git a/framework/src/source/TestGroup.bs b/framework/src/source/TestGroup.bs index 77220f9..1c25f3c 100644 --- a/framework/src/source/TestGroup.bs +++ b/framework/src/source/TestGroup.bs @@ -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 diff --git a/package.json b/package.json index a6c1e62..58a70a6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -38,9 +36,5 @@ "bugs": { "url": "https://github.com/rokucommunity/rooibos/issues" }, - "ropm": { - "rootDir": "src", - "packageRootDir": "dist" - }, "homepage": "https://github.com/rokucommunity/rooibos#readme" } diff --git a/rooibos.code-workspace b/rooibos.code-workspace index 182e9a6..2ad7ff7 100644 --- a/rooibos.code-workspace +++ b/rooibos.code-workspace @@ -29,7 +29,6 @@ "titleBar.inactiveBackground": "#f1ee2f", "titleBar.inactiveForeground": "#000000" }, - "cSpell.words": ["Inifnite"], "brightscript.bsdk": "node_modules/brighterscript" } } diff --git a/tests/bsconfig.json b/tests/bsconfig.json index 540bd08..0dfeb1b 100644 --- a/tests/bsconfig.json +++ b/tests/bsconfig.json @@ -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, diff --git a/tests/package.json b/tests/package.json index 5814e4c..7518066 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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" },