From 546a14fc508793fbed6e51ed5f86555dbece1f65 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Mon, 4 May 2026 05:27:23 -0700 Subject: [PATCH] chore: initial scaffolding for testbox --- .gitignore | 3 +- box.json | 9 ++- tests/Application.cfc | 24 +++++++ tests/runner.cfm | 36 ++++++++++ tests/specs/BDDTest.cfc | 125 ++++++++++++++++++++++++++++++++ tests/specs/MyFirstSpec.cfc | 15 ++++ tests/test.xml | 137 ++++++++++++++++++++++++++++++++++++ 7 files changed, 346 insertions(+), 3 deletions(-) create mode 100644 tests/Application.cfc create mode 100644 tests/runner.cfm create mode 100644 tests/specs/BDDTest.cfc create mode 100644 tests/specs/MyFirstSpec.cfc create mode 100644 tests/test.xml diff --git a/.gitignore b/.gitignore index 9638caf..9cbee4a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ crossdomain.xml node_modules/ dist/ dist-ssr/ -coldspa.config.json \ No newline at end of file +coldspa.config.json +modules/ \ No newline at end of file diff --git a/box.json b/box.json index 62fbac3..7778ca1 100644 --- a/box.json +++ b/box.json @@ -36,8 +36,12 @@ } ], "dependencies":{}, - "devDependencies":{}, - "installPaths":{}, + "devDependencies":{ + "testbox":"^7.0.0+19" + }, + "installPaths":{ + "testbox":"modules/testbox/" + }, "ignore":[ "**/.*", "/test/", @@ -46,6 +50,7 @@ "/dist/", "/dist-ssr/", "/node_modules/", + "/modules/", "/src/", "/WEB-INF/", "package.json", diff --git a/tests/Application.cfc b/tests/Application.cfc new file mode 100644 index 0000000..548dca0 --- /dev/null +++ b/tests/Application.cfc @@ -0,0 +1,24 @@ +/** + * Copyright Since 2005 Ortus Solutions, Corp + * www.ortussolutions.com + * ************************************************************************************* + */ +component { + + this.name = "A TestBox Runner Suite"; + // any other application.cfc stuff goes below: + this.sessionManagement = true; + + // any mappings go here, we create one that points to the root called test. + this.mappings[ "/tests" ] = getDirectoryFromPath( getCurrentTemplatePath() ); + // Turn on/off remote cfc content whitespace + this.suppressRemoteComponentContent = false; + + // any orm definitions go here. + + // request start + public boolean function onRequestStart( String targetPage ){ + return true; + } + +} diff --git a/tests/runner.cfm b/tests/runner.cfm new file mode 100644 index 0000000..ac4235e --- /dev/null +++ b/tests/runner.cfm @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/specs/BDDTest.cfc b/tests/specs/BDDTest.cfc new file mode 100644 index 0000000..313eb65 --- /dev/null +++ b/tests/specs/BDDTest.cfc @@ -0,0 +1,125 @@ +/** + * My first spec file + */ +component extends="testbox.system.BaseSpec" { + + /** + * You can prepare variables here that will be available to all specs in this spec file + */ + property testbox; + property foo; + property salvador; + + /*********************************** LIFE CYCLE Methods ***********************************/ + + /** + * Executes BEFORE all suites in this spec file + */ + function beforeAll(){ + variables.salvador = 1; + } + + /** + * Executes AFTER all suites in this spec file + */ + function afterAll(){ + // do cleanup here + } + + /*********************************** BDD SUITES ***********************************/ + + function run(){ + /** + * describe() starts a suite group of spec tests. It is the main BDD construct. + * You can also use the aliases: story(), feature(), scenario(), given(), when() + * to create fluent chains of human-readable expressions. + * + * Arguments: + * + * @title Required: The title of the suite, Usually how you want to name the desired behavior + * @body Required: A closure that will resemble the tests to execute. + * @labels The list or array of labels this suite group belongs to + * @asyncAll If you want to parallelize the execution of the defined specs in this suite group. + * @skip A flag that tells TestBox to skip this suite group from testing if true + * @focused A flag that tells TestBox to only run this suite and no other + */ + describe( "A spec", () => { + /** + * -------------------------------------------------------------------------- + * Runs before each spec in THIS suite group or nested groups + * -------------------------------------------------------------------------- + */ + beforeEach( () => { + testbox = 0; + testbox++; + } ); + + /** + * -------------------------------------------------------------------------- + * Runs after each spec in THIS suite group or nested groups + * -------------------------------------------------------------------------- + */ + afterEach( () => { + foo = 0; + } ); + + /** + * it() describes a spec to test. Usually the title is prefixed with the suite name to create an expression. + * You can also use the aliases: then(), test() to create fluent chains of human-readable expressions. + * + * Arguments: + * + * @title The title of this spec + * @body The closure that represents the test + * @labels The list or array of labels this spec belongs to + * @skip A flag or a closure that tells TestBox to skip this spec test from testing if true. If this is a closure it must return boolean. + * @data A struct of data you would like to bind into the spec so it can be later passed into the executing body function + * @focused A flag that tells TestBox to only run this spec and no other + */ + it( "can test for equality", () => { + expect( testbox ).toBe( 1 ); + } ); + + it( "can have more than one expectation to test", () => { + testbox = testbox * 8; + // type checks + expect( testbox ).toBeTypeOf( "numeric" ); + // dynamic type methods + expect( testbox ).toBeNumeric(); + // delta ranges + expect( testbox ).toBeCloseTo( expected = 10, delta = 2 ); + } ); + + it( "can have negative expectations", () => { + testbox = testbox * 8; + // type checks + expect( testbox ).notToBeTypeOf( "usdate" ); + // dynamic type methods + expect( testbox ).notToBeArray(); + // delta ranges + expect( testbox ).notToBeCloseTo( expected = 10, delta = 2 ); + } ); + + xit( "can have tests that can be skipped easily like this one by prefixing it with x", () => { + fail( "xit() this should skip" ); + } ); + + it( + title = "can have tests that execute if the right environment exists (Windows Only)", + body = () => { + expect( server.os.name ).toInclude( "Windows" ); + }, + skip = ( !isWindows() ) + ); + + it( + title = "can have tests that execute if the right environment exists (Mac Only)", + body = () => { + expect( server.os.name ).toInclude( "Mac" ); + }, + skip = ( !isMac() ) + ); + } ); + } + +} diff --git a/tests/specs/MyFirstSpec.cfc b/tests/specs/MyFirstSpec.cfc new file mode 100644 index 0000000..2cc96ca --- /dev/null +++ b/tests/specs/MyFirstSpec.cfc @@ -0,0 +1,15 @@ +component extends="testbox.system.BaseSpec"{ + + function run(){ + describe( "My First Test", ()=>{ + test( "it can add", ()=>{ + expect( sum( 1, 2 ) ).toBe( 3 ) + } ) + } ) + } + + private function sum( a, b ){ + return a + b + } + +} diff --git a/tests/test.xml b/tests/test.xml new file mode 100644 index 0000000..b17e926 --- /dev/null +++ b/tests/test.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests ran at ${start.TODAY} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.51.2