diff --git a/bsc-plugin/src/lib/rooibos/RooibosSession.ts b/bsc-plugin/src/lib/rooibos/RooibosSession.ts index adb0d38..1a0aef0 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSession.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSession.ts @@ -123,8 +123,7 @@ export class RooibosSession { let classStatement = (runtimeConfig.ast.statements[0] as NamespaceStatement).body.statements[0] as ClassStatement; this.updateRunTimeConfigFunction(classStatement, editor); this.updateVersionTextFunction(classStatement, editor); - this.updateClassLookupFunction(classStatement, editor); - this.updateGetAllTestSuitesNames(classStatement, editor); + this.updateClassMapFunction(classStatement, editor); this.createIgnoredTestsInfoFunction(classStatement, editor); } } @@ -191,32 +190,18 @@ export class RooibosSession { } } - updateClassLookupFunction(classStatement: ClassStatement, editor: AstEditor) { - let method = classStatement.methods.find((m) => m.name.text === 'getTestSuiteClassWithName'); + updateClassMapFunction(classStatement: ClassStatement, editor: AstEditor) { + let method = classStatement.methods.find((m) => m.name.text === 'getTestSuiteClassMap'); if (method) { editor.arrayPush(method.func.body.statements, ...Parser.parse(undent` - if false - ? "noop" ${this.sessionInfo.testSuitesToRun.map(suite => ` - else if name = "${suite.name}" - return ${suite.classStatement.getName(ParseMode.BrightScript)}`).join('')} - end if + return {${this.sessionInfo.testSuitesToRun.map(suite => ` + "${suite.name}": ${suite.classStatement.getName(ParseMode.BrightScript)}`).join('')} + } `).ast.statements); } } - updateGetAllTestSuitesNames(classStatement: ClassStatement, editor: AstEditor) { - let method = classStatement.methods.find((m) => m.name.text === 'getAllTestSuitesNames'); - if (method) { - editor.arrayPush(method.func.body.statements, ...Parser.parse([ - 'return [', - ...this.sessionInfo.testSuitesToRun.map((s) => ` "${s.name}"`), - ']' - ].join('\n')).ast.statements); - } - } - createNodeFiles(program: Program) { - for (let suite of this.sessionInfo.testSuitesToRun.filter((s) => s.isNodeTest)) { this.createNodeFile(program, suite); } diff --git a/bsc-plugin/src/lib/rooibos/RooibosSessionInfo.ts b/bsc-plugin/src/lib/rooibos/RooibosSessionInfo.ts index 73ddde8..558f894 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSessionInfo.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSessionInfo.ts @@ -150,6 +150,7 @@ export class SessionInfo { } } this.testSuitesToRun = [...this.testSuites.values()].filter((s) => s.isIncluded); + this.testSuitesToRun.sort((a, b) => a.name.localeCompare(b.name)); } isExcludedByTag(item: TestCase | TestGroup | TestSuite, isParentIncluded) { diff --git a/bsc-plugin/src/plugin.spec.ts b/bsc-plugin/src/plugin.spec.ts index bb0267c..36534a8 100644 --- a/bsc-plugin/src/plugin.spec.ts +++ b/bsc-plugin/src/plugin.spec.ts @@ -2031,8 +2031,7 @@ describe('RooibosPlugin', () => { //the methods should be empty by default expect(findMethod('getVersionText').func.body.statements).to.be.empty; expect(findMethod('getRuntimeConfig').func.body.statements).to.be.empty; - expect(findMethod('getTestSuiteClassWithName').func.body.statements).to.be.empty; - expect(findMethod('getAllTestSuitesNames').func.body.statements).to.be.empty; + expect(findMethod('getTestSuiteClassMap').func.body.statements).to.be.empty; expect(findMethod('getIgnoredTestInfo').func.body.statements).to.be.empty; await builder.transpile(); @@ -2062,8 +2061,9 @@ describe('RooibosPlugin', () => { ).to.eql(undent` function __rooibos_RuntimeConfig_builder() instance = {} - instance.new = sub() - end sub + instance.new = function() + m.testSuites = m.getTestSuiteClassMap() + end function instance.getVersionText = function() return "${version}" end function @@ -2086,20 +2086,17 @@ describe('RooibosPlugin', () => { "isRecordingCodeCoverage": false } end function + instance.getTestSuiteClassMap = function() + return { + "ATest1": ATest1 + "ATest2": ATest2 + } + end function instance.getTestSuiteClassWithName = function(name) - if false - ? "noop" - else if name = "ATest1" - return ATest1 - else if name = "ATest2" - return ATest2 - end if + return m.testSuites[name] end function instance.getAllTestSuitesNames = function() - return [ - "ATest1" - "ATest2" - ] + return m.testSuites.keys() end function instance.getIgnoredTestInfo = function() return { @@ -2119,8 +2116,7 @@ describe('RooibosPlugin', () => { //the methods should be empty again after transpile has finished expect(findMethod('getVersionText').func.body.statements).to.be.empty; expect(findMethod('getRuntimeConfig').func.body.statements).to.be.empty; - expect(findMethod('getTestSuiteClassWithName').func.body.statements).to.be.empty; - expect(findMethod('getAllTestSuitesNames').func.body.statements).to.be.empty; + expect(findMethod('getTestSuiteClassMap').func.body.statements).to.be.empty; expect(findMethod('getIgnoredTestInfo').func.body.statements).to.be.empty; }); @@ -2152,8 +2148,9 @@ describe('RooibosPlugin', () => { ).to.eql(undent` function __rooibos_RuntimeConfig_builder() instance = {} - instance.new = sub() - end sub + instance.new = function() + m.testSuites = m.getTestSuiteClassMap() + end function instance.getVersionText = function() return "${version}" end function @@ -2176,13 +2173,14 @@ describe('RooibosPlugin', () => { "isRecordingCodeCoverage": false } end function + instance.getTestSuiteClassMap = function() + return {} + end function instance.getTestSuiteClassWithName = function(name) - if false - ? "noop" - end if + return m.testSuites[name] end function instance.getAllTestSuitesNames = function() - return [] + return m.testSuites.keys() end function instance.getIgnoredTestInfo = function() return { diff --git a/framework/src/source/BaseTestSuite.bs b/framework/src/source/BaseTestSuite.bs index da40806..87cf90e 100644 --- a/framework/src/source/BaseTestSuite.bs +++ b/framework/src/source/BaseTestSuite.bs @@ -1908,7 +1908,7 @@ namespace rooibos ' m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber) ' return false ' end try - return false + ' return false end function ' /** diff --git a/framework/src/source/RuntimeConfig.bs b/framework/src/source/RuntimeConfig.bs index e0bcc3a..788feae 100644 --- a/framework/src/source/RuntimeConfig.bs +++ b/framework/src/source/RuntimeConfig.bs @@ -1,16 +1,25 @@ namespace rooibos class RuntimeConfig + function new() + m.testSuites = m.getTestSuiteClassMap() + end function + function getVersionText() end function function getRuntimeConfig() end function + function getTestSuiteClassMap() + end function + function getTestSuiteClassWithName(name) + return m.testSuites[name] end function function getAllTestSuitesNames() + return m.testSuites.keys() end function function getIgnoredTestInfo()