Skip to content

Commit 1b0f95d

Browse files
Make CI work (resolves #225) (#227)
* #225: Fix JSDoc defaults syntax * #225: Fix incorrect default value in JSDoc * #225: Make ESLint config more pagmatic * #225: Fix ESLint errors * #225: Add mongodb-memory-server dev dependency * #225: Allow using process.env in tests * #225: Make tests use in-memory MongoDB by default * #225: Make sure 'npm test' actually finishes * #225: Run CI against multiple MongoDB versions * #225: Log currently used MongoDB version in tests * #225: Fix small typo * #225: Don't pull Mongo binary on 'npm ci' on local By default, mongodb-memory-server pulls in a MongoDB binary on install. On a first run of 'npm ci', this makes npm seem to hang for no reason. No progress bar or anything is shown either. With this change, the MongoDB binary is only downloaded when needed. If needed, the download happens during tests, with progress indication. No download will happen for people using local Mongo for testing.
1 parent 9e86ae1 commit 1b0f95d

File tree

8 files changed

+2145
-204
lines changed

8 files changed

+2145
-204
lines changed

.eslintrc

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
"extends": "@dabh/eslint-config-populist",
33
"rules": {
44
"one-var": ["error", { "var": "never", "let": "never", "const": "never" }],
5-
"strict": 0
5+
"no-unused-vars": ["error", { "ignoreRestSiblings": true }],
6+
"no-undefined": "off",
7+
"no-console": "off",
8+
"strict": "off"
69
},
710
"parserOptions": {
8-
"ecmaVersion": 2022,
11+
"ecmaVersion": 2022
912
},
1013
"env": {
1114
"es2020": true

.github/workflows/ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ jobs:
1919
- 16
2020
- 18
2121
- 20
22+
mongo:
23+
- v6.0-latest
24+
- v5.0-latest
25+
- v4.4-latest
2226
steps:
2327
- uses: actions/checkout@v3
2428
- uses: actions/setup-node@v3
2529
with:
2630
node-version: ${{ matrix.node }}
2731
- name: Install Dependencies
32+
env:
33+
MONGOMS_VERSION: ${{ matrix.mongo }}
34+
MONGOMS_DISABLE_POSTINSTALL: 0
2835
run: npm clean-install
2936
- name: Lint
3037
run: npm run lint
3138
- name: Test
39+
env:
40+
MONGOMS_VERSION: ${{ matrix.mongo }}
3241
run: npm test

lib/helpers.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const ObjectID = require('mongodb').ObjectID;
1010

1111
/**
1212
* Prepares metadata to store into database.
13-
* @param {*} meta Metadata
14-
* @returns {*}
13+
* @param {Object} meta Metadata
14+
* @returns {Object} Prepared metadata
1515
*/
1616
exports.prepareMetaData = meta => {
1717
return cloneMeta(meta);
@@ -23,7 +23,8 @@ exports.prepareMetaData = meta => {
2323
* with string '[Circular]' and fixes field names to be storable within
2424
* MongoDB
2525
* @param {Object} node Current object or its leaf
26-
* @param {Array=} optParents Object's parents
26+
* @param {Array} optParents Object's parents
27+
* @returns {Object} Adjusted clone of object
2728
*/
2829
function cloneMeta(node, optParents) {
2930
if (!((node !== null && typeof node === 'object') || typeof node === 'function')

lib/winston-mongodb.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ const helpers = require('./helpers');
1919
/**
2020
* Constructor for the MongoDB transport object.
2121
* @constructor
22-
* @param {Object} options
23-
* @param {string=info} options.level Level of messages that this transport
22+
* @param {Object} options Options
23+
* @param {string} [options.level=info] Level of messages that this transport
2424
* should log.
25-
* @param {boolean=false} options.silent Boolean flag indicating whether to
25+
* @param {boolean} [options.silent=false] Boolean flag indicating whether to
2626
* suppress output.
2727
* @param {string|Object} options.db MongoDB connection uri or preconnected db
2828
* object.
2929
* @param {string} options.dbName The database name to connect to,
3030
* defaults to DB name based on connection URI if not provided
3131
* @param {Object} options.options MongoDB connection parameters
3232
* (optional, defaults to `{poolSize: 2, autoReconnect: true, useNewUrlParser: true}`).
33-
* @param {string=logs} options.collection The name of the collection you want
33+
* @param {string} [options.collection=log] The name of the collection you want
3434
* to store log messages in.
35-
* @param {boolean=false} options.storeHost Boolean indicating if you want to
35+
* @param {boolean} [options.storeHost=false] Boolean indicating if you want to
3636
* store machine hostname in logs entry, if set to true it populates MongoDB
3737
* entry with 'hostname' field, which stores os.hostname() value.
3838
* @param {string} options.label Label stored with entry object if defined.
3939
* @param {string} options.name Transport instance identifier. Useful if you
4040
* need to create multiple MongoDB transports.
41-
* @param {boolean=false} options.capped In case this property is true,
41+
* @param {boolean} [options.capped=false] In case this property is true,
4242
* winston-mongodb will try to create new log collection as capped.
43-
* @param {number=10000000} options.cappedSize Size of logs capped collection
43+
* @param {number} [options.cappedSize=10000000] Size of logs capped collection
4444
* in bytes.
4545
* @param {number} options.cappedMax Size of logs capped collection in number
4646
* of documents.
47-
* @param {boolean=false} options.tryReconnect Will try to reconnect to the
47+
* @param {boolean} [options.tryReconnect=false] Will try to reconnect to the
4848
* database in case of fail during initialization. Works only if `db` is
4949
* a string.
50-
* @param {boolean=false} options.decolorize Will remove color attributes from
50+
* @param {boolean} [options.decolorize=false] Will remove color attributes from
5151
* the log entry message.
52-
* @param {boolean=false} options.leaveConnectionOpen Will leave MongoClient connected
52+
* @param {boolean} [options.leaveConnectionOpen=false] Will leave MongoClient connected
5353
* after transport shut down.
5454
* @param {number} options.expireAfterSeconds Seconds before the entry is removed.
5555
* Do not use if capped is set.
@@ -189,7 +189,7 @@ MongoDB.prototype.close = function () {
189189
if (!this.mongoClient || this.leaveConnectionOpen) {
190190
return;
191191
}
192-
this.mongoClient.close().then(() => this.mongoClient = null).catch(err => {
192+
this.mongoClient.close().then(() => { this.mongoClient = null; }).catch(err => {
193193
console.error('Winston MongoDB transport encountered on error during '
194194
+ 'closing.', err);
195195
});
@@ -200,6 +200,7 @@ MongoDB.prototype.close = function () {
200200
* Core logging method exposed to Winston. Metadata is optional.
201201
* @param {Object} info Logging metadata
202202
* @param {Function} cb Continuation to respond to when complete.
203+
* @returns {boolean} Result boolean
203204
*/
204205
MongoDB.prototype.log = function (info, cb) {
205206
if (!this.logDb) {
@@ -213,8 +214,10 @@ MongoDB.prototype.log = function (info, cb) {
213214
// If database logs, better not to call database itself in the same call.
214215
process.nextTick(() => {
215216
if (this.silent) {
217+
// eslint-disable-next-line callback-return
216218
cb(null, true);
217219
}
220+
// eslint-disable-next-line no-control-regex
218221
const decolorizeRegex = new RegExp(/\u001b\[[0-9]{1,2}m/g);
219222
const entry = { timestamp: new Date(), level: (this.decolorize) ? info.level.replace(decolorizeRegex, '') : info.level };
220223
const msg = util.format(info.message, ...(info.splat || []));
@@ -250,7 +253,6 @@ MongoDB.prototype.log = function (info, cb) {
250253
* Query the transport. Options object is optional.
251254
* @param {Object=} optOptions Loggly-like query options for this instance.
252255
* @param {Function} cb Continuation to respond to when complete.
253-
* @returns {*}
254256
*/
255257
MongoDB.prototype.query = function (optOptions, cb) {
256258
if (!this.logDb) {
@@ -285,7 +287,7 @@ MongoDB.prototype.query = function (optOptions, cb) {
285287
* This will only work with a capped collection.
286288
* @param {Object} options Stream options for this instance.
287289
* @param {Stream} stream Pass in a pre-existing stream.
288-
* @returns {Stream}
290+
* @returns {Stream} Log stream for the transport
289291
*/
290292
MongoDB.prototype.stream = function (options, stream) {
291293
options = options || {};
@@ -343,7 +345,7 @@ MongoDB.prototype.stream = function (options, stream) {
343345
* Returns a log stream for this transport. Options object is optional.
344346
* @param {Object} options Stream options for this instance.
345347
* @param {Stream} stream Pass in a pre-existing stream.
346-
* @returns {Stream}
348+
* @returns {Stream} Log stream for the transport
347349
*/
348350
MongoDB.prototype.streamPoll = function (options, stream) {
349351
options = options || {};
@@ -398,6 +400,7 @@ MongoDB.prototype.streamPoll = function (options, stream) {
398400
if (stream.destroyed) {
399401
return;
400402
}
403+
// eslint-disable-next-line callback-return
401404
next();
402405
stream.emit('error', err);
403406
});

0 commit comments

Comments
 (0)