Skip to content

Commit

Permalink
Make CI work (resolves #225) (#227)
Browse files Browse the repository at this point in the history
* #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.
  • Loading branch information
curledUpSheep authored Jul 13, 2023
1 parent 9e86ae1 commit 1b0f95d
Show file tree
Hide file tree
Showing 8 changed files with 2,145 additions and 204 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"extends": "@dabh/eslint-config-populist",
"rules": {
"one-var": ["error", { "var": "never", "let": "never", "const": "never" }],
"strict": 0
"no-unused-vars": ["error", { "ignoreRestSiblings": true }],
"no-undefined": "off",
"no-console": "off",
"strict": "off"
},
"parserOptions": {
"ecmaVersion": 2022,
"ecmaVersion": 2022
},
"env": {
"es2020": true
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ jobs:
- 16
- 18
- 20
mongo:
- v6.0-latest
- v5.0-latest
- v4.4-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
env:
MONGOMS_VERSION: ${{ matrix.mongo }}
MONGOMS_DISABLE_POSTINSTALL: 0
run: npm clean-install
- name: Lint
run: npm run lint
- name: Test
env:
MONGOMS_VERSION: ${{ matrix.mongo }}
run: npm test
7 changes: 4 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const ObjectID = require('mongodb').ObjectID;

/**
* Prepares metadata to store into database.
* @param {*} meta Metadata
* @returns {*}
* @param {Object} meta Metadata
* @returns {Object} Prepared metadata
*/
exports.prepareMetaData = meta => {
return cloneMeta(meta);
Expand All @@ -23,7 +23,8 @@ exports.prepareMetaData = meta => {
* with string '[Circular]' and fixes field names to be storable within
* MongoDB
* @param {Object} node Current object or its leaf
* @param {Array=} optParents Object's parents
* @param {Array} optParents Object's parents
* @returns {Object} Adjusted clone of object
*/
function cloneMeta(node, optParents) {

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v4.4-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v4.4-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v6.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v6.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v6.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v6.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v4.4-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v4.4-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v6.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v6.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v5.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v5.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v5.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v5.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v4.4-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v4.4-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v5.0-latest)

Function 'cloneMeta' has too many statements (22). Maximum allowed is 15

Check warning on line 29 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v5.0-latest)

Function 'cloneMeta' has a complexity of 18. Maximum allowed is 11
if (!((node !== null && typeof node === 'object') || typeof node === 'function')
Expand Down
31 changes: 17 additions & 14 deletions lib/winston-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ const helpers = require('./helpers');
/**
* Constructor for the MongoDB transport object.
* @constructor
* @param {Object} options
* @param {string=info} options.level Level of messages that this transport
* @param {Object} options Options
* @param {string} [options.level=info] Level of messages that this transport
* should log.
* @param {boolean=false} options.silent Boolean flag indicating whether to
* @param {boolean} [options.silent=false] Boolean flag indicating whether to
* suppress output.
* @param {string|Object} options.db MongoDB connection uri or preconnected db
* object.
* @param {string} options.dbName The database name to connect to,
* defaults to DB name based on connection URI if not provided
* @param {Object} options.options MongoDB connection parameters
* (optional, defaults to `{poolSize: 2, autoReconnect: true, useNewUrlParser: true}`).
* @param {string=logs} options.collection The name of the collection you want
* @param {string} [options.collection=log] The name of the collection you want
* to store log messages in.
* @param {boolean=false} options.storeHost Boolean indicating if you want to
* @param {boolean} [options.storeHost=false] Boolean indicating if you want to
* store machine hostname in logs entry, if set to true it populates MongoDB
* entry with 'hostname' field, which stores os.hostname() value.
* @param {string} options.label Label stored with entry object if defined.
* @param {string} options.name Transport instance identifier. Useful if you
* need to create multiple MongoDB transports.
* @param {boolean=false} options.capped In case this property is true,
* @param {boolean} [options.capped=false] In case this property is true,
* winston-mongodb will try to create new log collection as capped.
* @param {number=10000000} options.cappedSize Size of logs capped collection
* @param {number} [options.cappedSize=10000000] Size of logs capped collection
* in bytes.
* @param {number} options.cappedMax Size of logs capped collection in number
* of documents.
* @param {boolean=false} options.tryReconnect Will try to reconnect to the
* @param {boolean} [options.tryReconnect=false] Will try to reconnect to the
* database in case of fail during initialization. Works only if `db` is
* a string.
* @param {boolean=false} options.decolorize Will remove color attributes from
* @param {boolean} [options.decolorize=false] Will remove color attributes from
* the log entry message.
* @param {boolean=false} options.leaveConnectionOpen Will leave MongoClient connected
* @param {boolean} [options.leaveConnectionOpen=false] Will leave MongoClient connected
* after transport shut down.
* @param {number} options.expireAfterSeconds Seconds before the entry is removed.
* Do not use if capped is set.
Expand Down Expand Up @@ -189,7 +189,7 @@ MongoDB.prototype.close = function () {
if (!this.mongoClient || this.leaveConnectionOpen) {
return;
}
this.mongoClient.close().then(() => this.mongoClient = null).catch(err => {
this.mongoClient.close().then(() => { this.mongoClient = null; }).catch(err => {
console.error('Winston MongoDB transport encountered on error during '
+ 'closing.', err);
});
Expand All @@ -200,6 +200,7 @@ MongoDB.prototype.close = function () {
* Core logging method exposed to Winston. Metadata is optional.
* @param {Object} info Logging metadata
* @param {Function} cb Continuation to respond to when complete.
* @returns {boolean} Result boolean
*/
MongoDB.prototype.log = function (info, cb) {
if (!this.logDb) {
Expand All @@ -213,8 +214,10 @@ MongoDB.prototype.log = function (info, cb) {
// If database logs, better not to call database itself in the same call.
process.nextTick(() => {
if (this.silent) {
// eslint-disable-next-line callback-return
cb(null, true);
}
// eslint-disable-next-line no-control-regex
const decolorizeRegex = new RegExp(/\u001b\[[0-9]{1,2}m/g);
const entry = { timestamp: new Date(), level: (this.decolorize) ? info.level.replace(decolorizeRegex, '') : info.level };
const msg = util.format(info.message, ...(info.splat || []));
Expand Down Expand Up @@ -250,7 +253,6 @@ MongoDB.prototype.log = function (info, cb) {
* Query the transport. Options object is optional.
* @param {Object=} optOptions Loggly-like query options for this instance.
* @param {Function} cb Continuation to respond to when complete.
* @returns {*}
*/
MongoDB.prototype.query = function (optOptions, cb) {
if (!this.logDb) {
Expand Down Expand Up @@ -285,7 +287,7 @@ MongoDB.prototype.query = function (optOptions, cb) {
* This will only work with a capped collection.
* @param {Object} options Stream options for this instance.
* @param {Stream} stream Pass in a pre-existing stream.
* @returns {Stream}
* @returns {Stream} Log stream for the transport
*/
MongoDB.prototype.stream = function (options, stream) {

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v4.4-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v6.0-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v6.0-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v4.4-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v6.0-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v5.0-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v5.0-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v4.4-latest)

Function has too many statements (17). Maximum allowed is 15

Check warning on line 292 in lib/winston-mongodb.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v5.0-latest)

Function has too many statements (17). Maximum allowed is 15
options = options || {};
Expand Down Expand Up @@ -343,7 +345,7 @@ MongoDB.prototype.stream = function (options, stream) {
* Returns a log stream for this transport. Options object is optional.
* @param {Object} options Stream options for this instance.
* @param {Stream} stream Pass in a pre-existing stream.
* @returns {Stream}
* @returns {Stream} Log stream for the transport
*/
MongoDB.prototype.streamPoll = function (options, stream) {
options = options || {};
Expand Down Expand Up @@ -398,6 +400,7 @@ MongoDB.prototype.streamPoll = function (options, stream) {
if (stream.destroyed) {
return;
}
// eslint-disable-next-line callback-return
next();
stream.emit('error', err);
});
Expand Down
Loading

0 comments on commit 1b0f95d

Please sign in to comment.