Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Jul 18, 2024
2 parents c6c4404 + abdf77b commit a5b6aba
Show file tree
Hide file tree
Showing 43 changed files with 1,163 additions and 693 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
node-version: [16.x, 18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
if: github.event.inputs.git-ref == ''
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
env:
CI: true
- name: Send codecov.io stats
if: matrix.node-version == '14.x'
if: matrix.node-version == '16.x'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -63,10 +63,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
- name: Install node_modules
run: yarn install
- name: Build
Expand Down
102 changes: 102 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,105 @@
## [10.0.0-beta.5](https://github.com/typegoose/mongodb-memory-server/compare/v10.0.0-beta.4...v10.0.0-beta.5) (2024-07-18)


### ⚠ BREAKING CHANGES

* **resolveConfig:** Default binary version is now "7.0.11"

### Features

* **resolveConfig:** update default binary version to 7.x ([9d569ac](https://github.com/typegoose/mongodb-memory-server/commit/9d569ac63e7f6bd729e0d98254226f4ed18acb0a))

## [10.0.0-beta.4](https://github.com/typegoose/mongodb-memory-server/compare/v10.0.0-beta.3...v10.0.0-beta.4) (2024-07-18)


### Features

* **index:** also top-level export "DryMongoBinary" and all errors ([d11abaa](https://github.com/typegoose/mongodb-memory-server/commit/d11abaaa9e7207756bd6d599b2455e7d5761f638))


### Dependencies

* **semver:** upgrade to version 7.6.3 ([100e571](https://github.com/typegoose/mongodb-memory-server/commit/100e57100c1c334c29a38ab8efaed0f7942e3235))


### Dev-Dependencies

* **eslint-plugin-prettier:** upgrade to version 5.2.1 ([15990b9](https://github.com/typegoose/mongodb-memory-server/commit/15990b97549a6a8632bab303d4a10204d91d90fe))

## [10.0.0-beta.3](https://github.com/typegoose/mongodb-memory-server/compare/v10.0.0-beta.2...v10.0.0-beta.3) (2024-07-15)


### Features

* **MongoMemoryServer:** allow setting if port generation is enabeld or not ([6c4daed](https://github.com/typegoose/mongodb-memory-server/commit/6c4daedf82ab86920037c5bb1dd2a15ba4031bbe)), closes [#816](https://github.com/typegoose/mongodb-memory-server/issues/816)


### Style

* **MongoMemoryReplSet:** fix lint ([bd8941b](https://github.com/typegoose/mongodb-memory-server/commit/bd8941b331eec9f4317ef8456142db69917528a3))


### Dependencies

* **https-proxy-agent:** upgrade to version 7.0.5 ([4d5be4d](https://github.com/typegoose/mongodb-memory-server/commit/4d5be4d5aa8330ab73dff8d0c1f5d0090b20e39b))


### Dev-Dependencies

* **prettier:** upgrade to version 3.3.3 ([5aba25a](https://github.com/typegoose/mongodb-memory-server/commit/5aba25a865f08184b1db1f433c35f35242d91b55))
* **rimraf:** upgrade to version 5.0.9 ([a6d706a](https://github.com/typegoose/mongodb-memory-server/commit/a6d706a75ab9560beb8c8053ddb7fabf42c453ca))
* **ts-jest:** upgrade to version 29.2.2 ([839e432](https://github.com/typegoose/mongodb-memory-server/commit/839e432c19d878cc4260114604274a439d0be626))

## [10.0.0-beta.2](https://github.com/typegoose/mongodb-memory-server/compare/v10.0.0-beta.1...v10.0.0-beta.2) (2024-07-13)


### Fixes

* **MongoBinaryDownloadUrl:** add mapping for Linux Mint 22 ([2ffc024](https://github.com/typegoose/mongodb-memory-server/commit/2ffc024ab6608d2f2d7da230f5ddf7dc4bbf4065))
* trigger release ([8c48020](https://github.com/typegoose/mongodb-memory-server/commit/8c48020816fe19fbcc4f886fcfb96302eaff8714))

## [10.0.0-beta.1](https://github.com/nodkz/mongodb-memory-server/compare/v9.4.0...v10.0.0-beta.1) (2024-06-24)


### ⚠ BREAKING CHANGES

* **resolveConfig:** Default binary version is now "7.0.9"
* **tsconfig:** potentially breaking change upgrading "target" to "es2021" in tsconfig
* Lowest supported NodeJS version is now 16.20.1

* **tsconfig:** update "target" to "es2021" ([abde8ca](https://github.com/nodkz/mongodb-memory-server/commit/abde8ca2ff2ebc077666d496520b3ce0f684ef99))


### Features

* add support for "Explicit Resource Management" ([ab7a73c](https://github.com/nodkz/mongodb-memory-server/commit/ab7a73c14fa80e51ec407d08b120b4ae6ee77ece)), closes [#794](https://github.com/nodkz/mongodb-memory-server/issues/794)
* **getport:** use net0listen by default ([887f1a1](https://github.com/nodkz/mongodb-memory-server/commit/887f1a1e932a8993ef3fd69cf1f65b700c89a77b)), closes [#827](https://github.com/nodkz/mongodb-memory-server/issues/827)
* **resolveConfig:** update default binary version to 7.x ([2436d63](https://github.com/nodkz/mongodb-memory-server/commit/2436d6300bd863efa3300103a3223d3849d0bda3))
* set lowest supported nodejs version to 16.20.1 ([30b302e](https://github.com/nodkz/mongodb-memory-server/commit/30b302e5518c3df92c4b229035b2b229639dfb3c)), closes [#805](https://github.com/nodkz/mongodb-memory-server/issues/805)


### Fixes

* **MongoBinaryDownloadUrl:** change default elementary version to 7 ([ecc4ffe](https://github.com/nodkz/mongodb-memory-server/commit/ecc4ffe2bbf47f3a2cd196d2ffa9a0e22aa4c94d))
* **MongoBinaryDownloadUrl:** change default mint version to 21 ([df97ea8](https://github.com/nodkz/mongodb-memory-server/commit/df97ea8f9edfb97c24a53f9bc6638697df70d85e))
* remove deprecated boolean cleanup argument (stop / cleanup) ([eef706f](https://github.com/nodkz/mongodb-memory-server/commit/eef706f7fef6ffe5caa0f0f8b3b99b168d8d7d2a))


### Dependencies

* **@types/node:** upgrade to version 16.11.7 ([c8a008a](https://github.com/nodkz/mongodb-memory-server/commit/c8a008aacff628ac0e8e7c77683987659411c8a1))
* **async-mutex:** upgrade to version 0.5.0 ([c9f45c9](https://github.com/nodkz/mongodb-memory-server/commit/c9f45c9f032918cbdc73c0953ecc95936c246bac))
* **mongodb:** upgrade to version 6.7.0 ([57e575c](https://github.com/nodkz/mongodb-memory-server/commit/57e575ce49344c79f2ae337da6aa43ada6738746)), closes [#804](https://github.com/nodkz/mongodb-memory-server/issues/804)
* **typescript:** upgrade to version 5.3.3 ([329d79e](https://github.com/nodkz/mongodb-memory-server/commit/329d79e484bf2f7da9e3d0ccf991bdd2cb4282a8))


### Dev-Dependencies

* **@typescript-eslint/*:** upgrade to version 6.21.0 ([b4055a7](https://github.com/nodkz/mongodb-memory-server/commit/b4055a715ee369f675a15059fb88cef38c1aec39))
* **lint-staged:** upgrade to version 14.0.1 ([0f54d29](https://github.com/nodkz/mongodb-memory-server/commit/0f54d29fe8ab51a806bb103609a7e34346c2b220))
* **prettier:** upgrade to version 3.3.0 ([fe1d62d](https://github.com/nodkz/mongodb-memory-server/commit/fe1d62d4fff1849e3fd76d0db745337e6fb693d7))
* **typedoc:** upgrade to version 0.25.13 ([0775c60](https://github.com/nodkz/mongodb-memory-server/commit/0775c60f14ec3026849ed70d24535c013b1d3aa7))

## [9.4.1](https://github.com/typegoose/mongodb-memory-server/compare/v9.4.0...v9.4.1) (2024-07-13)


Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Choose any package, because they are the same. They differ only in the default c

### Requirements

- NodeJS: 14.20.1+
- Typescript: 5.0+ (if used)
- NodeJS: 16.20.1+
- Typescript: 5.3+ (if used)

And one of those (on Linux):

Expand All @@ -86,7 +86,7 @@ On Linux, you will also need `libcurl4` (or `libcurl3` on some older distro vers

### Configuring which mongod binary to use

The default behavior is that version `6.0.14` for your OS will be downloaded. By setting [Environment variables](https://typegoose.github.io/mongodb-memory-server/docs/api/config-options) you are able to specify which version and binary will be downloaded:
The default behavior is that version `7.0.11` for your OS will be downloaded. By setting [Environment variables](https://typegoose.github.io/mongodb-memory-server/docs/api/config-options) you are able to specify which version and binary will be downloaded:

```sh
export MONGOMS_DOWNLOAD_URL=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz
Expand Down Expand Up @@ -128,7 +128,7 @@ const mongod = new MongoMemoryServer({
auth?: boolean, // add "--auth" argument, dont use this directly use top-level "auth"
},
binary?: {
version?: string, // by default '6.0.14'
version?: string, // by default '7.0.11'
downloadDir?: string, // see the documentation on what is chosen by default https://typegoose.github.io/mongodb-memory-server/docs/api/config-options#download_dir
platform?: string, // by default os.platform()
arch?: string, // by default os.arch()
Expand Down
16 changes: 1 addition & 15 deletions docs/api/config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Example: `ubuntu-18.04`

Option `VERSION` is used to set what mongodb version should be downloaded

Default: `6.0.14` (see [Mongodb Server Versions](../guides/mongodb-server-versions.md) for a complete list and policy)
Default: `7.0.11` (see [Mongodb Server Versions](../guides/mongodb-server-versions.md) for a complete list and policy)

This Option does not have a effect when [`ARCHIVE_NAME`](#archive_name) or [`DOWNLOAD_URL`](#download_url) is defined.

Expand Down Expand Up @@ -269,20 +269,6 @@ Also see [ARCHIVE_NAME](#archive_name).
Keep in mind that downloaded binaries will never be automatically deleted.
:::

### EXP_NET0LISTEN

| Environment Variable | PackageJson |
| :------------------: | :---------: |
| `MONGOMS_EXP_NET0LISTEN` | `expNet0Listen` |

Option `EXP_NET0LISTEN` is used to use the experimental (non-predictable) port generation of `net.listen`.

This option will use a random open port, which will lessen the "port is already in use" errors, but will not eliminate them.

This is a experimental option, it maybe removed, renamed or have changed behavior in the future.

Default: `false`

## How to use them in the package.json

To use the config options in the `package.json`, they need to be camelCased (and without `_`), and need to be in the property `config.mongodbMemoryServer`
Expand Down
20 changes: 20 additions & 0 deletions docs/api/interfaces/mongo-dispose-opts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: mongo-memory-dispose-opts
title: 'DisposeOptions'
---

API Documentation of `DisposeOptions`-Interface

## Values for `DisposeOptions`

### enabled

Typings: `enabled?: boolean`

Set whether to stop the manager on `[Symbol.asyncDispose]` calls.

### cleanup

Typings: `cleanup?: Cleanup`

Set custom cleanup options to be used for disposal, see [`cleanup` function](../classes/mongo-memory-server.md#cleanup) (the same options apply for the replset).
12 changes: 11 additions & 1 deletion docs/api/interfaces/mongo-memory-server-opts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ API Documentation of `MongoMemoryServerOpts`-Interface

### instance

Typings: `instance?: MemoryServerInstanceOpts`
Typings: `instance?: MemoryServerInstanceOpts & ExtraOptions`

Set custom options based on [`MongoMemoryInstanceOpts`](./mongo-memory-instance-opts.md), but ignores some properties:

- `auth` is ignored because it is set via [auth](#auth) property.

Extra options specific to [`MongoMemoryServer` class](../classes/mongo-memory-server.md):

- `portGeneration`: enable / disable port generation, enabled by default.

### binary

Typings: `binary?: MongoBinaryOpts`
Expand All @@ -32,3 +36,9 @@ Set custom spawn options for spawning processes, uses [`SpawnOptions`](https://n
Typings: `auth?: AutomaticAuth`

Set custom Authentication options for the instance, uses [`AutomaticAuth`](./mongo-memory-server-automaticauth.md).

### dispose

Typings: `dispose?: DisposeOptions`

Set custom behavior for when `[Symbol.asyncDispose]` is called, uses [`DisposeOptions`](./mongo-dispose-opts.md).
6 changes: 6 additions & 0 deletions docs/api/interfaces/replset-opts.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ Set how many ReplSet members to spawn, this number will be deducted from length
:::tip
It is recommended to set this number to a **odd** number, and try to never have it be **even**, see [MongoDB Deploy an Odd Number of Members](https://www.mongodb.com/docs/v5.2/core/replica-set-architectures/#deploy-an-odd-number-of-members).
:::

### dispose

Typings: `dispose?: DisposeOptions`

Set custom behavior for when `[Symbol.asyncDispose]` is called, uses [`DisposeOptions`](./mongo-dispose-opts.md).
11 changes: 11 additions & 0 deletions docs/guides/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ Since `8.4.0` objects can also be used instead of just booleans for parameter in

For Example `.stop({ doCleanup: false })` can be used instead of `.stop(false)`.
:::

### Does this package support Explicit Resource Management?

Yes, `[Symbol.asyncDispose]` is implemented for all manager classes, behavior can be configured via `dispose` options:

- [`MongoMemoryServerOpts.dispose`](../api/interfaces/mongo-memory-server-opts.md#dispose)
- [`ReplSetOpts.dispose`](../api/interfaces/replset-opts.md#dispose)

:::note
Note that when using `await using server =` that `[Symbol.asyncDispose]` is called at the end of the scope even if the value is reassigned to something out of the current scope.
:::
15 changes: 7 additions & 8 deletions docs/guides/integration-examples/test-runners.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export = async function globalSetup() {
process.env.MONGO_URI = `mongodb://${config.IP}:${config.Port}`;
}

// The following is to make sure the database is clean before an test starts
// The following is to make sure the database is clean before a test suite starts
const conn = await mongoose.connect(`${process.env.MONGO_URI}/${config.Database}`);
await conn.connection.db.dropDatabase();
await mongoose.disconnect();
Expand Down Expand Up @@ -89,7 +89,7 @@ beforeAll(async () => {
});

afterAll(async () => {
// put your client disconnection code here, example with mongodb:
// put your client disconnection code here, example with mongoose:
await mongoose.disconnect();
});
```
Expand All @@ -109,17 +109,16 @@ Keep in mind that jest's global-setup and global-teardown do **not** share a env

Start Mocha with `--timeout 60000` cause first download of MongoDB binaries may take a time.

```js
```ts
import mongoose from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';

let mongoServer;
const opts = { useMongoClient: true }; // remove this option if you use mongoose 5 and above

before(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
await mongoose.connect(mongoUri, opts);
await mongoose.connect(mongoUri);
});

after(async () => {
Expand All @@ -130,16 +129,16 @@ after(async () => {
describe('...', () => {
it('...', async () => {
const User = mongoose.model('User', new mongoose.Schema({ name: String }));
const cnt = await User.count();
const cnt = await User.countDocuments();
expect(cnt).to.equal(0);
});
});
```

## AVA test runner

For AVA written [detailed tutorial](https://github.com/zellwk/ava/blob/8b7ccba1d80258b272ae7cae6ba4967cd1c13030/docs/recipes/endpoint-testing-with-mongoose.md) how to test mongoose models by @zellwk.
For AVA there is a [detailed written tutorial](https://github.com/zellwk/ava/blob/8b7ccba1d80258b272ae7cae6ba4967cd1c13030/docs/recipes/endpoint-testing-with-mongoose.md) on how to test mongoose models with mongodb-memory-server by [@zellwk](https://github.com/zellwk).

:::note
Note that this mentioned tutorial is pre 7.x
Note that this tutorial is pre mongodb-memory-server 7.x.
:::
48 changes: 48 additions & 0 deletions docs/guides/migration/migrate10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
id: migrate10
title: 'Migrate to version 10.0.0'
---

Here are the Important changes made for 10.0.0

:::caution Important, Read this first
This Guide is written for migration from version `9.4.1` to `10.0.0`, for versions `>10.0.0 <11.0.0`, please consult the [CHANGELOG](https://github.com/typegoose/mongodb-memory-server/blob/master/CHANGELOG.md)
:::

## Breaking Changes

### Minimal NodeJS version is now `16`

With 10.0.0 the minimal nodejs required is `16.20.1`.

### Mongodb Driver Version upgraded to 6.x

The used MongoDB Driver version is now `6.7.0`.

### Default binary version is now 7.x

The default binary version has been upgraded from `6.0.x` to `7.0.x`. For more specifics see [mongodb-server-versions](../mongodb-server-versions.md).

:::note
In mongodb `7.0.0` storage engine `ephemeralForTest` has been removed, mongodb-memory-server will automatically translate any occurrence to `wiredTiger` with a warning.

It is recommended to run the tests against a tmpfs or equivalent (default `/tmp` on linux / macos).
:::

## Non-Breaking changes / Additions

### Compiler target is now `es2021`

The tsconfig `target` option has been updated to `es2021`, which will result in less polyfills.
This should be a non-breaking change.

### Getport now uses `net0listen` by default

This means a port is now generated by the engine (like nodejs) itself, previously known as `EXP_NET0LISTEN`.
This should reduce amount of `Max port tries exceeded` errors.

### Allow setting port generation in MongoMemoryServer

Starting with 10.0 there is a new option to set whether port generation is enabled or not on `MongoMemoryServer` called `portGeneration`. (default: `true`)

(Note that the `forceSamePort` parameter in `.start` will overwrite this option)
1 change: 1 addition & 0 deletions docs/guides/mongodb-server-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Starting with MongoDB version 5.0, the default versions for `mongodb-memory-serv

| `mongodb-memory-server-core` Version | Default MongoDB Version |
| :----------------------------------: | :---------------------: |
| 10.0.x - 10.0.x | 7.0.11 |
| 9.2.x - 9.2.x | 6.0.14 |
| 9.0.x - 9.1.x | 6.0.9 |
| 8.14.x - 8.16.x | 5.0.19 |
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/quick-start-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ If Top-Level async-await is not available for your case, the code can in most ca

## Requirements

- NodeJS: 14.20.1+
- Typescript: 5.0+ (if used)
- NodeJS: 16.20.1+
- Typescript: 5.3+ (if used)

When on Linux, one of the following are required:

Expand Down
Loading

0 comments on commit a5b6aba

Please sign in to comment.