Skip to content

Commit e89df5a

Browse files
committed
dependencies(typescript): upgrade to version 4.4.2
1 parent 01e662a commit e89df5a

19 files changed

+142
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"prettier": "2.3.2",
3232
"semantic-release": "17.4.7",
3333
"ts-jest": "27.0.5",
34-
"typescript": "4.3.5"
34+
"typescript": "4.4.2"
3535
},
3636
"workspaces": {
3737
"packages": [

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import MongoMemoryServer from '../MongoMemoryServer';
88
import * as utils from '../util/utils';
99
import { MongoMemoryInstanceOpts } from '../util/MongoInstance';
1010
import { StateError, WaitForPrimaryTimeoutError } from '../util/errors';
11+
import { assertIsError } from './testUtils/test_utils';
1112

1213
jest.setTimeout(100000); // 10s
1314

@@ -77,7 +78,8 @@ describe('single server replset', () => {
7778
new MongoMemoryReplSet({ replSet: { count: 0 } });
7879
fail('Expected "new MongoMemoryReplSet" to throw an error');
7980
} catch (err) {
80-
expect(err.message).toEqual('ReplSet Count needs to be 1 or higher!');
81+
assertIsError(err);
82+
expect(err.message).toMatchSnapshot();
8183
}
8284
});
8385

@@ -93,6 +95,7 @@ describe('single server replset', () => {
9395
} catch (err) {
9496
clearTimeout(timeout);
9597
expect(err).toBeInstanceOf(StateError);
98+
assertIsError(err);
9699
expect(err.message).toMatchSnapshot();
97100
}
98101
});
@@ -118,6 +121,7 @@ describe('single server replset', () => {
118121
} catch (err) {
119122
clearTimeout(timeout);
120123
expect(err).toBeInstanceOf(StateError);
124+
assertIsError(err);
121125
expect(err.message).toMatchSnapshot();
122126
}
123127
});
@@ -138,6 +142,7 @@ describe('single server replset', () => {
138142
} catch (err) {
139143
clearTimeout(timeout);
140144
expect(err).toBeInstanceOf(StateError);
145+
assertIsError(err);
141146
expect(err.message).toMatchSnapshot();
142147
}
143148
});
@@ -191,6 +196,7 @@ describe('single server replset', () => {
191196
} catch (err) {
192197
clearTimeout(timeout);
193198
expect(err).toBeInstanceOf(StateError);
199+
assertIsError(err);
194200
expect(err.message).toMatchSnapshot();
195201
}
196202
});
@@ -210,7 +216,8 @@ describe('single server replset', () => {
210216
fail('Expected "_initReplSet" to throw');
211217
} catch (err) {
212218
clearTimeout(timeout);
213-
expect(err.message).toEqual('One or more servers are required.');
219+
assertIsError(err);
220+
expect(err.message).toMatchSnapshot();
214221
}
215222
});
216223

@@ -382,6 +389,7 @@ describe('MongoMemoryReplSet', () => {
382389
fail('Expected assignment of "replSet.binaryOpts" to fail');
383390
} catch (err) {
384391
expect(err).toBeInstanceOf(StateError);
392+
assertIsError(err);
385393
expect(err.message).toMatchSnapshot();
386394
}
387395
});
@@ -392,6 +400,7 @@ describe('MongoMemoryReplSet', () => {
392400
fail('Expected assignment of "replSet.instanceOpts" to fail');
393401
} catch (err) {
394402
expect(err).toBeInstanceOf(StateError);
403+
assertIsError(err);
395404
expect(err.message).toMatchSnapshot();
396405
}
397406
});
@@ -402,6 +411,7 @@ describe('MongoMemoryReplSet', () => {
402411
fail('Expected assignment of "replSet.instanceOpts" to fail');
403412
} catch (err) {
404413
expect(err).toBeInstanceOf(StateError);
414+
assertIsError(err);
405415
expect(err.message).toMatchSnapshot();
406416
}
407417
});
@@ -412,7 +422,8 @@ describe('MongoMemoryReplSet', () => {
412422
replSet.replSetOpts = { count: 0 };
413423
fail('Expected assignment of "replSet.instanceOpts" to fail');
414424
} catch (err) {
415-
expect(err.message).toEqual('ReplSet Count needs to be 1 or higher!');
425+
assertIsError(err);
426+
expect(err.message).toMatchSnapshot();
416427
}
417428
});
418429
});

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import MongoInstance from '../util/MongoInstance';
1010
import * as utils from '../util/utils';
1111
import * as semver from 'semver';
1212
import { EnsureInstanceError, StateError } from '../util/errors';
13+
import { assertIsError } from './testUtils/test_utils';
1314

1415
tmp.setGracefulCleanup();
1516
jest.setTimeout(100000); // 10s
@@ -253,8 +254,9 @@ describe('MongoMemoryServer', () => {
253254
usersInfo: 1,
254255
});
255256
fail('Expected "db.command" to fail');
256-
} catch (err) {
257-
expect(err.codeName).toEqual('Unauthorized');
257+
} catch (err: any) {
258+
// TODO: re-investigate if "codeName" is actually the right property
259+
expect(err.codeName).toMatchSnapshot();
258260
}
259261
expect(MongoInstance.prototype.start).toHaveBeenCalledTimes(1);
260262
expect(MongoMemoryServer.prototype.createAuth).not.toHaveBeenCalled();
@@ -274,6 +276,7 @@ describe('MongoMemoryServer', () => {
274276
fail('Expected "start" to fail');
275277
} catch (err) {
276278
expect(err).toBeInstanceOf(StateError);
279+
assertIsError(err);
277280
expect(err.message).toMatchSnapshot();
278281
}
279282
}
@@ -287,6 +290,7 @@ describe('MongoMemoryServer', () => {
287290
fail('Expected "start" to fail');
288291
} catch (err) {
289292
expect(err).toBeInstanceOf(StateError);
293+
assertIsError(err);
290294
expect(err.message).toMatchSnapshot();
291295
}
292296
}
@@ -355,6 +359,7 @@ describe('MongoMemoryServer', () => {
355359
fail('Expected "ensureInstance" to throw');
356360
} catch (err) {
357361
expect(err).toBeInstanceOf(StateError);
362+
assertIsError(err);
358363
expect(err.message).toMatchSnapshot();
359364
}
360365
});
@@ -540,6 +545,7 @@ describe('MongoMemoryServer', () => {
540545
fail('Expected "cleanup" to fail');
541546
} catch (err) {
542547
expect(err).toBeInstanceOf(StateError);
548+
assertIsError(err);
543549
expect(err.message).toMatchSnapshot();
544550
}
545551
});
@@ -575,7 +581,8 @@ describe('MongoMemoryServer', () => {
575581
await mongoServer.createAuth();
576582
fail('Expected "createAuth" to fail');
577583
} catch (err) {
578-
expect(err.message).toEqual('"createAuth" got called, but "this.auth" is undefined!');
584+
assertIsError(err);
585+
expect(err.message).toMatchSnapshot();
579586
}
580587
});
581588

packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryReplSet.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
exports[`MongoMemoryReplSet "_waitForPrimary" should throw an error if timeout is reached 1`] = `"{\\"timeout\\":1}"`;
44

5+
exports[`MongoMemoryReplSet getters & setters setter of "replSetOpts" should throw an error if count is 1 or above 1`] = `"ReplSet Count needs to be 1 or higher!"`;
6+
57
exports[`MongoMemoryReplSet getters & setters state errors setter of "binaryOpts" should throw an error if state is not "stopped" 1`] = `
68
"Incorrect State for operation: \\"init\\", allowed States: \\"[stopped]\\"
79
This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:
@@ -26,12 +28,16 @@ This may be because of using a v6.x way of calling functions, look at the follow
2628
https://nodkz.github.io/mongodb-memory-server/docs/guides/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything"
2729
`;
2830

31+
exports[`single server replset "_initReplSet" should throw if server count is 0 or less 1`] = `"One or more servers are required."`;
32+
2933
exports[`single server replset "getUri" should throw an error if _state is not "running" or "init" 1`] = `
3034
"Incorrect State for operation: \\"stopped\\", allowed States: \\"[running,init]\\"
3135
This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:
3236
https://nodkz.github.io/mongodb-memory-server/docs/guides/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything"
3337
`;
3438

39+
exports[`single server replset "new" should throw an error if replSet count is 0 or less 1`] = `"ReplSet Count needs to be 1 or higher!"`;
40+
3541
exports[`single server replset "start" should throw an error if _state is not "stopped" 1`] = `
3642
"Incorrect State for operation: \\"running\\", allowed States: \\"[stopped]\\"
3743
This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:

packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryServer.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`MongoMemoryServer "createAuth" should throw an error if called without "this.auth" defined 1`] = `"\\"createAuth\\" got called, but \\"this.auth\\" is undefined!"`;
4+
35
exports[`MongoMemoryServer cleanup() should throw an error if state is not "stopped" 1`] = `
46
"Incorrect State for operation: \\"new\\", allowed States: \\"[stopped]\\"
57
This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:
@@ -28,6 +30,8 @@ This may be because of using a v6.x way of calling functions, look at the follow
2830
https://nodkz.github.io/mongodb-memory-server/docs/guides/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything"
2931
`;
3032

33+
exports[`MongoMemoryServer start() "createAuth" should not be called if "disabled" is true 1`] = `"Unauthorized"`;
34+
3135
exports[`MongoMemoryServer start() should throw an error if state is not "new" or "stopped" 1`] = `
3236
"Incorrect State for operation: \\"starting\\", allowed States: \\"[new,stopped]\\"
3337
This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { assertion } from '../../util/utils';
2+
3+
/**
4+
* This function is just here because "expect(err).toBeInstanceOf(Error)" does not use "asserts", and so stays "unknown" which makes typescript error
5+
* Use this function after any "toBeInstanceOf" calls!
6+
* @param value The Value to Assert to error
7+
*/
8+
export function assertIsError(value: unknown): asserts value is Error {
9+
assertion(value instanceof Error, new Error('Expected "value" to be instanceof Error!'));
10+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ export class DryMongoBinary {
156156

157157
return systemBinary; // returns if "access" is successful
158158
} catch (err) {
159-
log(`getSystemPath: can't find system binary at "${systemBinary}".\n${err.message}`);
159+
log(
160+
`getSystemPath: can't find system binary at "${systemBinary}".\n${
161+
err instanceof Error ? err.message : err
162+
}`
163+
);
160164
}
161165

162166
return undefined;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import resolveConfig, { envName, ResolveConfigVariables } from '../resolveConfig
66
import * as utils from '../utils';
77
import { DryMongoBinary } from '../DryMongoBinary';
88
import * as childProcess from 'child_process';
9+
import { assertIsError } from '../../__tests__/testUtils/test_utils';
910

1011
tmp.setGracefulCleanup();
1112

@@ -88,9 +89,8 @@ describe('MongoBinary', () => {
8889
await MongoBinary.getPath();
8990
fail('Expected "getPath" to fail');
9091
} catch (err) {
91-
expect(err.message).toEqual(
92-
'MongoBinary.getPath: could not find an valid binary path! (Got: "undefined", RUNTIME_DOWNLOAD: "false")'
93-
);
92+
assertIsError(err);
93+
expect(err.message).toMatchSnapshot();
9494
expect(DryMongoBinary.locateBinary).toBeCalledTimes(1);
9595
expect(MongoBinary.download).not.toHaveBeenCalled();
9696
}
@@ -209,9 +209,8 @@ build environment:
209209
await MongoBinary.getPath();
210210
fail('Expected "getPath" to fail');
211211
} catch (err) {
212-
expect(err.message).toEqual(
213-
'Option "SYSTEM_BINARY" was set, but binaryPath was empty! (system binary could not be found?) [This Error should normally not be thrown, please report this]'
214-
);
212+
assertIsError(err);
213+
expect(err.message).toMatchSnapshot();
215214
}
216215
});
217216
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { promises as fspromises } from 'fs';
22
import md5file from 'md5-file';
33
import * as mkdirp from 'mkdirp';
4+
import { assertIsError } from '../../__tests__/testUtils/test_utils';
45
import { DryMongoBinary } from '../DryMongoBinary';
56
import { Md5CheckFailedError } from '../errors';
67
import { MongoBinaryOpts } from '../MongoBinary';
@@ -273,6 +274,7 @@ describe('MongoBinaryDownload', () => {
273274
await du.startDownload();
274275
fail('Expected "startDownload" to fail');
275276
} catch (err) {
277+
assertIsError(err);
276278
expect(err.message).toEqual(customError.message);
277279
expect(console.error).toHaveBeenCalledTimes(1);
278280
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { assertIsError } from '../../__tests__/testUtils/test_utils';
12
import { UnknownPlatformError, UnknownArchitectureError } from '../errors';
23
import { LinuxOS } from '../getos';
34
import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';
@@ -573,6 +574,7 @@ describe('MongoBinaryDownloadUrl', () => {
573574
await du.getArchiveName();
574575
fail('Expected "getArchiveName" to throw');
575576
} catch (err) {
577+
assertIsError(err);
576578
expect(err).toBeInstanceOf(UnknownPlatformError);
577579
expect(err.message).toMatchSnapshot();
578580
}
@@ -588,6 +590,7 @@ describe('MongoBinaryDownloadUrl', () => {
588590
});
589591
fail('Expected "translatePlatform" to throw');
590592
} catch (err) {
593+
assertIsError(err);
591594
expect(err).toBeInstanceOf(UnknownPlatformError);
592595
expect(err.message).toMatchSnapshot();
593596
}
@@ -822,6 +825,7 @@ describe('MongoBinaryDownloadUrl', () => {
822825
MongoBinaryDownloadUrl.translateArch('ia32', 'darwin');
823826
fail('Expected "translateArch" to fail');
824827
} catch (err) {
828+
assertIsError(err);
825829
expect(err).toBeInstanceOf(UnknownArchitectureError);
826830
expect(err.message).toMatchSnapshot();
827831
}
@@ -832,6 +836,7 @@ describe('MongoBinaryDownloadUrl', () => {
832836
MongoBinaryDownloadUrl.translateArch('risc', 'linux');
833837
fail('Expected "translateArch" to fail');
834838
} catch (err) {
839+
assertIsError(err);
835840
expect(err).toBeInstanceOf(UnknownArchitectureError);
836841
expect(err.message).toMatchSnapshot();
837842
}

0 commit comments

Comments
 (0)