Created
March 17, 2022 13:48
-
-
Save adamcameron/236f28f7909bb964a402b147578da770 to your computer and use it in GitHub Desktop.
TestBox request.testbox.debug fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CHANGES ONLY | |
component { | |
// ... | |
// Setup Request Utilities | |
if ( !request.keyExists( "testbox" ) ) { | |
request.testbox = { | |
"console" : variables.console, | |
"debug" : () => debugFixed(argumentCollection=arguments, thisContext=this), // FIXED | |
"clearDebugBuffer" : variables.clearDebugBuffer, | |
"print" : variables.print, | |
"println" : variables.println, | |
"getDebugBuffer" : () => this.$debugBuffer // ADDED | |
}; | |
} | |
// ... | |
// copy of `debug`. Changes: passing in thisContext; referencing that rather than this | |
any function debugFixed( | |
any var, | |
string label = "", | |
boolean deepCopy = false, | |
numeric top = "999", | |
any thisContext | |
){ | |
// null check | |
if ( isNull( arguments.var ) ) { | |
arrayAppend( thisContext.$debugBuffer, "null" ); | |
return; | |
} | |
// duplication control | |
var newVar = ( arguments.deepCopy ? duplicate( arguments.var ) : arguments.var ); | |
// compute label? | |
if ( !len( trim( arguments.label ) ) ) { | |
// Check if executing spec is set, else most likely this is called from a request scoped debug method | |
arguments.label = !isNull( thisContext.$currentExecutingSpec ) ? thisContext.$currentExecutingSpec : 'request'; | |
} | |
// add to debug output | |
arrayAppend( | |
thisContext.$debugBuffer, | |
{ | |
data : newVar, | |
label : arguments.label, | |
timestamp : now(), | |
top : arguments.top | |
} | |
); | |
return thisContext; | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import testbox.system.BaseSpec | |
import cfmlInDocker.services.testboxTest.DebugTester | |
component extends=BaseSpec { | |
function run() { | |
describe("Testing request.testbox.debug", () => { | |
it("should write to debug buffer", () => { | |
request.testbox.debug("hi?") | |
expect(this.$debugBuffer).toHaveLength(1) | |
expect(this.$debugBuffer[1].data).toBe("hi?") | |
}) | |
fit("should write to debug buffer when called from a SUT", () => { | |
sut = new DebugTester() | |
sut.testMe() | |
messagesOnly = request.testbox.getDebugBuffer().map((debugEntry) => debugEntry.data) | |
expect(messagesOnly).toHaveLength(3) | |
expect(messagesOnly).toBe([ | |
//"in static constructor", | |
"in pseudo constructor", | |
"in constructor", | |
"in method" | |
]) | |
}) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
request.testBox.debug("in pseudo constructor") | |
static { | |
//request.testBox.debug("in static constructor") | |
} | |
function init() { | |
request.testBox.debug("in constructor") | |
} | |
function testMe() { | |
request.testBox.debug("in method") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment