-
Notifications
You must be signed in to change notification settings - Fork 240
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
Unit testing with Geddy says geddy is not defined #337
Comments
Can you try running
Then run I played with node-jscoverage a Let me know if this works. Miguel |
So I tried your suggestion but unfortunately, I get the same issue:
|
I'm not sure the error is related to how we run the tests. Does it work from the website? Can you try the following:
The |
Miguel, I tried your suggestion and it works. Okay I think I got jake tests to run now. I'm not sure what I did... but I basically made a new folder called test3 and put my tests in there and changed the directory from the JakeFile to point to it. I notice the tests just run forever though (ie. I have to hit CTRL+C in order to stop the process), but it doesn't do this with the simple example test. I get the correct output with all of my tests:
but it just sits there at the end. |
You might have an async test and forgot to signal that you the test Miguel On Sat, Mar 23, 2013 at 1:02 PM, elayman notifications@github.com wrote:
|
I tried the node-unit jake task again and I get this output (not sure why the n's are removed):
|
Ah! I forgot Thanks for your help. Any ideas on my nodeunit error? |
Can you try running node-unit on it's own? Miguel On Sat, Mar 23, 2013 at 1:08 PM, elayman notifications@github.com wrote:
|
Yes, I run: nodeunit test3/userTests.js
|
That's odd. The same code works when ran with jake? Miguel On Sat, Mar 23, 2013 at 2:26 PM, elayman notifications@github.com wrote:
|
Is it possible that NodeUnit is running the test code in some other process? On Sat, Mar 23, 2013 at 6:29 PM, Miguel Madero notifications@github.comwrote:
|
I apologize for my noobiness. I am new to node.js and Geddy and therefore nodeunit as well. I tried to add the
|
@mde is right. Nodeunit is using a different process, so this solution won't work. Even if we initialized the env in jake, we're starting a new process, hence new memory, new domain and undefined variables. Now, just as a reference, if we wanted to initialized the environment before we would run it as a jake task, not as another command. I was on the phone and couldn't send a link, but you can have a look at the jake docs for for further reference. To execute another jake task would run Now a couple of solutions are:
Have a look at
I've not had a chance to test any of this, but I hope this gives you some pointers. Let me know how it goes. We will have to do some changes to geddy to make this easier and add some docs. It's always good to play nice with alternative options, and jake isn't really shining as a test runner so this is an important category. |
So I tried to mess around with this today but couldn't get it working. It seems running the reporter.run still initializes a new process because the behavior is the same as calling exec nodeunit. EDIT: I put the geddy init code in EDIT2: I was able to fix that error by adding And unfortunately, the comment above this line doesn't help me much 😃
|
I don't have experience with nodeunit and I just got that from the docs. Miguel On Mon, Mar 25, 2013 at 11:36 AM, elayman notifications@github.com wrote:
|
I am not opposed to another testing framework, however I believe I will have similar issues with others won't I? Do you know of a test runner that doesn't use another process? |
Sorry, that's an area I'm not familiar with. I'm guessing that running it Miguel On Mon, Mar 25, 2013 at 10:59 PM, elayman notifications@github.com wrote:
|
Thanks for all of your guidance @MiguelMadero. I found a jakefile for running Mocha here: https://gist.github.com/BryanDonovan/5022389 I will try to use Mocha since it seems to be another good testing framework. |
Awesome, its great you found it. Maybe you can help us creating a testing I'll have a look once I finish this trip. Thanks
|
Done: https://github.com/mde/geddy/wiki/Unit-Testing-With-Geddy Feel free to edit or mention things I should add! |
Fantastic! I know this will help a lot of people out. |
Since this is somewhat related (I had mentioned I wanted to use a code coverage tool), do you know if I can do something similar to this post to run node-jscoverage, (ie. flatten the app directory and use instinct, or will Geddy complain)? "add instinct.js that consolidated all my models, controllers, middleware and exported them from one place. Then elsewhere in my project anytime I needed a model, controller or middleware I just required that main instinct module like so:
Then I added an index.js file at the project root that exports either lib/instinct or lib-cov/instinct depending on the INSTINCT_COV environment variable (which we'll set in our MakeFile)" Original link: http://brianstoner.com/blog/testing-in-nodejs-with-mocha/ |
@MiguelMadero - do you know if there's a config in geddy where it chooses the app/ directory so I can change it to app-cov/ when I'm using jscoverage? |
@elayman No there isn't, although you could just symlink app-cov to app. |
There is an option to set the app directory when running the server (-g/--geddy-root), but it only works when running the server. ( Another alternative would be to have a Jake task that you use a a prerequisite that does |
I followed @mde 's advice and created a copy of the directory before covering the code. Then I change directory and run the tests. Here is my wiki with link to my code: https://github.com/mde/geddy/wiki/Unit-Testing-&-Code-Coverage-With-Geddy |
Nice. Thanks for the wiki link. :) |
I'm running Geddy MVC Framework on Node.js on Heroku right now with a Postgres database. I can't seem to find any unit test frameworks for node.js that support Geddy. I have tried nodeunit, jasmine and a couple others but none seem to work with geddy (saying it is undefined - I think because it doesn't know how to import all of the required files).
I know Geddy provides their jake test tool but it doesn't seem to work either. It gives me this output:
Any help would be greatly appreciated. Also looking for a code coverage tool that will work with the unit testing framework I get working.
Thanks!
EDIT: My tests all start with this header to import the required modules:
And the import of Activity fails with the ReferenceError above, so it never even tries my tests.
Here is a nodeunit test I wrote
And the output
The text was updated successfully, but these errors were encountered: