diff --git a/bsc-plugin/src/lib/rooibos/RooibosConfig.ts b/bsc-plugin/src/lib/rooibos/RooibosConfig.ts index f43ed6af..6d5cd16b 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosConfig.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosConfig.ts @@ -22,6 +22,7 @@ export interface RooibosConfig { includeFilters?: string[]; tags?: string[]; catchCrashes?: boolean; + throwOnFailedAssertion?: boolean; sendHomeOnFinish?: boolean; reporter?: string; keepAppOpen?: boolean; diff --git a/bsc-plugin/src/lib/rooibos/RooibosSession.ts b/bsc-plugin/src/lib/rooibos/RooibosSession.ts index 430890a3..f54291d9 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSession.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSession.ts @@ -147,6 +147,7 @@ export class RooibosSession { "printLcov": ${this.config.printLcov ? 'true' : 'false'} "port": "${this.config.port || 'invalid'}" "catchCrashes": ${this.config.catchCrashes ? 'true' : 'false'} + "throwOnFailedAssertion": ${this.config.throwOnFailedAssertion ? 'true' : 'false'} "keepAppOpen": ${this.config.keepAppOpen === undefined || this.config.keepAppOpen ? 'true' : 'false'} }` ) diff --git a/bsc-plugin/src/plugin.spec.ts b/bsc-plugin/src/plugin.spec.ts index 94d5a8b7..c6594ca9 100644 --- a/bsc-plugin/src/plugin.spec.ts +++ b/bsc-plugin/src/plugin.spec.ts @@ -1610,6 +1610,7 @@ describe('RooibosPlugin', () => { "printLcov": false "port": "invalid" "catchCrashes": true + "throwOnFailedAssertion": false "keepAppOpen": true } end function @@ -1671,6 +1672,7 @@ describe('RooibosPlugin', () => { 'rooibos': { 'showOnlyFailures': true, 'catchCrashes': true, + 'throwOnFailedAssertion': false, 'lineWidth': 70, 'failFast': false, 'sendHomeOnFinish': false, diff --git a/bsc-plugin/src/plugin.ts b/bsc-plugin/src/plugin.ts index ffbf4750..d89721df 100644 --- a/bsc-plugin/src/plugin.ts +++ b/bsc-plugin/src/plugin.ts @@ -53,6 +53,9 @@ export class RooibosPlugin implements CompilerPlugin { if (config.catchCrashes === undefined) { config.catchCrashes = true; } + if (config.throwOnFailedAssertion === undefined) { + config.throwOnFailedAssertion = false; + } if (config.sendHomeOnFinish === undefined) { config.sendHomeOnFinish = true; } diff --git a/docs/index.md b/docs/index.md index bc10913f..5dfd2cd5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -163,6 +163,7 @@ Here is the information converted into a Markdown table: | printTestTimes? | boolean | If true, then the time each test took is output | | lineWidth? | number | Width of test output lines in columns | | catchCrashes? | boolean | If true, then any crashes will report CRASH statement, and note halt test execution - very useful for running a whole suite | +| throwOnFailedAssertion? | boolean | If true, then any failure will result in a runtime crash. Very useful for inspecting the stack frames and jumping right to the first failed test. | | sendHomeOnFinish? | boolean | If true, then the app will exit upon finish. The default is true. Useful to set to false for local test suites | | keepAppOpen? | boolean | When true, the app will remain open upon test completion. The default is true. Set false to return execution to Main | | testsFilePattern? | string | The pattern to use to find tests. This is a glob. The default is "**/*.spec.bs" | diff --git a/framework/src/source/BaseTestSuite.bs b/framework/src/source/BaseTestSuite.bs index 1a5cabae..eeb2fef4 100644 --- a/framework/src/source/BaseTestSuite.bs +++ b/framework/src/source/BaseTestSuite.bs @@ -51,6 +51,7 @@ namespace rooibos protected global = invalid protected catchCrashes = false + protected throwOnFailedAssertion = false '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '++ base methods to override @@ -262,6 +263,7 @@ namespace rooibos ? "" m.currentResult = test.result + m.currentResult.throwOnFailedAssertion = m.throwOnFailedAssertion if m.catchCrashes and not test.noCatch and not m.noCatch try test.run() @@ -302,6 +304,9 @@ namespace rooibos ' */ function fail(msg = "Error" as string) as dynamic if m.currentResult.isFail + if m.throwOnFailedAssertion + throw m.currentResult.getMessage() + end if return false end if m.currentResult.fail(msg, m.currentAssertLineNumber) @@ -1850,15 +1855,15 @@ namespace rooibos ' * @returns {Object} - mock that was wired into the real method ' */ function expectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - 'HACK - 'HACK - 'HACK - 'HACK - 'HACK + 'HACK + 'HACK + 'HACK + 'HACK + 'HACK ' try - return m.mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods) + return m.mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods) ' catch error - 'bs:disable-next-line + 'bs:disable-next-line ' m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber) ' return false ' end try diff --git a/framework/src/source/TestResult.bs b/framework/src/source/TestResult.bs index bda4ce34..61e25412 100644 --- a/framework/src/source/TestResult.bs +++ b/framework/src/source/TestResult.bs @@ -8,6 +8,7 @@ namespace rooibos public test = invalid public time = 0 public error = invalid + public throwOnFailedAssertion = false function new(test) m.test = test @@ -38,6 +39,9 @@ namespace rooibos m.message = message end if end if + if m.throwOnFailedAssertion + throw m.getMessage() + end if end function function crash(message as string, error) diff --git a/framework/src/source/TestRunner.bs b/framework/src/source/TestRunner.bs index 44c248c8..07bc9135 100644 --- a/framework/src/source/TestRunner.bs +++ b/framework/src/source/TestRunner.bs @@ -69,6 +69,7 @@ namespace rooibos testSuite.top = m.nodeContext.top testSuite.scene = m.nodeContext.global.testsScene testSuite.catchCrashes = m.config.catchCrashes + testSuite.throwOnFailedAssertion = m.config.throwOnFailedAssertion testSuite.scene.testText = `Running Suite ${i} of ${numSuites}: ${name}` m.runTestSuite(testSuite) if m.stats.hasFailures = true @@ -138,6 +139,7 @@ namespace rooibos testSuite.top = m.nodeContext.top testSuite.scene = m.nodeContext.global.testsScene testSuite.catchCrashes = m.config.catchCrashes + testSuite.throwOnFailedAssertion = m.config.throwOnFailedAssertion m.nodeContext.testSuite = testSuite m.nodeTestName = nodeTestName m.nodeContext.testRunner = m