I'm taking the plunge and just installed TestBox i...
# testing
b
I'm taking the plunge and just installed TestBox into a legacy CFML app (no coldbox or frameworks used), based on very helpful information from people here a while ago, but I'm a little lost still. I gitignored the TestBox directory created and created a new tests folder at the top level of my project where I want my tests split into nice organized files and folders in. I'm reading about a runner.cfm and creating mappings to tell TestBox where to find and run tests, but it looks like there is already a runner.cfm and a tests folder in the gitignored TestBox directory, so I'm confused - do I move those out of the gitignored testbox folder and modify the runner somehow? Or do I create a new runner file that I add custom mappings to ..or? Not sure how to get everything setup, but I got as far as 'box install testbox' 🤘
b
How did you install testbox?
The only folder you really need inside testbox is system
the other tests folder is the actual testbox test suite, which really shoudn't be there if you installed it from ForgeBox via CommandBox
Copy code
install testbox
CommandBox also has scaffolding commands to help you create the runner
Copy code
testbox generate harness
b
I went to the top level of my project, adjacent to views and model folder, for example but outside of wwwroot where public browser stuff is served and ran 'box install testbox' (I have commandbox installed on my machine, not in docker etc just to be clear). It created the box json like you pointed out from before and the TestBox folder which I gitignored as advised as well. The generate commands for scaffolding a runner sound promising I'll try that
Aaah yes that command gave me a tests folder and runner etc file 🙏 . Now to dig into those
I think I'm close. Going to tests/runner.cfm has an error: Cannot find
/wwwroot/tests/runner.cfm [/app/wwwroot/tests/runner.cfm] not found.
I'm guessing it has something to do with the mappings in the tests/application.cfc file. At the risk of looking like a doofus, I'm just going to say it: I don't understand what mappings are or what that is doing. I know it's something to do with making folders visible or findable by CF/Lucee, but I don't understand how the syntax works, i.e. what the path on the left is vs. the path on the right side of the assignment
=
etc. Pretty sure my problem is in the mapping. There is a bind mount of everything on my local to an /app directory, so going to try adding paths under /app on either side.
(there's also a mapping from /root to
expandPath("/")
that was generated automatically, not sure what that is or if i can just remove it.
Ah,ok I moved the tests folder to wwwroot and now I can run a test! This feels strange because I don't think I should have a tests folder as browsable in the app alongside or adjacent with the other application source code, but it's a step further.
g
Think of a mapping as a shortcut or a symlink if you're a linux user. The directory can be anywhere on your disk; Eg. the physical location of the "tests" folder is in: Win:
c:\my\convoluted\path\tests
or Linux
/my/convoluted/path/tests
(this is just an example - you place the folders where you want them to live. Then the "mapping" is how you tell CF / Lucee - Where to find the physical files AND how to mount them in your application. so if you want
<https://mywebsite.com/tests>
to to be the url you hit you have a mapping like the following in you config.json (if you're using commandbox) Windows
Copy code
"CFMappings": {
        "/tests": {
            "INSPECTTEMPLATE": "always",
            "PHYSICAL": "c:\my\convoluted\path\tests"
        }
}
Linux
Copy code
"CFMappings": {
        "/tests": {
            "INSPECTTEMPLATE": "always",
            "PHYSICAL": "/my/convoluted/path/tests"
        }
}
if for example you wanted the following URL to work;
<https://mywebsite.com/my/really/really/convoluted/path/tests>
you would use;
Copy code
"CFMappings": {
        "/my/really/really/convoluted/path/tests": {
            "INSPECTTEMPLATE": "always",
            "PHYSICAL": "/my/convoluted/path/tests"
        }
}
In CFML - just think Shortcut / symlink when you hear "mapping". At what path "in" my application do I want XXX directory to appear? NOTE: The (Windows/linux) user account that runs CFML needs access to the physical location. JUST having the mapping isn't enough. NOTE2: You don't HAVE to use mappings. You CAN use a literal windows "soft" shortcut or a Linux symlink to place the directory you need. The difference is ownership / where the configuration lies... Does your IT dept control the OS/infrastructure?' Do you have rights to create OS level shortcuts/symlinks? Do you want the "mappings" controlled by the CFML application's configuration? It is "standard convention" to use CFML mappings as opposed to OS shortcuts - but it is NOT a requirement. As for having the tests directory as being browsable / accessible... Use your web server's configuration to set the permissions appropriately. - just as you would for an applications "uploads" directory - so that they aren't accessible/browsable to the general public. Use a Web Application Firewall (WAF) to limit access to the directory to certain IPs or via a specific URL...
🙏 1
b
Ah ok, thanks for the explanation. So a mapping is:
where/my/stuff/exists
=
where/Lucee/thinks/my/stuff/exists
As for not letting tests be public, I assume I need to go into a tomcat config somewhere (I'm used to working with react/node and tooling that handles running tests and serving separate public build and asset files automagically).
Actually, now that I've been trying mappings every which way from Sunday, looks like I got it backwards. It's
this.mappings[/mounted/path/Lucee/sees]
=
/actual/path/where/my/stuff/is
👍🏼 1