Skip to content

Commit

Permalink
feat: replace console.log with debug
Browse files Browse the repository at this point in the history
closes #105
  • Loading branch information
vladholubiev committed May 3, 2019
1 parent 42a8143 commit 5c2526f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ const path = require('path');
const fs = require('fs');
const globalConfigPath = path.join(__dirname, 'globalConfig.json');

const debug = require('debug')('jest-mongodb:environment');

module.exports = class MongoEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}

async setup() {
console.log('Setup MongoDB Test Environment');
debug('Setup MongoDB Test Environment');

const globalConfig = JSON.parse(fs.readFileSync(globalConfigPath, 'utf-8'));

Expand All @@ -20,7 +22,7 @@ module.exports = class MongoEnvironment extends NodeEnvironment {
}

async teardown() {
console.log('Teardown MongoDB Test Environment');
debug('Teardown MongoDB Test Environment');

await super.teardown();
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"dependencies": {
"cwd": "0.10.0",
"debug": "4.1.1",
"mongodb": "3.2.3",
"mongodb-memory-server": "5.1.0"
},
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ it('should insert a doc into collection', async () => {

Cache MongoDB binary in CI by putting this folder to the list of cached paths: `./node_modules/.cache/mongodb-memory-server/mongodb-binaries`

You can enable debug logs by setting environment variable `DEBUG=jest-mongodb:*`

## See Also

- [jest-dynamodb](https://github.com/shelfio/jest-dynamodb)
Expand Down
3 changes: 2 additions & 1 deletion setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const cwd = require('cwd');
const MongodbMemoryServer = require('mongodb-memory-server');
const globalConfigPath = join(__dirname, 'globalConfig.json');

const debug = require('debug')('jest-mongodb:setup');
const mongod = new MongodbMemoryServer.default(getMongodbMemoryOptions());

module.exports = async () => {
Expand All @@ -18,7 +19,7 @@ module.exports = async () => {

// Write global config to disk because all tests run in different contexts.
fs.writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));
console.log('Config is written');
debug('Config is written');

// Set reference to mongod in order to close the server during teardown.
global.__MONGOD__ = mongod;
Expand Down
4 changes: 3 additions & 1 deletion teardown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const debug = require('debug')('jest-mongodb:teardown');

module.exports = async function() {
console.log('Teardown mongod');
debug('Teardown mongod');
await global.__MONGOD__.stop();
};

0 comments on commit 5c2526f

Please sign in to comment.