A simple unit test to demonstrate how to use RTD #102

Closed
wants to merge 11 commits into
from

Conversation

Projects
None yet
2 participants
@D-Ne0
Contributor

D-Ne0 commented May 12, 2014

The concept behind RTD unit testing framework is to test app code in a non-meteor context environment. This means Meteor objects, it's packages etc. are not available during testing. So, while I was testing a template function, there were alot of errors like 'undefined is not an object "Template.server_channels"'. To remove these error I tried following techniques:

  1. As suggested by RTD author: Create stubs for whatever you require in unit testing. Refer to this for more details: xolvio/rtd#87. But this was not feasible because I had to create too many stubs.
  2. Then I looked at test/karma.conf.js(originally present in dir node_modules/rtd). It has a configuration variable called 'files' which allows you to load only specific app files, thus removing the pain of creating any extra stubs. You can find in this pull request that I am loading only one app file(from test/karma.conf.js) which I had tested(test/client/chat/chat_connections/channels.js) and created stubs for only that file.

Conclusion: This is the best approach I could think of to unit test Waartaa. Since alot of code has already been written in Waartaa and RTD follows TDD techinque. So I think the only way to unit test is to load only those files(by specifying it in test/karma.conf.js) which you want to unit test.

Let me know If this approach suits you.

PS: Please also look at the directory structure inside test/unit/client where the first test is placed.

@D-Ne0

This comment has been minimized.

Show comment
Hide comment
@D-Ne0

D-Ne0 May 12, 2014

Contributor

Oops clicked the submit button soon!

To install RTD just run:

npm install

since I have already updated the package.json file.

Contributor

D-Ne0 commented May 12, 2014

Oops clicked the submit button soon!

To install RTD just run:

npm install

since I have already updated the package.json file.

@@ -16,7 +16,7 @@ Template.server_channels.channels = function (server_id) {
}
function serverChannelsCreatedCallback () {
- $('#chat-servers .nano').nanoScroller();
+ $('#chat-servers .nan').nanoScroller();

This comment has been minimized.

@rtnpro

rtnpro May 13, 2014

Member

why nano to nan?

@rtnpro

rtnpro May 13, 2014

Member

why nano to nan?

This comment has been minimized.

@D-Ne0

D-Ne0 May 13, 2014

Contributor

Sorry, that was a mistake.

@D-Ne0

D-Ne0 May 13, 2014

Contributor

Sorry, that was a mistake.

+ describe("Template.server_channels.channels", function () {
+
+ it("asks for channels to be in alphabetical order, to not have last_updated field, to be active", function () {
+ var someLocaliCollectionCursor = {};

This comment has been minimized.

@rtnpro

rtnpro May 13, 2014

Member

Typo? shouldn't it be someLocalCollectionCursor?

@rtnpro

rtnpro May 13, 2014

Member

Typo? shouldn't it be someLocalCollectionCursor?

This comment has been minimized.

@D-Ne0

D-Ne0 May 13, 2014

Contributor

Yes.

@D-Ne0

D-Ne0 May 13, 2014

Contributor

Yes.

@rtnpro

This comment has been minimized.

Show comment
Hide comment
@rtnpro

rtnpro May 18, 2014

Member

@D-Ne0 Can you please rebase this branch on top of latest master? I want to try it out. Please let me know after rebasing it.

Member

rtnpro commented May 18, 2014

@D-Ne0 Can you please rebase this branch on top of latest master? I want to try it out. Please let me know after rebasing it.

@D-Ne0

This comment has been minimized.

Show comment
Hide comment
@D-Ne0

D-Ne0 May 18, 2014

Contributor

@rtnpro Done. And I hope I have rebased it correctly.

Contributor

D-Ne0 commented May 18, 2014

@rtnpro Done. And I hope I have rebased it correctly.

@rtnpro

This comment has been minimized.

Show comment
Hide comment
@rtnpro

rtnpro May 20, 2014

Member

@D-Ne0

I have merged your code here: https://github.com/waartaa/waartaa/tree/tests.

How do I run the tests?

I am getting the following error:

./node_modules/rtd/rtd --debug
Running "bgShell:killAll" (bgShell) task
[D] Task source: /home/vagrant/waartaa/node_modules/rtd/node_modules/grunt-bg-shell/tasks/bg-shell.coffee

Running "downloadAndOrStartSelenium" task
[D] Task source: /home/vagrant/waartaa/node_modules/rtd/Gruntfile.js
Fatal error: spawn ENOENT
[vagrant@localhost waartaa]$ ./node_modules/rtd/rtd
Fatal error: spawn ENOENT
Member

rtnpro commented May 20, 2014

@D-Ne0

I have merged your code here: https://github.com/waartaa/waartaa/tree/tests.

How do I run the tests?

I am getting the following error:

./node_modules/rtd/rtd --debug
Running "bgShell:killAll" (bgShell) task
[D] Task source: /home/vagrant/waartaa/node_modules/rtd/node_modules/grunt-bg-shell/tasks/bg-shell.coffee

Running "downloadAndOrStartSelenium" task
[D] Task source: /home/vagrant/waartaa/node_modules/rtd/Gruntfile.js
Fatal error: spawn ENOENT
[vagrant@localhost waartaa]$ ./node_modules/rtd/rtd
Fatal error: spawn ENOENT
@D-Ne0

This comment has been minimized.

Show comment
Hide comment
@rtnpro

This comment has been minimized.

Show comment
Hide comment
@rtnpro

rtnpro May 26, 2014

Member

Merged.

Member

rtnpro commented May 26, 2014

Merged.

@rtnpro rtnpro closed this May 26, 2014

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