Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
replace jscs, jshint by eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe committed Dec 25, 2015
1 parent 1dcccf7 commit 467e9ff
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 43 deletions.
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "airbnb/base",
"ecmaFeatures": {
"generators": true
},
"rules": {
"object-curly-spacing": 0,
"no-cond-assign": [2, "except-parens"]
}
}
3 changes: 0 additions & 3 deletions .jscsrc

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"description": "Erase collections, models and schemas for unit testing with mongoose",
"main": "src/index.js",
"scripts": {
"test": "npm run jshint && npm run jscs && mocha",
"jshint": "jshint **/*.js",
"jscs": "jscs **/*.js",
"lint": "eslint test src",
"test": "npm run lint && mocha test/",
"coveralls": "mocha --require blanket -R mocha-lcov-reporter | coveralls"
},
"repository": {
Expand All @@ -32,8 +31,8 @@
"devDependencies": {
"blanket": "^1.1.7",
"coveralls": "^2.11.4",
"jscs": "^2.1.0",
"jshint": "^2.8.0",
"eslint": "^1.9.0",
"eslint-config-airbnb": "^2.0.0",
"mocha": "^2.2.5",
"mocha-lcov-reporter": "1.0.0",
"mongoose": "^4.1.2",
Expand Down
34 changes: 17 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
var async = require('async');
const async = require('async');

// requires mongoose to be connected to the database
function erase(mongoose, done) {
async.waterfall([
// ensure a database connection is established
function(cb) {
(cb) => {
if (!mongoose.connection.db) {
return cb(new Error('no established database connection'));
}
cb();
},
// get collections
function(cb) {
(cb) => {
mongoose.connection.db.collections(cb);
},
// drop collections
function(collections, cb) {
async.each(collections, function(collection, eachCb) {
(collections, cb) => {
async.each(collections, (collection, eachCb) => {
if (collection.collectionName.match(/^system\./)) {return eachCb();}
// drop collection
collection.drop(eachCb);
}, cb);
},
// reset mongoose models
function(cb) {
(cb) => {
mongoose.connection.models = {};
mongoose.models = {};
mongoose.modelSchemas = {};
cb();
},
//// ensureIndexes
//_.map(models, function (model) {
// return model.ensureIndexes.bind(model);
//})
// // ensureIndexes
// _.map(models, function (model) {
// return model.ensureIndexes.bind(model);
// })
], done);
}

Expand All @@ -42,21 +42,21 @@ function connect(mongoose, dbURI, options, cb) {
}

function connectAndErase(mongoose, dbURI, options) {
options = options || {};
return function(done) {
const newOptions = options || {};
return (done) => {
async.series([
function(cb) {
connect(mongoose, dbURI, options, cb);
(cb) => {
connect(mongoose, dbURI, newOptions, cb);
},
function(cb) {
(cb) => {
erase(mongoose, cb);
}
},
], done);
};
}

module.exports = {
connect: connect,
erase: erase,
connectAndErase: connectAndErase
connectAndErase: connectAndErase,
};
13 changes: 13 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../.eslintrc",
"env": {
"mocha": true
},
"globals": {
"should": true
},
"rules": {
"func-names": 0,
"no-unused-expressions": 0
}
}
33 changes: 15 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
var dbURI = 'mongodb://localhost/mongoose-erase';
var mongoose = require('mongoose');
var async = require('async');
var should = require('should');
const dbURI = 'mongodb://localhost/mongoose-erase';
const mongoose = require('mongoose');
const async = require('async');

var erase = require('../');
const erase = require('../');

describe('erase()', function() {

before(function(done) {
describe('erase()', () => {
before((done) => {
async.series([
// make sure that database is connected and erase it
erase.connectAndErase(mongoose, dbURI),
// add collection users
function(cb) {
var User = mongoose.model('User', new mongoose.Schema({
name: {type: String, index: true}
(cb) => {
const User = mongoose.model('User', new mongoose.Schema({
name: {type: String, index: true},
}));
User.create({name: 'Darth'}, cb);
},
// erase
function(cb) {
(cb) => {
erase.erase(mongoose, cb);
}
},
], done);
});

it('should remove collections', function(done) {
mongoose.connection.db.collections(function(err, collections) {
it('should remove collections', function assertDeletion(done) {
mongoose.connection.db.collections((err, collections) => {
if (err) {return done(err);}
collections.should.have.lengthOf(1);
done();
});
});

it('should remove models', function() {
(function() {
it('should remove models', () => {
(() => {
mongoose.model('User');
}).should.throw();
});

});
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--compilers js:babel-core/register
--recursive
-r should

0 comments on commit 467e9ff

Please sign in to comment.