mardi 22 décembre 2015

How can I deliver async integration testing using npm library?

I maintain a set of middleware that is required to produce valid GeoJSON in order to power its resulting service. There is an npm module that can perform the linting based on a String or object. Since the middleware itself is not in node, I'd like to have a test-suite for the middleware that uses npm as an integration testing suite, ensuring that each endpoint is producing valid GeoJSON.

I am using mocha, but apart from that, I am open to any framework that produces results. (I've tried Q, q-io, async-arrays, and a few others.)

Here's a synchronous-style writeup of what I'm aiming for:

describe('testPath()', function() {
    it("should be a function", function () {
      expect(geojsonLint.testPath).to.be.a('function')
    });

    it("should test a path", function () {
      var firstPath = geojsonLint.findEndpoints()[0];
      expect(geojsonLint.testPath(firstPath)).to.be.true
    });
});

Then, building on that, a synchronous version of testing all the paths might look like this:

describe('testAllPaths()', function() {
    it("should test a path", function () {
      geojsonLint.findEndpoints().map(function(path) {
         expect(geojsonLint.testPath(path)).to.be.true
      }
    });
});

I've altered my implementation of testPath significantly many times, but the most illustrative attempt is the following:

  testPath: function (path, callback) {
    return request('http://localhost:5000/'+path, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        callback(geojsonhint.hint(body), error, response);
      } else {
        callback(body, error, response);
      }
    });
  }

I can ensure that the middleware is running locally on another port, in the event of a successful request, I'd like the results passed to geojsonhint.hint. Ultimately, I'd like to verify the results of that call are empty.

My efforts so far are available, but I'd qualify them as poor.

Any fixed point on which to build is appreciated.

Aucun commentaire:

Enregistrer un commentaire