簡體   English   中英

擺攤摩卡

[英]Sequelize stalls mocha

我正在嘗試測試我的路線和控制器。 這是我編寫的演示測試,以查看一切是否正常運行。

 import chai from "chai"; import chaiHttp from "chai-http"; import chaiAsPromised from "chai-as-promised"; import sinon from "sinon"; import sinonChai from "sinon-chai"; import wtfnode from "wtfnode"; import UserRepo from "../repositories/userRepository"; import server, { stopServer } from "../app"; import db from "../models/index"; wtfnode.init(); chai.use(chaiHttp); chai.use(chaiAsPromised); chai.use(sinonChai); chai.should(); describe("TEST", () => { describe("Happy Path", () => { before(() => { sinon.stub(UserRepo, "getUsers"); const users = [ { id: 1, first_name: "test", last_name: "test" }, { id: 2, first_name: "test", last_name: "test" }, { id: 3, first_name: "test", last_name: "test" }, { id: 4, first_name: "test", last_name: "test" }, { id: 5, first_name: "test", last_name: "test" } ]; UserRepo.getUsers.returns(users); }); it("Retrieves users from the database and renders an index page displaying all the users", done => { chai .request(server) .get("/admins/users") .end((err, res) => { res.should.have.status(200); UserRepo.getUsers.should.have.been.calledOnce; done(); }); }); after(() => { UserRepo.getUsers.restore(); stopServer(); db.sequelize.close(); wtfnode.dump(); }); }); }); 

下面的代碼段顯示了如何在“ app.js”中導出服務器

 const server = app.listen(port, () => { /* eslint-disable no-console */ console.log(`App Running on port ${port}`); /* eslint-enable no-console */ }); export const stopServer = () => { console.log("Shutting the server"); server.close(); }; export default server; 

盡管我正在嘗試關閉服務器並關閉數據庫連接,但是摩卡無法正常退出

因此,我包括了wtfnode,以查看哪些進程阻止了Mocha正常退出。 wtfnode報告如下所示:

 [WTF Node?] open handles: - File descriptors: (note: stdio always exists) - fd 1 (tty) (stdio) - fd 2 (tty) (stdio) - Sockets: - (?:?) -> null:? (destroyed) - IP ADDRESS:52510 -> IP ADDRESS:3306 - Timers: Unable to determine callsite for "bound". Did you require `wtfnode` at the top of your entry point? - (10000 ~ 10 s) bound @ unknown:0 - (10000 ~ 10 s) (anonymous) @ C:\\GVW6\\node_modules\\generic-pool\\lib\\Pool.js:389 - (9999 ~ 9 s) bound @ C:\\GVW6\\node_modules\\generic-pool\\lib\\ResourceRequest.js:48 

據我了解,端口3306上運行的進程阻止了Mocha退出,而端口3306是我的數據庫服務器。

任何幫助將不勝感激

應用程序中還有另一個實例化序列化的腳本。 該腳本未關閉連接。 在此添加了關閉命令並解決了該問題。 謝謝大家的幫助:)

暫無
暫無

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

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