question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Curl` call wrapped within a Promise makes mocha not finishing test cases.

See original GitHub issue

Sorry if this is not a right place but I’m looping with a debugger for hours already and I think I am out of ideas of what can be wrong.

tldr; testing with mocha is highly unreliable, usually times out

Longer story

I’m using this package for a long time and first I’d like to thank all the contributors for amazing work you do. Thank you.

Today I decided to update my small library by bumping node-libcurl to latest version.

I have small regression/integration test and I found most of them (sometimes all) fail after upgrade with no good reason.

I spent hours trying to detect the issue in my code but I’m pretty sure there is some bug in this code.

I’ve made a smallest as possible test to prove that: https://github.com/sznowicki/uptime-check/blob/node-libcurl-2/test/node-libcurl-issue-test.js

In this file you’ll find three test cases: curl pure implementation, curl wrapped in a promise and called in traditional way, same wrapped curl called in async/await way.

While pure implementation always succeeds (also tried placing it last), Promise.then always times out, async/await usually times out but sometimes is surprisingly green (slow though).

To be honest, I don’t have a good idea why this package would cause this behaviour from mocha, but I did try many ways of testing that to exclude other possibilities.

It just feels like something either overrides mocha’s “done/await” checks.

On way of testing was to resolve early, before Curl is involved and this made the tests finishing again (also included in the test cases I posted). And I think this is a very good reason to post this issue here and not in the mocha repo.

If you have any questions, or concerns I promise to be active in this issue.

If I missed something stupid and obvious, I’d like to apologise in advance.

PS: maybe it matters: node v10.2.1

EDIT:

  • The mentioned test is all green with node-libcurl@1.3.3
  • my system: macOS 10.14.5
  • url used in test doesn’t play any role in this, original tests were testing against a real website under my control

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:31 (22 by maintainers)

github_iconTop GitHub Comments

4reactions
as-comcommented, Jun 30, 2019

For those following along by email: the comment above has been updated with a band-aid solution to this bug.

tl;dr: wrap your resolve call in setImmediate.

3reactions
JCMaiscommented, Apr 10, 2020

296 days later this has been finally fixed 🎉🥳, for details see the issue above.

The fix is available on the prerelease version 2.1.0-4, which can be installed with:

yarn add node-libcurl@next

If everything works correctly, I will release the 2.1.0 version at the start of next week, I will close this issue when I do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha does not seem wait for promise chain to complete ...
Mocha expects a promise to be returned by a function for it to wait. Either explicitly return a promise from plain functions or...
Read more >
testdouble - npm
If sends-invoice exports a plain object of function properties, an object will be returned with test double functions in place of the originals' ......
Read more >
Our Express.js REST API series ends with a bang ... - Toptal
Learn how to add a Dockerized MongoDB instance, Mongoose, JWT authentication, user permissions, and automated testing with Mocha, Chai, and SuperTest.
Read more >
Deno 1.15 Release Notes
The new API is general enough so it can be wrapped by polyfills to emulate existing test frameworks like mocha or node-tap ....
Read more >
Testing with Node and Docker Compose, Part 2
complete call can finish after the component has been unmounted, in which case trying to update the state is an error. The unmounted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found