Code Monkey home page Code Monkey logo

Comments (20)

sibelius avatar sibelius commented on July 26, 2024 1

you should add this

import 'babel-polyfill' on top of your tests

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024 1

Please install new [email protected] and update your code in such way:

- var MongodbMemoryServer = require('mongodb-memory-server');
+ var MongodbMemoryServer = require('mongodb-memory-server').default;

When you remove babel, the require method loose default export. So without babel, you should do it explicitly require('mongodb-memory-server').default.

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

@BenjaminPrice did import 'babel-polyfill' help to you? If so, I add а note to Readme.md.

@sibelius thanks for help

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

@nodkz Unfortunately, it did not help. I ended up with a new problem where node just leaks memory until it crashes.

<--- Last few GCs --->

   75546 ms: Mark-sweep 650.4 (706.8) -> 650.2 (706.8) MB, 114.6 / 0 ms [allocation failure] [GC in old space requested].
   75659 ms: Mark-sweep 650.2 (706.8) -> 650.2 (706.8) MB, 113.1 / 0 ms [allocation failure] [GC in old space requested].
   75808 ms: Mark-sweep 650.2 (706.8) -> 650.0 (699.8) MB, 148.1 / 0 ms [last resort gc].
   75921 ms: Mark-sweep 650.0 (699.8) -> 649.8 (699.8) MB, 113.4 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x10eb16b4629 <JS Object>
    1: from [/Users/me/Projects/myProject/node_modules/babel-polyfill/node_modules/core-js/modules/_typed-array.js:~134] [pc=0xb25be0b6352] (this=0x14b7088cfc89 <JS Function Uint8Array (SharedFunctionInfo 0x1d5256d388d1)>,source=0x10eb16da561 <an Uint8Array with map 0x15af9304d09>)
    2: /* anonymous */(aka /* anonymous */) [/Users/me/Projects/myProject/node_modules/babel-po...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
[1]    37476 abort      jest

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

Too strange. Can you provide public repo where reproduced last or first error?

from mongodb-memory-server.

sibelius avatar sibelius commented on July 26, 2024

there are some leaks on babel-polyfill, that's why jest stopped using as a default

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

@sibelius do you know how make async/await (regeneratorRuntime) working without babel-polyfill?

Or it will be better to remove it at all? But in this case, I drop support for Node 6 and below.

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

It'll take me a while to get something together, in a public repo, to duplicate it. Likely can get something together over the weekend. But, if you can come up with a solution that avoids the need for babel-polyfill before then, even better :)

from mongodb-memory-server.

sibelius avatar sibelius commented on July 26, 2024

https://babeljs.io/docs/plugins/transform-regenerator/

image

maybe we can avoid the babel-polyfill

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

I've tried adding just regenerator-runtime and I get a bit further but it appears that the mongo server never starts, and thus I am unable to resolve getConnectionString and my tests time out.

We're 1 step closer.

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

Try to set 60 second timeout or maybe more. At first run it downloads 70 mb mongodb binaries and may be not enough time for download. After success first run it will use aleeady downloaded local binaries.

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

I had timeout at 120 seconds. On a previous run it had completed the download (it broke after that).

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

Try to start server with debug:true option and provide here console output.

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

I redacted my hostname and test file name but otherwise here is the log:

  Mongo[62610] createDownloadDir(): /Users/benprice/.mongodb-binaries/mongodb-download +7ms
  Mongo[62610] getDownloadURI (url obj returned with href): https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] getTempDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz.downloading +0ms
  Mongo[62610] getHttpOptions { protocol: 'https:',
  hostname: 'fastdl.mongodb.org',
  path: '/osx/mongodb-osx-x86_64-3.4.4.tgz' } +0ms
  Mongo[62610] createDownloadDir(): true +11ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +0ms
  Mongo[62610] sending file from cache /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +0ms
  Mongo[62610] @getMD5HashFileLocation resolving md5HashLocation: /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz.md5 +0ms
  Mongo[62610] @getMD5Hash resolving offlineSignature 88c0cb3e0b912db01ed66847f1a4e674 +1ms
  Mongo[62610] isDownloadPresent() md5 match: true +260ms
  Mongo[62610] download(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] @getMD5HashFileLocation resolving md5HashLocation: /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz.md5 +0ms
  Mongo[62610] @getMD5Hash resolving offlineSignature 88c0cb3e0b912db01ed66847f1a4e674 +1ms
  Mongo[62610] getExtractLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/88c0cb3e0b912db01ed66847f1a4e674 +0ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +1ms
  Mongo[62610] @getMD5HashFileLocation resolving md5HashLocation: /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz.md5 +0ms
  Mongo[62610] @getMD5Hash resolving offlineSignature 88c0cb3e0b912db01ed66847f1a4e674 +0ms
  Mongo[62610] getDownloadLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz +0ms
  Mongo[62610] @getMD5HashFileLocation resolving md5HashLocation: /Users/benprice/.mongodb-binaries/mongodb-download/mongodb-osx-x86_64-3.4.4.tgz.md5 +0ms
  Mongo[62610] @getMD5Hash resolving offlineSignature 88c0cb3e0b912db01ed66847f1a4e674 +1ms
  Mongo[62610] getExtractLocation(): /Users/benprice/.mongodb-binaries/mongodb-download/88c0cb3e0b912db01ed66847f1a4e674 +0ms
  Mongo[62610] sending file from cache /Users/benprice/.mongodb-binaries/mongodb-download/88c0cb3e0b912db01ed66847f1a4e674 +0ms
  Mongo[62610] isExtractPresent(): true +20ms
  Mongo[62610] MongoBinary: Mongod binary path: /Users/benprice/.mongodb-binaries/mongodb-download/88c0cb3e0b912db01ed66847f1a4e674/mongodb-osx-x86_64-3.4.4/bin +17ms
  Mongo[62610] MongoBinary: Download lock removed +23ms
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] MongoDB starting : pid=60116 port=62610 dbpath=/var/folders/4n/vzm4q2115zngshphwll8tj400000gn/T/mongo-mem-60106BGc4c0hjEU4g 64-bit host=redacted.local
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] db version v3.4.4
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] allocator: system
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] modules: none
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] build environment:
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten]     distarch: x86_64
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten]     target_arch: x86_64
  Mongo[62610] 2017-08-03T15:02:00.756-0400 I CONTROL  [initandlisten] options: { net: { port: 62610 }, security: { authorization: "disabled" }, storage: { dbPath: "/var/folders/4n/vzm4q2115zngshphwll8tj400000gn/T/mongo-mem-60106BGc4c0hjEU4g", engine: "ephemeralForTest" } }
  Mongo[62610]  +28ms
  Mongo[62610] 2017-08-03T15:02:00.768-0400 I CONTROL  [initandlisten]
  Mongo[62610] 2017-08-03T15:02:00.768-0400 I CONTROL  [initandlisten] ** NOTE: The ephemeralForTest storage engine is for testing only.
  Mongo[62610] 2017-08-03T15:02:00.768-0400 I CONTROL  [initandlisten] **       Do not use in production.
  Mongo[62610] 2017-08-03T15:02:00.768-0400 I CONTROL  [initandlisten]
  Mongo[62610] 2017-08-03T15:02:00.769-0400 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/folders/4n/vzm4q2115zngshphwll8tj400000gn/T/mongo-mem-60106BGc4c0hjEU4g/diagnostic.data'
  Mongo[62610]  +13ms
  Mongo[62610] 2017-08-03T15:02:00.770-0400 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
  Mongo[62610] 2017-08-03T15:02:00.770-0400 I INDEX    [initandlisten] 	 building index using bulk method; build may temporarily use up to 500 megabytes of RAM
  Mongo[62610] 2017-08-03T15:02:00.770-0400 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
  Mongo[62610] 2017-08-03T15:02:00.770-0400 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
  Mongo[62610]  +0ms
  Mongo[62610] 2017-08-03T15:02:00.772-0400 I NETWORK  [thread1] waiting for connections on port 62610
  Mongo[62610]  +2ms
 RUNS  __tests__/utils/redacted.test.js

Test Suites: 6 passed, 6 of 7 total
Tests:       108 passed, 108 total
Snapshots:   5 passed, 5 total
Time:        30s, estimated 310s
████████████████████████████████████████  Mongo[62610] Shutdown MongoDB server on port 62610 with pid 60116 +3s
  Mongo[62610] Removing tmpDir /var/folders/4n/vzm4q2115zngshphwll8tj400000gn/T/mongo-mem-60106BGc4c0hjEU4g +4ms
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I CONTROL  [signalProcessingThread] got signal 15 (Terminated: 15), will terminate after current cmd ends
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I NETWORK  [signalProcessingThread] closing listening socket: 6
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I NETWORK  [signalProcessingThread] closing listening socket: 7
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-62610.sock
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
  Mongo[62610] 2017-08-03T15:02:03.898-0400 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
  Mongo[62610] 2017-08-03T15:02:03.899-0400 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
  Mongo[62610] 2017-08-03T15:02:03.899-0400 I CONTROL  [signalProcessingThread] now exiting
  Mongo[62610] 2017-08-03T15:02:03.899-0400 I CONTROL  [signalProcessingThread] shutting down with code:0
  Mongo[62610]  +77ms
  Mongo[62610] MongodbInstance: is failed: Mongod shutting down +2ms

It then repeats until the timeout hits.

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

Did you disconnect mongoose and stop mongod server in afterAll?

You may read how it works with Ava https://github.com/zellwk/ava/blob/8b7ccba1d80258b272ae7cae6ba4967cd1c13030/docs/recipes/endpoint-testing-with-mongoose.md It quite similar with Jest.

PS. I'm offline, see u tomorrow.

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

Yes, I was. I removed that and now the tests worked. I guess my tests were ending too early. I'll look at the tests next and see if I can readd the afterAll.

from mongodb-memory-server.

BenjaminPrice avatar BenjaminPrice commented on July 26, 2024

I was now able to get everything working by adding regenerator-runtime and fixing my tests up a bit. Please add a note for node 4.x that requiring regenerator-runtime is required and then I think we can close this issue.

from mongodb-memory-server.

nodkz avatar nodkz commented on July 26, 2024

@BenjaminPrice try new version [email protected] without adding regenerator-runtime in your tests. Now regenerator-runtime added implicitly in mongodb-memory-server. And should be no matter use you babel-polyfill, regenerator-runtime or not.

from mongodb-memory-server.

 avatar commented on July 26, 2024

Hi, I installed the 1.4.0 version and I still get the regenerator-runtime error. If I require it in my my mocha tests I get another error: MongodbMemoryServer is not a constructor.
Any idea why this happens? My code is below:

require("regenerator-runtime/runtime");
var MongodbMemoryServer = require('mongodb-memory-server');
let mongoServer;

before((done) => {
 mongoServer = new MongodbMemoryServer();
 mongoServer.getConnectionString().then((mongoUri) => {
   mongoose.connect(mongoUri, (err) => {
     done(err);
   });
 });
}); 

from mongodb-memory-server.

 avatar commented on July 26, 2024

Works great! Thanks a lot!

from mongodb-memory-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.