Skip to content

TypeError: Cannot read property 'getConnectionString' of undefined #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ojongerius opened this issue Apr 25, 2018 · 4 comments
Closed

Comments

@ojongerius
Copy link

Hey there!

If I pull down your repo and npm install like so:

git clone [email protected]:vladgolubev/jest-mongodb.git && cd jest-mongodb
npm install

Running Jest will fail like so:

▶ jest

 RUNS  ./mongo-insert.test.js
 FAIL  ./mongo-aggregate.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getConnectionString' of undefined

       9 |     console.log('Setup MongoDB Test Environment');
      10 |
    > 11 |     this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString();
      12 |     this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__;
      13 |
      14 |     await super.setup();

      at MongoEnvironment.setup (mongo-environment.js:11:57)

 FAIL  ./mongo-insert.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getConnectionString' of undefined

       9 |     console.log('Setup MongoDB Test Environment');
      10 |
    > 11 |     this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString();
      12 |     this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__;
      13 |
      14 |     await super.setup();

      at MongoEnvironment.setup (mongo-environment.js:11:57)

Test Suites: 2 failed, 2 total
Tests:       0 total
Snapshots:   0 total
Time:        0.409s
Ran all test suites.
Teardown mongod

If I run with --runInBand will succeed:

▶ jest --runInBand
Setup MongoDB Test Environment
 PASS  ./mongo-insert.test.js
Teardown MongoDB Test Environment
Setup MongoDB Test Environment
 PASS  ./mongo-aggregate.test.js

Test Suites: 2 passed, 2 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        1.504s
Ran all test suites.
Teardown mongod
Teardown MongoDB Test Environment

And Jest runs that use the cache will succeed to unless you either manually remove the cache or pass --no-cache, ie:

▶ jest
Setup MongoDB Test Environment
 PASS  ./mongo-insert.test.js
Teardown MongoDB Test Environment
Setup MongoDB Test Environment
 PASS  ./mongo-aggregate.test.js

Test Suites: 2 passed, 2 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        1.089s
Ran all test suites.
Teardown mongod
Teardown MongoDB Test Environment

~/jest-mongodb  master ✗                                                                                        68d ⚑
▶ jest --no-cache

 RUNS  ./mongo-insert.test.js
 FAIL  ./mongo-insert.test.js.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getConnectionString' of undefined

       9 |     console.log('Setup MongoDB Test Environment');
      10 |
    > 11 |     this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString();
      12 |     this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__;
      13 |
      14 |     await super.setup();

      at MongoEnvironment.setup (mongo-environment.js:11:57)

 FAIL  ./mongo-aggregate.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getConnectionString' of undefined

       9 |     console.log('Setup MongoDB Test Environment');
      10 |
    > 11 |     this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString();
      12 |     this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__;
      13 |
      14 |     await super.setup();

      at MongoEnvironment.setup (mongo-environment.js:11:57)

Test Suites: 2 failed, 2 total
Tests:       0 total
Snapshots:   0 total
Time:        0.44s
Ran all test suites.
Teardown mongod
@ojongerius
Copy link
Author

ojongerius commented Apr 25, 2018

Aha! Judging by your package.json you do run jest --runInBand https://github.com/vladgolubev/jest-mongodb/blob/4b31ee4e4c40c6d939ba4791ff971050bfd92219/package.json#L18

Shall I resurrect #2 ? I'd still like to understand why this is happening 😀

@ojongerius
Copy link
Author

Aha, related issue at jestjs/jest#5731

@ojongerius
Copy link
Author

I've raised jestjs/jest#6063 and created https://github.com/ojongerius/jest-bug to make it easier for the Jest folks to validate this happens against recent versions of all the things.

@vladholubiev
Copy link
Member

vladholubiev commented Jul 21, 2018

@ojongerius I just updated jest and mongodb to the latest versions + removed --runInBand flag. This should work much more reliably now ✨ Would you mind giving it a spin now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants