SBoudrias / gulp-istanbul

Istanbul unit test coverage plugin for gulp.
MIT License
186 stars 87 forks source link

Using Istanbul with Parse-Server #107

Open majidhassan opened 8 years ago

majidhassan commented 8 years ago

Hello,

I'm trying to use gulp-istanbul with gulp-mocha to get coverage on my parse-server API, but I can't seem to get any coverage on my cloud files.

This is my gulpfile.js:

var gulp = require('gulp'),
    mocha = require('gulp-mocha'),
    istanbul = require('gulp-istanbul'),

    JS_PATH_SERVER = "/home/parse/cloud_dir/cloud/",
    TEST_PATH_SERVER = "./tests/";

function handleError(err) {
  console.error(err);
}

// Run Node.js tests and create LCOV-format reports with Istanbul
gulp.task('test-server', function () {
  return gulp.src([JS_PATH_SERVER + '**/*.js'])
      .pipe(istanbul({includeUntested: true})) // Node.js source coverage
      .on('end', function () {
          gulp.src(TEST_PATH_SERVER + '**/*.js')
              .pipe(mocha({
                  reporter: 'spec'
              }))
              .on('error', handleError)
              .pipe(istanbul.writeReports('reports')); // Creating reports
      });
});

And the following is a sample from my mocha tests:

var supertest = require("supertest");

var server = supertest.agent("http://localhost:1337/parse/");
var headers = {"X-Parse-Application-Id": "myappid", "Content-Type": "application/json"};

// UNIT test begin

describe("SAMPLE unit test",function(){
    it("should get constants", function(done) {
    server
        .post('functions/getConstants')
        .set(headers)
        .expect(200)
        .end(function(err, res) {
            done();
        });
  });
});

Any ideas, what I might be doing wrong?

majidhassan commented 8 years ago

I also tried running Parse as an express app, then passing it to supertest. But none of that worked. Using this approach I even got the 0% issue even when passing includeUntested: true.

This is my test case, including Parse Server instantiation.

var app_id = "<actual app id>";
var headers = {"X-Parse-Application-Id": app_id, "Content-Type": "application/json"};

// SETUP PARSE

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');

var api = new ParseServer({
  databaseURI: "<actual mongo URI>",
  cloud: "<actual cloud path>",
  appId: app_id,
  masterKey: "<actual master key>",
  serverURL: "http://localhost:1337/parse"
});

var app = express();

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var httpServer = require('http').createServer(app);
httpServer.listen(1337, function() {
    console.log('parse-server-example running on port ' + 1337 + '.');
});

// END OF PARSE SETUP

var request = require('supertest');
// var test_api = request.agent("http://localhost:1337/parse/");
var test_api = request.agent(app);

// UNIT test begin

describe("SAMPLE unit test", function() {
    it("should get constants", function(done) {
    test_api
        .post('functions/getConstants')
        .set(headers)
        .expect(200)
        .end(function(err, res) {
            done();
        });
    });
});