angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

feat(test): Add testing support for server. #22

Closed DaftMonk closed 10 years ago

DaftMonk commented 10 years ago

Add mocha test folder for testing server code. grunt test would run through all the mocha tests in addition to the client side karma tests.

Could be integrated with server side generators for automatically generating routes with tests.

iangregsondev commented 10 years ago

I +1 this, with regards to grunt test running through the both client and server tests, maybe it would be better to have different tasks attack client / server tests separately and one task to attack both?

DaftMonk commented 10 years ago

Agreed. Maybe grunt test, grunt test:server, grunt test:client?

iangregsondev commented 10 years ago

Yes, sounds logical. grunt test to run all, and the others to concentrate on the specifics.

DaftMonk commented 10 years ago

Ok, so I'm just trying to decide how to structure the test folder. Would it be confusing to have a folder structure like this?

Rather than

I'd prefer the latter, but if I move the spec folder it will break all existing angular subgenerators because they'll be generating tests in the wrong location.

iangregsondev commented 10 years ago

Yes I prefer the second one, but this will probably make it harder to merge from generator-angular ?

Although if we are going to be changing the structure rather than separating under different testing frameworks, have them separated to /client ... /server ? This i think is more logical ?? Maybe I am wrong ?

/test . /client . /server

or to make merging easier leave the /test alone and create a new structure from the root

/server-test

but this breaks naming standards in my opinion.

I suppose it comes down to what is easiest and more understandable without breaking anything :-)

I would wait for further comments from others.

DaftMonk commented 10 years ago

Sweet, I just found out that the test folder can be set from the bower file! So having a folder structure that's logical shouldn't be a problem.

So now I'm just wondering what is more logical, client/server test folders or mocha/karma. I think that it might be slightly better to say client/server since someone might want to swap out the testing frameworks.

iangregsondev commented 10 years ago

Great! Yes this was my thinking too, the separations should be on the type of technology in my honest opinion i.e. server or client....

People will probably swap them out, i think its even possible to use mocha with angularjs on the client so if we had separation via "type of testing framework" then technically we might mix both client and server tests inside the mocha directory, which wouldn't be good.

Also another thing is that you may have developers working on just the server and others working on just the client.

DaftMonk commented 10 years ago

Totally agree, that makes a lot of sense.

DaftMonk commented 10 years ago

I have a branch that's pretty much ready to go for this, but it depends on generator-karma. We need to be able to configure the path that it sets the karma test folder to. I submitted a PR to generator-karma https://github.com/yeoman/generator-karma/pull/40 for this, just waiting to hear back from them.

matthewrankin commented 10 years ago

@DaftMonk Where are you planning for the e2e tests to reside? Are you thinking of something like this?

./test/client/
./test/e2e/
./test/server/
DaftMonk commented 10 years ago

Actually more like this

./test/client/e2e/
./test/client/spec/
./test/client/mock/
./test/server/
robwil commented 10 years ago

It looks like the generator-karma pull request was merged & closed. Is this ready to go now?

DaftMonk commented 10 years ago

@robwil They haven't published the new version over npm yet. I'll open an issue about it on their repo, but I might just add the server test folder/configuration before they update their generator. This issue has been dragging on for a lot longer than I hoped.

robwil commented 10 years ago

That'd be great, even if you want to put it in a Github branch so we can see the general approach and start migrating (if necessary) our backend tests to that format.

DaftMonk commented 10 years ago

@robwil You got it.

edit: Oh damn. I lost the branch when my github repo got corrupted and I had to pull from the remote version. I'll have to do it again, but it was easy enough to set up.

DaftMonk commented 10 years ago

Added a branch for mocha tests.

ragingwind commented 10 years ago

+1 look forward to release.

fiznool commented 10 years ago

Firstly, I'm new to this project - just wanted to say what an incredibly useful generator this is, thanks for all the hard work.

My question is - I was wondering why the choice was made to use mocha instead of jasmine_node for the server-side code? The latter would allow you to write the same style / syntax tests for both client and server-side (since the upstream generator is using Jasmine). Perhaps not a big deal initially but I would certainly prefer to stick to a single test syntax.

I have a version of this generator using grunt-jasmine-node instead of grunt-mocha-test working on my local copy and would be happy to help if this was something that is deemed important. Otherwise no worries :)