How to start Locomotive server/app for integration testing?

我与影子孤独终老i 提交于 2019-12-13 07:23:27

问题


I am converting an Express app to Locomotive and I cannot figure out how to migrate my tests.

In Express, I simply did this in my /test/test.api.organization.js file:

var app = require("../app").app,
  request = require("supertest");
  should = require("should");

describe("Organization API", function() {
  it( "GET /api/v1/organizations should return status 200 and Content-Type: application/json.", function (done) {
    postReq.done( function () {
      request(app)
        .get( "/api/v1/organizations" )
        .set( "Authorization", authData )
        .expect( 200 )
        .expect( 'Content-Type', /application\/json/, done );
    });
  });
}

And that was it - simply require'ing the app file was enough. But Locomotive does not have an app.js or server.js file, the server is started simply from command line with lcm server.

How can I start the server/app and make my tests work again?


回答1:


You can boot the Locomotive app yourself:

var locomotive = require('locomotive');

describe('Test Name', function() {
  before(function(done) {
    // instantiate locomotive app
    this.app = new locomotive.Locomotive();
    this.app.boot(ROOTDIRECTORY, ENVIRONMENT, function() {
      done();
    });
  });
  // your test cases
});

ROOT_DIRECTORY is the directory where your Locomotive project lives, ENVIRONMENT is the environment in which you want your Locomotive app to run (usually test).



来源:https://stackoverflow.com/questions/14216861/how-to-start-locomotive-server-app-for-integration-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!