Skip to content

Commit

Permalink
refactor: remove async as a prod dependency
Browse files Browse the repository at this point in the history
Fix #8073
  • Loading branch information
vkarpov15 committed Sep 28, 2019
1 parent 3647292 commit 9bb4b03
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 130 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
],
"license": "MIT",
"dependencies": {
"async": "2.6.2",
"bson": "~1.1.1",
"kareem": "2.3.1",
"mongodb": "3.3.2",
Expand All @@ -37,6 +36,7 @@
"acquit": "1.x",
"acquit-ignore": "0.1.x",
"acquit-require": "0.1.x",
"async": "2.6.2",
"babel-loader": "7.1.4",
"babel-preset-es2015": "6.24.1",
"benchmark": "2.1.4",
Expand Down
33 changes: 6 additions & 27 deletions test/docs/discriminators.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var assert = require('assert');
var async = require('async');
var mongoose = require('../../');

var Schema = mongoose.Schema;
Expand Down Expand Up @@ -90,21 +89,14 @@ describe('discriminator docs', function () {
});
};

async.map([event1, event2, event3], save, function (error) {
// acquit:ignore:start
assert.ifError(error);
// acquit:ignore:end

Event.countDocuments({}, function (error, count) {
// acquit:ignore:start
assert.ifError(error);
// acquit:ignore:end
Promise.all([event1.save(), event2.save(), event3.save()]).
then(() => Event.countDocuments()).
then(count => {
assert.equal(count, 3);
// acquit:ignore:start
done();
// acquit:ignore:end
});
});
});

/**
Expand Down Expand Up @@ -138,29 +130,16 @@ describe('discriminator docs', function () {
var event2 = new ClickedLinkEvent({time: Date.now(), url: 'google.com'});
var event3 = new SignedUpEvent({time: Date.now(), user: 'testuser'});

var save = function (doc, callback) {
doc.save(function (error, doc) {
callback(error, doc);
});
};

async.map([event1, event2, event3], save, function (error) {
// acquit:ignore:start
assert.ifError(error);
// acquit:ignore:end

ClickedLinkEvent.find({}, function (error, docs) {
// acquit:ignore:start
assert.ifError(error);
// acquit:ignore:end
Promise.all([event1.save(), event2.save(), event3.save()]).
then(() => ClickedLinkEvent.find({})).
then(docs => {
assert.equal(docs.length, 1);
assert.equal(docs[0]._id.toString(), event2._id.toString());
assert.equal(docs[0].url, 'google.com');
// acquit:ignore:start
done();
// acquit:ignore:end
});
});
});

/**
Expand Down
78 changes: 26 additions & 52 deletions test/model.discriminator.querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const Schema = mongoose.Schema;
const assert = require('assert');
const random = require('../lib/utils').random;
const util = require('util');
const async = require('async');


/**
* Setup
Expand Down Expand Up @@ -47,21 +45,10 @@ describe('model', function() {
SecretEvent = BaseEvent.discriminator('model-discriminator-querying-secret', SecretEventSchema);
});

afterEach(function(done) {
async.series(
[
function removeBaseEvent(next) {
BaseEvent.deleteMany({}, next);
},
function removeImpressionEvent(next) {
ImpressionEvent.deleteMany({}, next);
},
function removeConversionEvent(next) {
ConversionEvent.deleteMany({}, next);
}
],
done
);
afterEach(function() {
return BaseEvent.deleteMany({}).
then(() => ImpressionEvent.deleteMany({})).
then(() => ConversionEvent.deleteMany({}));
});

after(function(done) {
Expand All @@ -86,7 +73,7 @@ describe('model', function() {
ContainerModel = db.model('container-event-model', ContainerSchema);
});

it('into non-discriminated arrays works', function(done) {
it('into non-discriminated arrays works', function() {
const c = new ContainerModel({
title: 'events-group-1'
});
Expand All @@ -95,32 +82,25 @@ describe('model', function() {
const d3 = new DiscCustomEvent();
c.events.push(d1);
c.events.push(d2);
async.series(
[
function(next) { d1.save(next); },
function(next) { d2.save(next); },
function(next) { d3.save(next); },
function(next) { c.save(next); },
function(next) {
ContainerModel.findOne({}).populate('events').exec(function(err, doc) {
assert.ifError(err);
assert.ok(doc.events && doc.events.length);
assert.equal(doc.events.length, 2);
doc.events.push(d3);
let hasDisc = false;
const discKey = DiscCustomEvent.schema.discriminatorMapping.key;
doc.events.forEach(function(subDoc) {
if (discKey in subDoc) {
hasDisc = true;
}
});
assert.ok(hasDisc);
next();
});
}
],
done
);

return d1.save().
then(() => d2.save()).
then(() => d3.save()).
then(() => c.save()).
then(() => ContainerModel.findOne({}).populate('events')).
then(doc => {
assert.ok(doc.events && doc.events.length);
assert.equal(doc.events.length, 2);
doc.events.push(d3);
let hasDisc = false;
const discKey = DiscCustomEvent.schema.discriminatorMapping.key;
doc.events.forEach(function(subDoc) {
if (discKey in subDoc) {
hasDisc = true;
}
});
assert.ok(hasDisc);
});
});
});

Expand Down Expand Up @@ -879,18 +859,12 @@ describe('model', function() {
describe('aggregate', function() {
let impressionEvent, conversionEvent, ignoredImpressionEvent;

beforeEach(function(done) {
beforeEach(function() {
impressionEvent = new ImpressionEvent({name: 'Test Event'});
conversionEvent = new ConversionEvent({name: 'Test Event', revenue: 10});
ignoredImpressionEvent = new ImpressionEvent({name: 'Ignored Event'});

async.forEach(
[impressionEvent, conversionEvent, ignoredImpressionEvent],
function(doc, cb) {
doc.save(cb);
},
done
);
return Promise.all([impressionEvent, conversionEvent, ignoredImpressionEvent].map(d => d.save()));
});

describe('using "RootModel#aggregate"', function() {
Expand Down
68 changes: 18 additions & 50 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

const assert = require('assert');
const async = require('async');
const co = require('co');
const start = require('./common');
const utils = require('../lib/utils');
Expand Down Expand Up @@ -4035,7 +4034,7 @@ describe('model: populate:', function() {
});
});

it('out-of-order discriminators (gh-4073)', function(done) {
it('out-of-order discriminators (gh-4073)', function() {
const UserSchema = new Schema({
name: String
});
Expand Down Expand Up @@ -4094,54 +4093,23 @@ describe('model: populate:', function() {
const be2 = new BlogPostEvent({ blogpost: b2 });
const be3 = new BlogPostEvent({ blogpost: b3 });

async.series(
[
u1.save.bind(u1),
u2.save.bind(u2),
u3.save.bind(u3),

c1.save.bind(c1),
c2.save.bind(c2),
c3.save.bind(c3),

b1.save.bind(b1),
b2.save.bind(b2),
b3.save.bind(b3),

ce1.save.bind(ce1),
ue1.save.bind(ue1),
be1.save.bind(be1),

ce2.save.bind(ce2),
ue2.save.bind(ue2),
be2.save.bind(be2),

ce3.save.bind(ce3),
ue3.save.bind(ue3),
be3.save.bind(be3),

function(next) {
Event.
find({}).
populate('user comment blogpost').
exec(function(err, docs) {
docs.forEach(function(doc) {
if (doc.__t === 'User4073') {
assert.ok(doc.user.name.indexOf('user') !== -1);
} else if (doc.__t === 'Comment4073') {
assert.ok(doc.comment.content.indexOf('comment') !== -1);
} else if (doc.__t === 'BlogPost4073') {
assert.ok(doc.blogpost.title.indexOf('blog post') !== -1);
} else {
assert.ok(false);
}
});
next();
});
}
],
done
);
const docs = [u1, u2, u3, c1, c2, c3, b1, b2, b3, ce1, ue1, be1, ce2, ue2, be2, ce3, ue3, be3];

return Promise.all(docs.map(d => d.save())).
then(() => Event.find({}).populate('user comment blogpost')).
then(docs => {
docs.forEach(function(doc) {
if (doc.__t === 'User4073') {
assert.ok(doc.user.name.indexOf('user') !== -1);
} else if (doc.__t === 'Comment4073') {
assert.ok(doc.comment.content.indexOf('comment') !== -1);
} else if (doc.__t === 'BlogPost4073') {
assert.ok(doc.blogpost.title.indexOf('blog post') !== -1);
} else {
assert.ok(false);
}
});
});
});

it('dynref bug (gh-4104)', function(done) {
Expand Down
1 change: 1 addition & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,7 @@ describe('Query', function() {
});

it('throw on sync exceptions in callbacks (gh-6178)', function(done) {
const async = require('async');
const schema = new Schema({});
const Test = db.model('gh6178', schema);

Expand Down

0 comments on commit 9bb4b03

Please sign in to comment.