It's possible that this is already possible with the existing mocha suite, but I am just unaware of how to do it. For that reason, I've got a Stack Overflow with pretty much the same issue, here.
I'm trying to develop a test suite for my company's application. We have a list of reports: [reportA, reportB, reportC... ad nauseum] and there are about 120 of these.
For each report, we need to (asynchronously) grab a record from the server. Once we have that record, we then need to run a (similar, but not identical) battery of tests on it (roughly ~200 or so per report.) Complicating the fact is that I'll have to do some if/then routing in order to make sure only the correct tests are run on the correct report, but that's a minor issue compared to running the tests in the first place.
My first thought was to grab the reports with a Promise, and the inside the .then() method, run those "describe()" and "it()" statements. No dice - Mocha will not run inside a .then() statement.
My second thought: create a "testmaker" function that returns a mocha test, and run them one after each other.
Again, no such luck, I'm getting a "describe is not defined" error.
ERROR: ReferenceError: describe is not defined
_I can't really use the "before()" or "beforeEach()" functions, because the asynchronous task needs to be completed before describe() executes._
If this is not an actual issue - or inappropriate, I apologize, but I'm starting to get to the end of my rope.
Maybe use --delay and call run in the end if the then?
That would solve the immediate problem. I'd prefer, of course, to be able to grab a report, test it, then move onto the next one, but this will solve it.
When I have some spare time, I might start running through the source and building a third-party library that manages this behavior, but for right now, this'll do.
Thanks!
Most helpful comment
Maybe use
--delayand callrunin the end if thethen?