dimanche 28 juin 2015

Meteor testing: read from fixture

I would like to know how to use fs.readFileSync to read from a fixture file while testing my Meteor app with Jasmine and Velocity.

I am testing a method that makes an external API call, and I want to mock the response. I have saved a sample .xml response from the API in the tests directory. My plan is to read from that file, and mock the response.

But I am not able to read that file because Meteor does not include it when building the app. Here is an error I get:

'/Users/mikecho/myApp/.meteor/local/build/programs/server/sample_response.xml'

How can I read from this file? Or is there a better way to mock this third party API response?

Here is how I am stubbing the response:

var fs = Meteor.npmRequire('fs');
var path = Meteor.npmRequire('path');

HTTP = {
  get: function (url) {
    var sampleResponse = path.resolve('./sample_response.xml');

    return {
      content: fs.readFileSync(sampleResponse)
    };
  }
};

Aucun commentaire:

Enregistrer un commentaire