deno.land / x / mongoose@6.7.5 / test / mocha-fixtures.js

mocha-fixtures.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const mms = require('mongodb-memory-server');
/* * Default MMS mongodb version is used, unless MONGOMS_VERSION is set (which is set with the matrix in test.yml for CI) */
// a single-instance running for single-instance testslet mongoinstance;
// a replset-instance for running repl-set testslet mongorreplset;
// decide whether to start MMS instances or use the existing URI'sconst startMemoryInstance = !process.env.MONGOOSE_TEST_URI;const startMemoryReplset = !process.env.MONGOOSE_REPLSET_URI;
module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { let instanceuri; let replseturi;
process.env.RUNTIME_DOWNLOAD = '1'; // ensure MMS is able to download binaries in this context
// set some options when running in a CI if (process.env.CI) { // this option is also set in the github-ci tests.yml, but this is just to ensure it is in any CI process.env.MONGOMS_PREFER_GLOBAL_PATH = '1'; // set MMS to use "~/.cache/mongodb-binaries" even when the path does not yet exist }
if (startMemoryInstance) { mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'], storageEngine: 'wiredTiger' } }); instanceuri = mongoinstance.getUri(); } else { instanceuri = process.env.MONGOOSE_TEST_URI; }
if (startMemoryReplset) { mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: 3, args: ['--setParameter', 'ttlMonitorSleepSecs=1'], storageEngine: 'wiredTiger' } }); // using 3 because even numbers can lead to vote problems replseturi = mongorreplset.getUri(); } else { replseturi = process.env.MONGOOSE_REPLSET_URI; }
process.env.MONGOOSE_TEST_URI = instanceuri; process.env.MONGOOSE_REPLSET_URI = replseturi;};
module.exports.mochaGlobalTeardown = async function mochaGlobalTeardown() { if (mongoinstance) { await mongoinstance.stop(); } if (mongorreplset) { await mongorreplset.stop(); }};
mongoose

Version Info

Tagged at
a year ago