loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.96k stars 1.07k forks source link

Minor: mocha never finishes because it no longer receives the --exit option #2403

Closed joeytwiddle closed 4 years ago

joeytwiddle commented 5 years ago

Description / Steps to reproduce / Feature proposal

  1. On a default project, add some annoying code:
    echo "setInterval(() => console.log('nasty loop'), 60000);" \
        >> src/controllers/ping.controller.ts
  2. Run npm test

Current Behavior

After the tests have passed, mocha blocks. The process never ends.

Expected Behavior

After the tests have passed, mocha should exit back to the command-line.

Additional

I guess that --exit is the desired behaviour, because I see it in packages/build/config/mocha.opts.

But it doesn't appear in generators/project/templates/test/mocha.opts (if it did then I guess that would close the issue).

The change happened somewhere between version 1.0.0 and 1.0.1 of @loopback/build

git diff @loopback/build@1.0.0 @loopback/build@1.0.1 packages/build

It looks like the new behaviour is to only use the default mocha.opts if there is no test/mocha.opts in the project.

Whether --exit is really desirable is up to you! But I feel the "default fallback" opts should be closer to the "template default".

Workaround for consumers

When I encountered this problem, I simply added --exit to our project's test/mocha.opts to fix it.

Another workaround might be to find and destroy whatever is keeping the mocha process alive. You may use why-is-node-running to help with that.

Acceptance criteria


šŸŽ† Hacktoberfest 2020

Greetings :wave: to all Hacktoberfest 2020 participants!

Here are few tips šŸ‘€ to make your start easier, see also #6456:

bajtos commented 5 years ago

Thank you @joeytwiddle for reporting the problem! I vaguely remember that some of LB connectors may be keeping the process running because of the connection pool they use in background (and don't unref it as they should).

I think it will be best to add --exit to the mocha opts file template we use for new projects. Would you like to contribute this change?

@strongloop/loopback-maintainers any objections or other proposals?

simlt commented 4 years ago

Hi, I am currently having a similar problem on a loopback project when using the mssql connector, so I wanted to contribute. I can confirm that enabling the exit option for mocha solved the problem.

I'm leaving a comment just to let others know that I want to take care of this issue.

dhmlau commented 4 years ago

Thanks @simlt. Let me assign it to you.

bajtos commented 4 years ago

closing as done via #6475