Skip to content

Commit d8d6749

Browse files
committed
fix(MongoBinary): use ".stdout.toString" for command output parsing
fixes #487
1 parent 0d990d3 commit d8d6749

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/mongodb-memory-server-core/src/util/MongoBinary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class MongoBinary {
9292
if (!isNullOrUndefined(binaryPath)) {
9393
log(`getPath: Spawning binaryPath "${binaryPath}" to get version`);
9494
const spawnOutput = spawnSync(binaryPath, ['--version'])
95-
.toString()
95+
.stdout.toString()
9696
// this regex is to match the first line of the "mongod --version" output "db version v4.0.20"
9797
.match(/^\s*db\s+version\s+v?(\d+\.\d+\.\d+)\s*$/im);
9898

packages/mongodb-memory-server-core/src/util/__tests__/MongoBinary.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ describe('MongoBinary', () => {
116116
// DO NOT INDENT THE TEXT
117117
jest.spyOn(childProcess, 'spawnSync').mockReturnValue(
118118
// @ts-expect-error Because "Buffer" is missing values from type, but they are not used in code, so its fine
119-
Buffer.from(`db version v4.0.20
119+
{
120+
stdout: Buffer.from(`db version v4.0.20
120121
git version: e2416422da84a0b63cde2397d60b521758b56d1b
121122
OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020
122123
allocator: tcmalloc
123124
modules: none
124125
build environment:
125126
distmod: ubuntu1804
126127
distarch: x86_64
127-
target_arch: x86_64`)
128+
target_arch: x86_64`),
129+
}
128130
);
129131
process.env[envName(ResolveConfigVariables.VERSION)] = '4.0.20'; // set it explicitly to that version to test matching versions
130132
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = sysBinaryPath;
@@ -141,15 +143,17 @@ build environment:
141143
// DO NOT INDENT THE TEXT
142144
jest.spyOn(childProcess, 'spawnSync').mockReturnValue(
143145
// @ts-expect-error Because "Buffer" is missing values from type, but they are not used in code, so its fine
144-
Buffer.from(`db version v4.0.20
146+
{
147+
stdout: Buffer.from(`db version v4.0.20
145148
git version: e2416422da84a0b63cde2397d60b521758b56d1b
146149
OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020
147150
allocator: tcmalloc
148151
modules: none
149152
build environment:
150153
distmod: ubuntu1804
151154
distarch: x86_64
152-
target_arch: x86_64`)
155+
target_arch: x86_64`),
156+
}
153157
);
154158
process.env[envName(ResolveConfigVariables.VERSION)] = '4.4.0'; // set it explicitly to that version to test non-matching versions
155159
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = sysBinaryPath;

0 commit comments

Comments
 (0)