Env.execute() returns after some of the specs are run, but not all

43 views
Skip to first unread message

Joe Barnes

unread,
Mar 14, 2016, 12:47:48 AM3/14/16
to Jasmine
I'm working on an sbt plugin for running javascript tests on the JVM, and jasmine is my first test framework to integrate.  Everything worked great until I tried it against a larger test suite.  In my boot I register an onComplete callback which simply sets a flag.  Then later I simply call jasmine.getEnv().execute() and return the flag.

As I mentioned, this works as long as there are few test cases.  Once the test is a bit larger (the size of introduction.js for instance), the execute() function returns after about 15-20 expects have run.  My flag check fails because the onComplete has not been called, and the tests continue to run after my function returns.  As a result, my task fails and you can see where I announce the failure but the dots from expects running are still getting printed:

[info] Started
..................[error] (*:jsTest) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1 s, completed Mar 13, 2016 10:08:27 AM
.> .....................................................................................................
........................................................................................................
.......................................................
[info] 279 specs, 0 failures
[info] Finished in 0 seconds

I wouldn't have been surprised if execute() sort of scheduled the running with a timeout and ran all of them after returning immediately from execute().  But since initially I observed that it didn't return until the specs ran, I assumed all of them would run.  I find this behavior of running some, returning, the running the rest to be very odd.  Even more odd is that the number of expectations isn't consistent even with the same test suite.  The number of dots I see printed out varies slightly.

Ideally, I would like execute() to NOT return until all of the tests have run.  Otherwise I'll need to do a busy-wait poll util window.sbtJsTest.complete is set to true.

Does anyone have some good ideas on how I can accomplish this?

Thanks,
Joe


Gregg Van Hove

unread,
Mar 14, 2016, 12:27:17 PM3/14/16
to jasmi...@googlegroups.com
Execution of a Jasmine suite is always potentially asynchronous. For suites above a certain size (around 20 I think), Jasmine will start to use `setTimeout` to keep the call stack from getting out of hand, so that execution can continue. The suite could also have specs that are async (using `done`). The `onComplete` callback in the ConsoleReporter is invoked when the suite finishes with the `jasmineDone` event, so will always come after all specs have completed.

Hope this helps. Thanks for using Jasmine!

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages