0

我正在将 Express 应用程序转换为 Locomotive,但我无法弄清楚如何迁移我的测试。

在 Express 中,我只是在我的/test/test.api.organization.js文件中执行此操作:

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 );
    });
  });
}

就是这样 - 只需require'ing 应用程序文件就足够了。但是 Locomotive 没有app.jsorserver.js文件,服务器只是从命令行用lcm server.

如何启动服务器/应用程序并使我的测试再次工作?

4

1 回答 1

2

您可以自己启动 Locomotive 应用程序:

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 是您的 Locomotive 项目所在的目录,ENVIRONMENT 是您希望 Locomotive 应用程序运行的环境(通常test)。

于 2013-01-10T07:20:47.530 回答