簡體   English   中英

NodeJS測試-公開應用

[英]NodeJS Tests - exposing app

我正在用supertest測試我的NodeJS應用程序。 在app.js的結尾,我公開了我的應用程序,因此可以在test.js中使用它。

///////////////////
// https options
var options = {
    key: fs.readFileSync("./private/keys/Server.key"),
    cert: fs.readFileSync("./private/certs/Server.crt"),
    ca: fs.readFileSync("./private/ca/CA.crt"),
    requestCert: true,
    rejectUnauthorized: false
};

///////////////////
// start https server
var server = https.createServer(options, app).listen(app.get("port"), function(){
    console.log('Server listening on port ' + app.get('port'));
});

exports = module.exports = server;


當我在test.js中要求服務器時,選項路徑會導致錯誤,因為test.js位於目錄./test/test.js中,而app.js位於./app.js中。

我正在努力為這個問題找到一個干凈的解決方案。

如果您將選項放入模塊中,則可以直接使用它,也可以使用諸如rewiresandboxed-module之類的東西在測試中存根它

或者,您可以修改導出以接受選項作為參數,以便通過例如require('server')(config)進行選擇

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM