0

My Meteor Server method calls another server to retrieve data first, cache in mongo db and then respond to request. I want to test my server code using Meteor with Velocity.

For unit test, I have a json file containing sample response from the api but I do not know how could I load that file to mock as api response for server test. Since it is server test, I cannot access jquery or getJSONFixtures() from jasmine-jquery.

How can I load that json file in my server test code?

EDIT As from this answer I do not want to put my test resource files bundled as assets in /private directory

Community
  • 1
  • 1
surenyonjan
  • 2,097
  • 3
  • 17
  • 26
  • 2
    Possible duplicate of [Meteor: reading simple JSON file](http://stackoverflow.com/questions/24474675/meteor-reading-simple-json-file) – Brett McLain Dec 09 '15 at 15:50
  • @sparticus what is `private` directory? Is it good place to store my test resource file? – surenyonjan Dec 09 '15 at 15:57
  • The private directory is where you place server-side assets (not code). JSON files fall into this category. Just create a directory called "private" in your root meteor directory and place the JSON in there. Read more about private directories here: http://stackoverflow.com/questions/21172215/meteor-private-subdirectory – Brett McLain Dec 09 '15 at 16:02
  • yes the json file is definitely not code. However, there is some distinction between assets and test resources. When I deploy my code I would not like to publish my tests files. There can be multiple test resources, what you say? – surenyonjan Dec 09 '15 at 16:06
  • In the private folder I would just create a sub folder called "test". You might be able to configure your meteor build to not include that directory, or do some fancy directory linking to provide access to your test resources without having them included in the build. – Brett McLain Dec 09 '15 at 16:08
  • can you provide some helpful links not to include some files in some specific build? – surenyonjan Dec 09 '15 at 17:29

1 Answers1

0

Thanks for the nice suggestion from @sparticus.

This solved my problem:

  1. Put all your test resource files in ./tests directory. Mine is inside ./tests/resources/**/*
  2. For every gulp task to run test (gulp test) first copy them to private directory ./private/tests. Then your test files will be available as Assets.getText(<filename>).
  3. Make sure you also clean ./private/tests directory while you run any new tasks

This made me sure that my test resource files are not bundled during deployment.

surenyonjan
  • 2,097
  • 3
  • 17
  • 26