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

Test a sails project #1239

Closed
danielfeelfine opened this Issue Dec 25, 2013 · 16 comments

Comments

7 participants
@danielfeelfine
Copy link
Contributor

danielfeelfine commented Dec 25, 2013

I did not find anywhere on how to test a project sails natively. I think you should add the 'test' directory, and embed simple tests on a new project created from the generator. Tests are very important, can not be left out. What say you?

@albertosouza

This comment has been minimized.

Copy link

albertosouza commented Dec 25, 2013

@danielfeelfine i use mocha and cake to run the tests.
With the structure: https://github.com/albertosouza/we/tree/master/test and to run the tests using the file: https://github.com/albertosouza/we/blob/master/Cakefile with the command "cake test"

@danielfeelfine

This comment has been minimized.

Copy link
Contributor Author

danielfeelfine commented Dec 25, 2013

Great @albertosouza, it's a nice example. I'm in favor of the Sails has the minimum standard tests, and that tests are included by default of a new blank project. This encourages beginners to test the application, which is very important. So you can make a pull request with testing the new blank application template with the Sails generator. Believe it will be approved if written cleanly.

@albertosouza

This comment has been minimized.

Copy link

albertosouza commented Dec 25, 2013

Needs more work for add in Sails generator but I'll see what I can do in this weekend.

@danielfeelfine

This comment has been minimized.

Copy link
Contributor Author

danielfeelfine commented Dec 25, 2013

The #797 can help for this. Maybe I'll work on it before v0.10 is released. But what do you think of having basic tests embedded in the generator?

@albertosouza

This comment has been minimized.

Copy link

albertosouza commented Dec 26, 2013

Compound.js has this feature and are very helpfull
I think a basic structure of tests speeds up the construction of tests in new projects and helps a lot for those who are beginning to use the framework

@hyzhak

This comment has been minimized.

Copy link

hyzhak commented Dec 26, 2013

I think SailsJS lack of possibilities to instantiate a separate model and controllers, like Angularjs has for controllers http://docs.angularjs.org/guide/dev_guide.unit-testing or Django has for testing models https://docs.djangoproject.com/en/1.6/intro/tutorial05/.

But It is very important for unit testing to have possibilities of decoupling parts of system to isolating and test each part without instantiate whole SailsJS server.

@nathanleclaire

This comment has been minimized.

Copy link

nathanleclaire commented Dec 27, 2013

+1 I think that there should be a default test directory in the main project structure, and generators should create test files for the Controller and Model they generate. This would encourage testing which is a very important feature of any application. As it stands right now it is unclear how to even begin testing, say, a controller I have generated. I have a general idea but Sails makes most other things so easy that IMO this should become part of the framework's culture ASAP. I think that encouraging testing in, say, AngularJS has been very beneficial for that project.

@albertosouza

This comment has been minimized.

Copy link

albertosouza commented Dec 29, 2013

Existing feature request for "Test generation" : #88

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented Jan 22, 2014

@albertosouza thanks for posting your testing strategy! For our projects, we use mocha as well.

@hyzhak Absolutely right-- but good news is the generators in sails v0.10 allow for complete customization of your project structure (like this one that spits out a Sails app that looks like an Express app)

generators are much more stable now-- they're being used in the v0.10 branch of sails.
Here's where you'd want to add the folder / helpers:
https://github.com/balderdashy/sails-generate-new/blob/master/lib/index.js#L29

We probably dont need a separate generator for the testing boilerplate (a la frontend, backend, and gruntfile) right out the gate (although folks might want to use vows instead of mocha, etc. so we could go there as soon as someone needs/wants the feature, i.e. sails-generate-testharness)-- but we could totally just use the folder/template helpers for now to do the job (and bundle it in the sails-generate-new module) I'm happy to merge a PR like that!

As far as generating individual tests post-sails new (similar functionality to generate-controller), I set up sails-generate-test using the generator for generators

Repo:
https://github.com/balderdashy/sails-generate-test

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented Jan 22, 2014

Also made a repo for if anyone wants to work on it (https://github.com/balderdashy/sails-generate-testharness)

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented Jan 22, 2014

Moved to trello feature requests:

sails-generate-test
sails-generate-testharness

@mikermcneil mikermcneil reopened this Jan 22, 2014

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented Jan 22, 2014

Err nevermind-- there's no way to respond there... We need to come up w/ a better solution..

@ndhoule

This comment has been minimized.

Copy link
Contributor

ndhoule commented Feb 22, 2014

@mikermcneil, I'd be down to take a stab at this. Would you mind committing a dummy readme in sails-generate-testharness? (GitHub doesn't allow forking on empty repos.)

Edit: Just saw sails-generate-test. Is the idea that sails-generate-test is for individual tests and sails-generate-testharness is for initial setup? Assuming that's the case, maybe it'd be more user friendly to roll them into the same generator, usage something like this:

sails generate test --harness
sails generate test user (controller and model tests)
sails generate test --controller=user
sails generate test --model=user

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented Mar 2, 2014

@ndhoule awesome! https://github.com/balderdashy/sails-generate-test

IMO, sails-generate-controller and sails-generate-model should call sails-generate-test to also create a test file at the same time. The boilerplate helpers and top-level test folder should be created by sails-generate-backend. What do you think?

@CWyrtzen

This comment has been minimized.

Copy link

CWyrtzen commented May 7, 2014

@ndhoule @mikermcneil @danielfeelfine @albertosouza @hyzhak @nathanleclaire This has been marked as a feature request. Is there more we need to do here or can we close this? Please tag me @CWyrtzen in your response, thanks~

@mikermcneil

This comment has been minimized.

Copy link
Member

mikermcneil commented May 20, 2014

I recently added sails.request() so you can simulate http requests without lifting the server. Also you can do sails.get() and sails.post() a la express now. Check out the new unit tests in core.

PRs welcome guys- please submit them to sails-generate-test (make the test folder in a new sails app with helpers and stuff)

Thanks
-mm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment