Reputation: 938
I'm having difficulties while executing test script on my node.js
project using Mocha.
Problem is that test script never finishes, unless I finish it manually (ctrl+c). This problem started after I added --timeout
parameter to mocha.opts
. Timeout is added because I use mock-mongoose
library, where suggested timeout is 120000 ms
.
Here is my mocha.opts
:
--require ts-node/register
--watch-extensions ts
--timeout 120000
tests/**/*.ts
Here's code example:
it("POST '/route' should return OK", async () => {
const result = await routeController.createSomething(data)
expect(result.statusCode).is.equal(HttpStatus.OK)
})
I also tried calling done()
function, but still not helping.
My project structure:
node_modules
src
--- source code...
tests
--- tests source...
package.json
package-lock.json
....
Test script: mocha --opts ./tests/mocha.opts
Thanks in advance!
Upvotes: 1
Views: 1079
Reputation: 1831
You can try using the --exit
param which will allow mocha to kill itself.
But the problem here is that you missed to cleanup something in your code.
Read here https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit
You can also try https://github.com/mafintosh/why-is-node-running to pinpoint the reason why your code does not terminate.
Upvotes: 3