javascriptjsonmeteormeteor-velocity

how to load json file in meteor server side test


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


Solution

  • 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.