Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Dec 30, 2024
2 parents 0b65dd1 + b6b01c6 commit 9f28979
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 27 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [10.1.3-beta.1](https://github.com/typegoose/mongodb-memory-server/compare/v10.1.2...v10.1.3-beta.1) (2024-12-09)


### Fixes

* **DryMongoBinary::getPath:** always absoluteize System_Binary path ([c0975c3](https://github.com/typegoose/mongodb-memory-server/commit/c0975c32a273c452c7e4353096f48e1addec8460))
* **MongoBinary::getPath:** check that "stdout" actually exists ([613e670](https://github.com/typegoose/mongodb-memory-server/commit/613e6704db78c423afbafc3b88301f6f4ea34d8d)), closes [#742](https://github.com/typegoose/mongodb-memory-server/issues/742) [#issuecomment-2528284865](https://github.com/typegoose/mongodb-memory-server/issues/issuecomment-2528284865)
* **MongoBinary:** dont execute systembinary "--version" cmd if version check is false ([03c8412](https://github.com/typegoose/mongodb-memory-server/commit/03c84129a9a58c9d7325d127eea6fb18b18de461))

## [10.1.2](https://github.com/typegoose/mongodb-memory-server/compare/v10.1.1...v10.1.2) (2024-10-11)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ or
{
"config": {
"mongodbMemoryServer": {
"debug": "1", // also available case-insensitive values: "on" "yes" "true"
"debug": "1" // also available case-insensitive values: "on" "yes" "true"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/enable-debug-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MONGOMS_DEBUG=1 npm run test
{
"config": {
"mongodbMemoryServer": {
"debug": "1", // also available case-insensitive values: "on" "yes" "true"
"debug": "1" // also available case-insensitive values: "on" "yes" "true"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-core",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
"main": "lib/index",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class DryMongoBinary {
if (!!useOpts.systemBinary) {
log(`locateBinary: env "SYSTEM_BINARY" was provided with value: "${useOpts.systemBinary}"`);

const systemReturn = await this.getSystemPath(useOpts.systemBinary);
const systemReturn = await this.getSystemPath(path.resolve(useOpts.systemBinary));

if (isNullOrUndefined(systemReturn)) {
throw new BinaryNotFoundError(useOpts.systemBinary, ' (systemBinary)');
Expand Down
23 changes: 12 additions & 11 deletions packages/mongodb-memory-server-core/src/util/MongoBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,20 @@ export class MongoBinary {
if (!!options.systemBinary) {
// this case should actually never be false, because if "SYSTEM_BINARY" is set, "locateBinary" will run "getSystemPath" which tests the path for permissions
if (!isNullOrUndefined(binaryPath)) {
log(`getPath: Spawning binaryPath "${binaryPath}" to get version`);
const spawnOutput = spawnSync(binaryPath, ['--version'])
.stdout.toString()
// this regex is to match the first line of the "mongod --version" output "db version v4.0.25" OR "db version v4.2.19-11-ge2f2736"
.match(/^\s*db\s+version\s+v?(\d+\.\d+\.\d+)(-\d*)?(-[a-zA-Z0-9].*)?\s*$/im);

assertion(
!isNullOrUndefined(spawnOutput),
new Error('Couldnt find an version from system binary output!')
);

// dont warn if the versions dont match if "SYSTEM_BINARY_VERSION_CHECK" is false, but still test the binary if it is available to be executed
if (envToBool(resolveConfig(ResolveConfigVariables.SYSTEM_BINARY_VERSION_CHECK))) {
log(`getPath: Spawning binaryPath "${binaryPath}" to get version`);
const spawnOutput = spawnSync(binaryPath, ['--version'])
// NOTE: "stdout" seemingly can be "undefined", see https://github.com/typegoose/mongodb-memory-server/issues/742#issuecomment-2528284865
.stdout?.toString()
// this regex is to match the first line of the "mongod --version" output "db version v4.0.25" OR "db version v4.2.19-11-ge2f2736"
.match(/^\s*db\s+version\s+v?(\d+\.\d+\.\d+)(-\d*)?(-[a-zA-Z0-9].*)?\s*$/im);

assertion(
!isNullOrUndefined(spawnOutput),
new Error('Couldnt find an version from system binary output!')
);

log('getPath: Checking & Warning about version conflicts');
const binaryVersion = spawnOutput[1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ build environment:
expect(console.warn).toHaveBeenCalledTimes(1);
});

it('should return and check an SYSTEM_BINARY and dont warn version conflict if SYSTEM_BINARY_VERSION_CHECK is false', async () => {
it('should return and check a SYSTEM_BINARY and dont warn version conflict if SYSTEM_BINARY_VERSION_CHECK is false', async () => {
jest.spyOn(console, 'warn');
// Output taken from mongodb x64 for "ubuntu" version "4.0.25"
// DO NOT INDENT THE TEXT
Expand All @@ -218,7 +218,7 @@ build environment:
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY_VERSION_CHECK)] = 'false';

const output = await MongoBinary.getPath();
expect(childProcess.spawnSync).toHaveBeenCalledTimes(1);
expect(childProcess.spawnSync).toHaveBeenCalledTimes(0);
expect(MongoBinary.download).not.toHaveBeenCalled();
expect(console.warn).not.toHaveBeenCalled();
expect(output).toBe(sysBinaryPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ describe('DryBinary', () => {
expect(fspromises.access).toHaveBeenCalled();
});

it('should return SystemBinary with absolute path', async () => {
const mockBinary = 'bin/mongod';
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;
jest.spyOn(fspromises, 'access').mockResolvedValue(void 0);

const returnValue = await binary.DryMongoBinary.locateBinary({ version: '1.1.1' });
expect(returnValue).not.toEqual(mockBinary);
expect(returnValue).toEqual(path.resolve(mockBinary));
expect(binary.DryMongoBinary.binaryCache.size).toBe(0); // system binaries dont get added to the cache
expect(fspromises.access).toHaveBeenCalled();
});

it('should throw an error if SystemBinary was provided, but not found', async () => {
const mockBinary = '/usr/local/bin/mongod';
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.0",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"mongodb_version": "4.0.28",
"description": "MongoDB Server for testing (auto-download 4.0 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.1.2",
"mongodb-memory-server-core": "10.1.3-beta.1",
"tslib": "^2.7.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.2",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"mongodb_version": "4.2.24",
"description": "MongoDB Server for testing (auto-download 4.2 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.1.2",
"mongodb-memory-server-core": "10.1.3-beta.1",
"tslib": "^2.7.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global-4.4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global-4.4",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"mongodb_version": "4.4.28",
"description": "MongoDB Server for testing (auto-download 4.4 version to ~/.cache/mongodb-binaries).",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.1.2",
"mongodb-memory-server-core": "10.1.3-beta.1",
"tslib": "^2.7.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-global/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server-global",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"description": "MongoDB Server for testing (auto-download latest version to ~/.cache/mongodb-binaries).",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -24,7 +24,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.1.2",
"mongodb-memory-server-core": "10.1.3-beta.1",
"tslib": "^2.7.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-memory-server",
"version": "10.1.2",
"version": "10.1.3-beta.1",
"description": "MongoDB Server for testing (auto-download latest version). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -24,7 +24,7 @@
"mongomem"
],
"dependencies": {
"mongodb-memory-server-core": "10.1.2",
"mongodb-memory-server-core": "10.1.3-beta.1",
"tslib": "^2.7.0"
},
"scripts": {
Expand Down

0 comments on commit 9f28979

Please sign in to comment.