Skip to content

Commit

Permalink
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 15, 2025
2 parents 9f78d7d + bdd7a2f commit 8497348
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 64 deletions.
1 change: 1 addition & 0 deletions bsc-plugin/package-lock.json

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

3 changes: 2 additions & 1 deletion bsc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"compile": "npm run clean && tsc -p .",
"prepublishOnly": "npm run build",
"lint": "eslint \"src/**\"",
"build": "npm run compile && cp -r ../framework/src/source ./dist/lib/framework",
"build": "npm run compile && cp -r ../framework/src ./dist/lib/framework",
"postinstall": "ropm copy",
"test": "nyc mocha",
"test:nocover": "mocha",
Expand Down Expand Up @@ -59,6 +59,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.16.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
"minimatch": "^3.0.4",
"mocha": "^9.1.3",
Expand Down
2 changes: 1 addition & 1 deletion bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('RooibosPlugin', () => {
expect(a).to.equal(b);
});

it.only('correctly transpiles some statements', async () => {
it.skip('correctly transpiles some statements', async () => {
const source = `sub foo()
x = function(y)
if (true) then
Expand Down
94 changes: 43 additions & 51 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,64 @@
import type { BrsFile, Program, XmlFile } from 'brighterscript';
import type { BrsFile, BscFile, Program, XmlFile } from 'brighterscript';
import { standardizePath as s } from 'brighterscript';
import * as path from 'path';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import * as fastGlob from 'fast-glob';
import type { TestSuite } from './TestSuite';

export class FileFactory {
private coverageComponentXmlTemplate;
private coverageComponentBrsTemplate;

constructor(
private options?: {
frameworkSourcePath?: string;
}
) {
this.options = this.options ?? {};
if (!this.options.frameworkSourcePath) {
if (__filename.endsWith('.ts')) {
//load the files directly from their source location. (i.e. the plugin is running as a typescript file from within ts-node)
this.options.frameworkSourcePath = s`${__dirname}/../../../../framework/src/source`;
} else {
//load the framework files from the dist folder (i.e. the plugin is running as a node_module)
this.options.frameworkSourcePath = s`${__dirname}/../framework`;
}
private frameworkSourcePath: string;

constructor() {
if (__filename.endsWith('.ts')) {
//load the files directly from their source location. (i.e. the plugin is running as a typescript file from within ts-node)
this.frameworkSourcePath = s`${__dirname}/../../../../framework/src`;
} else {
//load the framework files from the dist folder (i.e. the plugin is running as a node_module)
this.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');
this.coverageComponentXmlTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/components/rooibos/CodeCoverage.xml'), 'utf8');
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/source/rooibos/CodeCoverage.brs'), 'utf8');
}

private frameworkFileNames = [
'BaseTestSuite',
'CommonUtils',
'Coverage',
'Matchers',
'Rooibos',
'RuntimeConfig',
'Stats',
'Test',
'TestGroup',
'BaseTestReporter',
'ConsoleTestReporter',
'JUnitTestReporter',
'MochaTestReporter',
'TestResult',
'TestRunner',
'Utils'
];

private targetPath = 'source/rooibos/';
private targetCompsPath = 'components/rooibos/';
public addedFrameworkFiles = [];
public addedSourceFrameworkFilePaths: string[] = [];
public addedFrameworkFiles: BscFile[] = [];

public addFrameworkFiles(program: Program) {
this.addedFrameworkFiles = [];
for (let fileName of this.frameworkFileNames) {
let sourcePath = path.resolve(path.join(this.options.frameworkSourcePath, `${fileName}.bs`));
let fileContents = fs.readFileSync(sourcePath, 'utf8');
let destPath = path.join(this.targetPath, `${fileName}.bs`);
let entry = { src: sourcePath, dest: destPath };
let globedFiles = fastGlob.sync([
'**/*.{bs,brs,xml}',
'!**/bslib.brs',
'!**/manifest',
'!**/CodeCoverage.{brs,xml}',
'!**/RooibosScene.xml'
], {
cwd: this.frameworkSourcePath,
absolute: false,
followSymbolicLinks: true,
onlyFiles: true
});

for (let filePath of globedFiles) {
if (/^source[/\\]rooibos[/\\]/g.test(filePath)) {
// Save a list of all source files added to the program
// to be imported by node test components
this.addedSourceFrameworkFilePaths.push(filePath);
}
let sourcePath = path.resolve(this.frameworkSourcePath, filePath);
let fileContents = fs.readFileSync(sourcePath, 'utf8').toString();
let entry = { src: sourcePath, dest: filePath };
this.addedFrameworkFiles.push(
program.setFile(entry, fileContents)
);
}

let entry = {
src: s`${this.options.frameworkSourcePath}/RooibosScene.xml`,
dest: s`${this.targetCompsPath}/RooibosScene.xml`
src: s`${this.frameworkSourcePath}/components/RooibosScene.xml`,
dest: s`components/rooibos/RooibosScene.xml`
};
this.addedFrameworkFiles.push(
program.setFile(entry, this.createTestXML('RooibosScene', 'Scene'))
Expand All @@ -75,8 +67,8 @@ export class FileFactory {

public createTestXML(name: string, baseName: string, suite?: TestSuite): string {
let scriptImports = [];
for (let fileName of this.frameworkFileNames) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${this.targetPath}${fileName}.bs" />`);
for (let filePath of this.addedSourceFrameworkFilePaths) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${filePath}" />`);
}

// Add the test spec file rather then relying on auto imports
Expand Down Expand Up @@ -118,8 +110,8 @@ export class FileFactory {

public isIgnoredFile(file: BrsFile | XmlFile): boolean {
let name = file.pkgPath.toLowerCase();
let result = this.frameworkFileNames.find((f) => {
return name === path.join(this.targetPath, `${f}.bs`).toLowerCase();
let result = this.addedFrameworkFiles.find((f) => {
return name === f.pkgPath.toLowerCase();
}
);
return result !== undefined;
Expand Down
6 changes: 0 additions & 6 deletions bsc-plugin/src/lib/rooibos/RooibosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,4 @@ export interface RooibosConfig {
reporters?: string[];
keepAppOpen?: boolean;
testSceneName?: string;

/**
* The path to the folder where the rooibos framework roku files reside.
* @default `dist/lib/framework`
*/
frameworkSourcePath?: string;
}
1 change: 0 additions & 1 deletion bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('RooibosPlugin', () => {
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);
}

Expand Down
2 changes: 1 addition & 1 deletion bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class RooibosPlugin implements CompilerPlugin {

this.config = this.getConfig((builder.options as any).rooibos || {});

this.fileFactory = new FileFactory(this.config);
this.fileFactory = new FileFactory();
if (!this.session) {
this.session = new RooibosSession(builder, this.fileFactory);
this.codeCoverageProcessor = new CodeCoverageProcessor(builder, this.fileFactory);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1018,13 +1018,13 @@ namespace rooibos.common

sub logDebug(value)
#if ROOIBOS_DEBUG_LOGS
? "[Rooibos Debug]: "value
? "[Rooibos Debug]: " value
#end if
end sub

sub logTrace(value)
#if ROOIBOS_TRACE_LOGS
? "[Rooibos Trace]: "value
? "[Rooibos Trace]: " value
#end if
end sub

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace rooibos
m.testTimer.mark()
if m.currentTest = invalid
rooibos.common.logTrace("All tests are finished")
'finished
m.finishAsyncTests()
else
test = m.currentTest
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8497348

Please sign in to comment.