Skip to content
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

feat(server-tests): code coverage and e2e #505

Merged
merged 2 commits into from
Aug 30, 2014

Conversation

kingcody
Copy link
Member

Changes:

  • split server tests into unit and e2e type test
  • adjust mochaTest and test:server tasks to reflect the two types of tests
  • implement grunt-mocha-istanbul task for server-side code coverage
  • add test:coverage task
  • improve mocha.conf.js
  • add sinon, expect, and assert as globals to server/.jshintrc-spec
  • add proxyquire to the app for better stubbing in unit tests
  • improve test to reflect recent changes and to lay ground work for more coverage

Grunt Task test:
The grunt 'test' task now has a 'coverage' target. Used like so grunt test:coverage.
This task will run istanbul for the server unit tests and e2e test separately.
The resulting coverage reports will be placed in coverage/(unit|e2e). There is also an option
for the test:coverage task, possibilities for option are:

  • unit
  • e2e
  • check

test:coverage:check will check the coverage reports for both unit and e2e and
report whether or not they meet the required coverage.

Changes:
- add `mocha.conf.js` and use it as a `require` in `mochaTest` task
- switch `should.js` for `mocha-chai`
- change server-side test assertions to user chai assertions

Breaking Changes:
- should.js is no longer included, chai assertions should be used instead.
@kingcody
Copy link
Member Author

Depends on #500

@kingcody kingcody changed the title feat(app): code coverage feat(server-tests): code coverage Aug 30, 2014
Changes:
- split server tests into `unit` and `e2e` type test
- adjust `mochaTest` and `test:server` tasks to reflect the two types of tests
- implement `grunt-mocha-istanbul` task for server-side code coverage
- add `test:coverage` task
- improve `mocha.conf.js`
- add sinon, expect, and assert as globals to `server/.jshintrc-spec`
- add `proxyquire` to the app for better stubbing in unit tests
- improve test to reflect recent changes and to lay ground work for more coverage

Grunt Task `test`:
The grunt 'test' task now has a 'coverage' target. Used like so `grunt test:coverage`.
This task will run istanbul for the server unit tests and e2e test separately.
The resulting coverage reports will be placed in `coverage/(unit|e2e)`. There is also an option
for the `test:coverage` task, possibilities for option are:
- `unit`
- `e2e`
- `check`

`test:coverage:check` will check the coverage reports for both `unit` and `e2e` and
report whether or not they meet the required coverage.
@kingcody kingcody force-pushed the feature/mocha-istanbul branch from bc21e25 to dbbaa20 Compare August 30, 2014 16:01
@kingcody kingcody changed the title feat(server-tests): code coverage feat(server-tests): code coverage and e2e Aug 30, 2014
DaftMonk added a commit that referenced this pull request Aug 30, 2014
feat(server-tests): code coverage and e2e
@DaftMonk DaftMonk merged commit 4babb07 into angular-fullstack:canary Aug 30, 2014
@kingcody
Copy link
Member Author

@DaftMonk any thoughts on the direction I took with the tests/setup?

@kingcody kingcody deleted the feature/mocha-istanbul branch August 30, 2014 18:24
@DaftMonk
Copy link
Member

Sorry, I only meant to merge #500 but I somehow must have merged this before I was able to review it.

I have some questions/comments.

I do understand you're trying to draw a distinction between unit tests and integration tests, but calling them e2e tests might be confusing, since we already have e2e tests with protractor.

Don't really like using return statements in the expectations, they aren't really adding anything.

I'm a bit confused about what the index.spec.js files are testing, and where the index.js is being tested from those tests. Edit: Nevermind, I see how these tests work now. Looks good, but I think I might want to make it a bit more clear where the stubs are being injected into the index file.

@kingcody
Copy link
Member Author

Suggestions for e2e alternative name? I'm in no way bias.

The return statements are because jshint see the assertion as just a property lookup. We can adjust .jshintrc-spec if you like.

@kingcody
Copy link
Member Author

Make stub injection clearer: comment proxyquire usage? Or do we need to break those definitions up more?

describe('.authenticate()', function() {

it("should authenticate user if password is valid", function() {
return user.authenticate('password').should.be.true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaftMonk this is the jshint expr issue. This line and 62 are considered expressions only. Most of the other assertions that return are returning a promise to be asserted by mocha.

Edit: actually most of the assertions in the index.spec.js test fall under the expression issue

@kingcody
Copy link
Member Author

@DaftMonk here's a small refactor branch with some of the changes you mentioned, a few performance improvements, and clean task to remove old coverage reports. Let me know what you'd like to do about e2e and anything else you see in 519f628

@kingcody
Copy link
Member Author

kingcody commented Sep 3, 2014

Ok, not sure how I missed it or why I was getting expression lint errors, but I do see that "expr": true is set in the server's .jshintrc file. Also I'm not getting those errors anymore, perhaps I was just tired idk. Either way, we can remove any non-promise return from the tests without any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants