Last active
May 9, 2022 13:24
-
-
Save adamcameron/be49e9615b05f0e32278dda1ec99ed73 to your computer and use it in GitHub Desktop.
testing how to deal with beforeEach / afterEach
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
<style> | |
.tinytest {background-color: black; color:white; font-family:monospace} | |
.tinytest div {margin-left: 1em} | |
.tinyTest .pass {color:green;} | |
.tinyTest .fail {color:red;} | |
.tinyTest .error {background-color:red; color:black} | |
</style> | |
<cfscript> | |
baseContext = [] | |
describe = (message, callback) => { | |
var thisContext = { | |
message = message, | |
tests = [] | |
} | |
baseContext.prepend(thisContext) | |
writeOutput("<div>") | |
writeOutput("#message#<br>") | |
callback() | |
baseContext.shift() | |
writeOutput("</div>") | |
} | |
beforeEach = (callBack) => { | |
baseContext[1].beforeEach = callback | |
} | |
afterEach = (callBack) => { | |
baseContext[1].afterEach = callback | |
} | |
it = (message, callback) => { | |
writeOutput("<div>") | |
baseContext.reduce((contexts, context) => contexts.prepend(context), []).each((context) => { | |
if (context.keyExists("beforeEach")) { | |
context.beforeEach() | |
} | |
}) | |
writeOutput("It #message#: ") | |
callback() | |
baseContext.each((context) => { | |
if (context.keyExists("afterEach")) { | |
context.afterEach() | |
} | |
}) | |
writeOutput("</div>") | |
} | |
run = (context) => { | |
describe("outer", () => { | |
beforeEach(() => { | |
writeoutput("beforeEach outer<br>") | |
}) | |
afterEach(() => { | |
writeoutput("afterEach outer<br>") | |
}) | |
it("is the first test", () => { | |
writeoutput("one<br>") | |
}) | |
it("is the second test", () => { | |
writeoutput("two<br>") | |
}) | |
describe("middle", () => { | |
beforeEach(() => { | |
writeoutput("beforeEach middle<br>") | |
}) | |
afterEach(() => { | |
writeoutput("afterEach middle<br>") | |
}) | |
it("is a test before the inner describe", () => { | |
writeoutput("three<br>") | |
}) | |
describe("inner", () => { | |
beforeEach(() => { | |
writeoutput("beforeEach inner<br>") | |
}) | |
afterEach(() => { | |
writeoutput("afterEach inner<br>") | |
}) | |
it("is the inner first test", () => { | |
writeoutput("four<br>") | |
}) | |
it("is the inner second test", () => { | |
writeoutput("five<br>") | |
}) | |
}) | |
it("is a test after the inner describe", () => { | |
writeoutput("six<br>") | |
}) | |
}) | |
it("is the last test", () => { | |
writeoutput("seven<br>") | |
}) | |
}) | |
} | |
writeOutput('<div class="tinyTest">') | |
result = run(baseContext) | |
writeOutput('</div>') | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment