diff --git a/bsc-plugin/package-lock.json b/bsc-plugin/package-lock.json index c63d2780..a9e752a9 100644 --- a/bsc-plugin/package-lock.json +++ b/bsc-plugin/package-lock.json @@ -38,6 +38,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", diff --git a/bsc-plugin/package.json b/bsc-plugin/package.json index b5de2c96..a0d1a148 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -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", @@ -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", diff --git a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts index 3a2522ec..dcfcad61 100644 --- a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts +++ b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts @@ -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 diff --git a/bsc-plugin/src/lib/rooibos/FileFactory.ts b/bsc-plugin/src/lib/rooibos/FileFactory.ts index 3bac405a..71ddeaec 100644 --- a/bsc-plugin/src/lib/rooibos/FileFactory.ts +++ b/bsc-plugin/src/lib/rooibos/FileFactory.ts @@ -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')) @@ -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(`