I tried to run the test in another machine and I get a different error:
> server@1.0.0 test /mnt/data/Desenvolvimento/workspace/mflix-js
> jest --passWithNoTests "mongoclient"
Determining test suites to run...Setup Mongo Connection
(node:22321) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.
FAIL test/lessons/mongoclient.spec.js (12.622s)
MongoClient
✓ Client initialized with URI (1968ms)
✓ Client initialized with URI and options (1766ms)
✓ Database handle created from MongoClient (2095ms)
✕ Collection handle created from database handle (2025ms)
● MongoClient › Collection handle created from database handle
expect(received).toBeNull()
Received: [MongoError: user is not allowed to do action [find] on [sample_mflix.movies]]
135 | expect(numMoves).toBe(23539)
136 | } catch (e) {
> 137 | expect(e).toBeNull()
| ^
138 | } finally {
139 | testClient.close()
140 | }
at toBeNull (test/lessons/mongoclient.spec.js:137:17)
at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
at Generator.prototype.(anonymous function) [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 3 passed, 4 total
Snapshots: 0 total
Time: 12.993s, estimated 16s
Ran all test suites matching /mongoclient/i.
Teardown Mongo Connection
Jest did not exit one second after the test run has completed.
Those are different Linux machines, where the version of the dependencies may differ (for example, in the first one I have the mongo client version 3.6 and in the second one version 4.2).
Update:
In this second machine, when I raise the connectTimeoutMS
to, say, 20000, it works!
So, what could be wrong with the first one? There the error happens in the test/config/mongoEnvironment.js
at the teardown()
function. I’ ve seen posts here where people also have the same error, but I’m not sure what the solution is…