totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Only setup F.listener but don't create server #589

Closed ckpiggy closed 6 years ago

ckpiggy commented 6 years ago

I'm writing a endpoint test for my api. Instead of creating a http server, I want to use the listener function to simulate the server How can I got a full function F.listener without creating a http server listening any port?

Currently I create a method in index.js

F.prepare_listener = function(){
    const http = require('http')
    extend_request(http.IncomingMessage.prototype)
    extend_response(http.ServerResponse.prototype)
    F.$configure_configs()
    F.$configure_versions()
    F.$configure_workflows()
    F.$configure_sitemap()
    F.isTest && F.$configure_configs('config-test', true)
}

But actually, I don't know if this is a proper way to setup the listener. How should I do?

petersirka commented 6 years ago

Why don't you want to create a server? It's a big problem to simulate the server.

ckpiggy commented 6 years ago

I just figure out I can use F.http to start a server before all the test start and use F.listener with supertest XD