New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to run code after all tests complete #241
Comments
Why not use an |
because I need to close the connection after all of the unit tests finish, not just after each describe block. Mongoose is designed to open one connection for the whole process, use it, and close it when everything is done. |
Well, first thing off the top of my head (not ideal) is you can use the force exit flag when you run jasmine node. I'll think about other solutions today. On Jul 2, 2013, at 12:27 PM, "Richard Bateman" notifications@github.com wrote:
|
I wasn't aware of that flag; good thought. The other idea a friend of mine thought of was to write a custom reporter to execute the code. Kinda hackish, but likely effective. I'll try it tonight. |
Lemme know how that goes. |
This worked for me. I added the following code to a helper module: /**
* Override the finishCallback so we can add some cleanup methods.
* This is run after all tests have been completed.
*/
var _finishCallback = jasmine.Runner.prototype.finishCallback;
jasmine.Runner.prototype.finishCallback = function () {
// Run the old finishCallback
_finishCallback.bind(this)();
// add your cleanup code here...
}; |
Great suggestion sobotkip - it was just what I needed. I guess we really need an afterAll() teardown method as part of the framework. |
I can't believe we need to monkey-patch Jasmine to get basic setup and teardown hooks. This issue has been known for years and it doesn't look like Pivotal's gonna budge: jasmine/jasmine#56. I wanted to use jasmine but after butting my head against the same problem of needing to stop an Express server, I decided to switch to Mocha which worked right out of the box. |
…orm setup and teardown to stop the Express server after tests are done, and it doesn't look like there's going to be a way to do it in jasmine without monkey-patching the framework: mhevery/jasmine-node#241
This is all about asynchronous tests, where the JavaScript code flow cannot be used to naturally place the Some cases can be covered by artificial test steps, some by a beforeAll + afterAll plugin. |
Am facing the same issue with jasmine-node and mongodb. I launch jasmine-node in a separate process via grunt.util.spawn, and it blocks indefinitely until disconnect is called. Problem is, I only want to call disconnect after ALL tests have finished, and not connect/disconnect per test. Like others of you have mentioned, beforeEach/afterEach are just not feasible for integration tests. Makes them much more expensive. |
I've determined why the process blocks after all tests completes. It's because you have to disconnect from mongodb, or the event loop with be blocked. This makes sense, but what doesn't is why jasmine doesn't provide hooks for beforeAll and afterAll. It's here where you'd want to connect and disconnect from mongodb. Next step is to install the plugin that monkey patches jasmine to provide this functionality. * mhevery/jasmine-node#241 * https://github.com/nonplus/jasmine-beforeAll * jasmine/jasmine#56
Am I right that we should close this? Issue is pretty confusing in opened state. Related: #366 |
how to run .sql file for Postgres SQL in jasmine when before running spec. I don't get any solutions for this. can I add .sql file code in jasmine.json file? |
I am not looking to run testing code; I simply need to close the database connection so that the process will end. there seems to be no way to do this, and this is a pretty critical fatal flaw for using jasmine with node.js
The text was updated successfully, but these errors were encountered: