English 中文(简体)
如何以正确的方式从测试网中发射服务器?
原标题:What is the correct way to launch your server from vows for testing?

我有一个专用服务器,我正在使用电网进行测试。 我想从ow子测试套中操作服务器,这样,我就迫切需要使服务器在背景中运行,以便测试套能运行。 因此,我只能产生一个驾.任务,管理服务器,孤立地测试服务器。

<编码>server.coffee 我建立了(快车)服务器,配置了该服务器,铺设了线路,并称之为像仪表:

# Express - setup
express = require  express 
app = module.exports = express.createServer()

# Express - configure and set up routes
app.configure ->
   app.set  views , etc....
   ....

# Express - start
app.listen 3030

在我简单的<密码>中,js 我有:

vows    = require( vows ),
assert  = require( assert ),
server  = require( ../app/server/server );

// Create a Test Suite
vows.describe( routes ).addBatch({
     GET /      : respondsWith(200),
     GET /401   : respondsWith(401),
     GET /403   : respondsWith(403),
     GET /404   : respondsWith(404),
     GET /500   : respondsWith(500),
     GET /501   : respondsWith(501)
}).export(module);

<代码>respondsWith(代码)在功能上与ows doc中的功能相似。

When I require server in the above test, it automatically begins running the server and the tests run and pass, which is great, but I dont feel like I am doing it the right way.

I dont have much control over when the server begins, and what happens if I want to configure the server to point to a test environment rather than the default one, or change the default logging level for when im testing?

我会把我的ow子改换成咖啡,但现在,它都是在 j子里,就像从docs中学习一样!

最佳回答

这是一个令人感兴趣的问题,因为昨天晚上我确实想做些什么。 我的口号是小的Coffe。 之后,我对其作了重新评价,创建了以下<代码>app.coffee:

# ... Imports
app = express.createServer()

# Create a helper function
exports.start = (options={port:3000, logfile:undefined})->
  # A function defined in another module which configures the app
  conf.configure app, options 
  app.get  / , index.get
  # ... Other routes
  console.log  Starting... 
  app.listen options.port

现在,我有一个<代码>index.coffee(相当于server.coffee)简单明了:

require( ./app ).start port:3000

然后,我用

app = require( ../../app )
# ...

# To avoid annoying logging during tests
logfile = require( fs ).createWriteStream  extravagant-zombie.log 

# Use the helper function to start the app
app.start port: 3000, logfile: logfile

describe "GET  / ", ->
  it "should have no blog if no one was registered", ->
    zombie.visit  http://localhost:3000 , (err, browser, status) ->
      expect(browser.text  title ).toEqual  My Title 
      asyncSpecDone()
    asyncSpecWait()

问题在于:我做了些什么,我建议是在一个从服务器开始的模块中设立一个职能。 然后,只要你想要,就把这一职能称作你。 我不知道这是否是“良好设计”,但它对我来说是可行和实用的。

此外,我怀疑诺德.js和Coffe贝里没有“良好设计”。 这些是新的、非常创新的技术。 当然,我们可以“失败”——就像这种局面一样,有两个不同的人喜欢设计并改变了设计。 我们可以感觉到“错误方式”,但这并不意味着已经存在“正确方式”。 最后,我认为,我们必须在你的发展中发明一些“正确方式”:

(最好也询问如何做事。) 也许有人有好的想法,公众讨论将有利于其他发展者。

问题回答

暂无回答




相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签