Skip to content

Commit 43a0138

Browse files
authoredJul 24, 2018
Merge pull request #441 from strongloop/drop-node
chore: drop node 4 and update deps
2 parents 60aaecc + 3773a16 commit 43a0138

20 files changed

+2452
-1528
lines changed
 

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

‎.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: node_js
22
node_js:
3-
- "4"
43
- "6"
4+
- "8"
5+
- "10"
56
env:
67
- CXX=g++-4.8
78
addons:

‎benchmarks/index.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var DataSource = require('loopback-datasource-juggler').DataSource;
79
var connector = require('..');
810
var Benchmark = require('benchmark');
@@ -13,7 +15,7 @@ var ds = new DataSource(connector, {
1315
database: process.env.LB_DB || 'strongloop',
1416
});
1517
var Todo = ds.define('Todo', {
16-
content: { type: String },
18+
content: {type: String},
1719
});
1820

1921
// not critical for MongoDB, but may uncover inefficiencies in SQL connectors
@@ -25,15 +27,15 @@ function resetTestState() {
2527
Todo.destroyAll();
2628
}
2729

28-
var suite = new Benchmark.Suite;
30+
var suite = new Benchmark.Suite();
2931
suite
3032
.on('start', function() {
3133
console.log('#', new Date());
3234
})
3335
.add('create', {
3436
defer: true,
3537
fn: function(deferred) {
36-
Todo.create({ content: 'Buy eggs, ' + (uniqVal++) }, function() {
38+
Todo.create({content: 'Buy eggs, ' + uniqVal++}, function() {
3739
deferred.resolve();
3840
});
3941
},
@@ -48,25 +50,25 @@ suite
4850
},
4951
onStart: function() {
5052
Todo.create([
51-
{ content: 'Buy eggs' },
52-
{ content: 'Buy milk' },
53-
{ content: 'Buy cheese' },
53+
{content: 'Buy eggs'},
54+
{content: 'Buy milk'},
55+
{content: 'Buy cheese'},
5456
]);
5557
},
5658
onComplete: resetTestState,
5759
})
5860
.add('find with a simple filter', {
5961
defer: true,
6062
fn: function(deferred) {
61-
Todo.find({ where: { content: 'Buy milk' }}, function() {
63+
Todo.find({where: {content: 'Buy milk'}}, function() {
6264
deferred.resolve();
6365
});
6466
},
6567
onStart: function() {
6668
Todo.create([
67-
{ content: 'Buy eggs' },
68-
{ content: 'Buy milk' },
69-
{ content: 'Buy cheese' },
69+
{content: 'Buy eggs'},
70+
{content: 'Buy milk'},
71+
{content: 'Buy cheese'},
7072
]);
7173
},
7274
onComplete: resetTestState,
@@ -79,4 +81,4 @@ suite
7981
Todo.destroyAll();
8082
process.exit();
8183
})
82-
.run({ async: true });
84+
.run({async: true});

‎example/model.js

+56-42
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,66 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var g = require('strong-globalize')();
79

810
var DataSource = require('loopback-datasource-juggler').DataSource;
911

10-
var config = require('rc')('loopback', { dev: { mongodb: {}}}).dev.mongodb;
12+
var config = require('rc')('loopback', {dev: {mongodb: {}}}).dev.mongodb;
1113

1214
var ds = new DataSource(require('../'), config);
1315

14-
var Customer = ds.createModel('customer', { seq: { type: Number, id: true }, name: String, emails: [
15-
{ label: String, email: String },
16-
], age: Number });
16+
var Customer = ds.createModel('customer', {
17+
seq: {type: Number, id: true},
18+
name: String,
19+
emails: [{label: String, email: String}],
20+
age: Number,
21+
});
1722

1823
Customer.destroyAll(function(err) {
19-
Customer.create({
20-
seq: 1,
21-
name: 'John1',
22-
emails: [
23-
{ label: 'work', email: 'john@x.com' },
24-
{ label: 'home', email: 'john@y.com' },
25-
],
26-
age: 30,
27-
}, function(err, customer1) {
28-
console.log(customer1.toObject());
29-
30-
Customer.create({
31-
seq: 2,
32-
name: 'John2',
24+
Customer.create(
25+
{
26+
seq: 1,
27+
name: 'John1',
3328
emails: [
34-
{ label: 'work', email: 'john2@x.com' },
35-
{ label: 'home', email: 'john2@y.com' },
29+
{label: 'work', email: 'john@x.com'},
30+
{label: 'home', email: 'john@y.com'},
3631
],
37-
age: 35,
38-
}, function(err, customer2) {
39-
Customer.find({ where: { 'emails.email': 'john@x.com' }}, function(err, customers) {
40-
g.log('{{Customers}} matched by {{emails.email}} %s', customers);
41-
});
32+
age: 30,
33+
},
34+
function(err, customer1) {
35+
console.log(customer1.toObject());
36+
37+
Customer.create(
38+
{
39+
seq: 2,
40+
name: 'John2',
41+
emails: [
42+
{label: 'work', email: 'john2@x.com'},
43+
{label: 'home', email: 'john2@y.com'},
44+
],
45+
age: 35,
46+
},
47+
function(err, customer2) {
48+
Customer.find({where: {'emails.email': 'john@x.com'}}, function(
49+
err,
50+
customers
51+
) {
52+
g.log('{{Customers}} matched by {{emails.email}} %s', customers);
53+
});
4254

43-
Customer.find({ where: { 'emails.0.label': 'work' }}, function(err, customers) {
44-
g.log('{{Customers}} matched by {{emails.0.label}} %s', customers);
45-
});
46-
/*
55+
Customer.find({where: {'emails.0.label': 'work'}}, function(
56+
err,
57+
customers
58+
) {
59+
g.log('{{Customers}} matched by {{emails.0.label}} %s', customers);
60+
});
61+
/*
4762
customer1.updateAttributes({name: 'John'}, function(err, result) {
4863
console.log(err, result);
4964
});
5065
51-
5266
customer1.delete(function(err, result) {
5367
customer1.updateAttributes({name: 'JohnX'}, function(err, result) {
5468
console.log(err, result);
@@ -57,17 +71,17 @@ Customer.destroyAll(function(err) {
5771
});
5872
*/
5973

60-
Customer.findById(customer1.seq, function(err, customer1) {
61-
console.log(customer1.toObject());
74+
Customer.findById(customer1.seq, function(err, customer1) {
75+
console.log(customer1.toObject());
6276

63-
customer1.name = 'John';
64-
customer1.save(function(err, customer1) {
65-
console.log(customer1.toObject());
66-
ds.disconnect();
67-
});
68-
});
69-
});
70-
});
77+
customer1.name = 'John';
78+
customer1.save(function(err, customer1) {
79+
console.log(customer1.toObject());
80+
ds.disconnect();
81+
});
82+
});
83+
}
84+
);
85+
}
86+
);
7187
});
72-
73-

‎index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var SG = require('strong-globalize');
79
SG.SetRootDir(__dirname);
810

‎leak-detection/fixtures/todo.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var DataSource = require('loopback-datasource-juggler').DataSource;
79
var connector = require('../..');
810

@@ -12,7 +14,7 @@ var db = new DataSource(connector, {
1214
database: process.env.LB_DB || 'strongloop',
1315
});
1416
var Todo = db.define('Todo', {
15-
content: { type: String },
17+
content: {type: String},
1618
});
1719

1820
module.exports = Todo;

‎leak-detection/globals.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
global.sinon = require('sinon');
6+
'use strict';
7+
78
global.ITERATIONS = process.env.ITERATIONS || 100;
89
require('should');

‎leak-detection/leak-detector.test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var memwatch = require('memwatch-next');
9+
var sinon = require('sinon');
710

811
describe('leak detector', function() {
912
before(function() {
@@ -16,8 +19,8 @@ describe('leak detector', function() {
1619
var iterations = 0;
1720
var leaks = [];
1821
var interval = setInterval(function() {
19-
if (test.iterations >= ITERATIONS || test.spy.called) {
20-
test.spy.called.should.be.true;
22+
if (test.iterations >= global.ITERATIONS || test.spy.called) {
23+
test.spy.called.should.be.True();
2124
clearInterval(interval);
2225
return done();
2326
}

‎leak-detection/mongodb.test.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var memwatch = require('memwatch-next');
9+
var sinon = require('sinon');
710
var Todo = require('./fixtures/todo');
811

912
describe('mongodb', function() {
@@ -29,12 +32,13 @@ describe('mongodb', function() {
2932
hasOptions = false;
3033
}
3134
var interval = setInterval(function() {
32-
if (ctx.iterations >= ITERATIONS || ctx.spy.called) {
33-
ctx.spy.called.should.be.false;
35+
if (ctx.iterations >= global.ITERATIONS || ctx.spy.called) {
36+
ctx.spy.called.should.be.False();
3437
clearInterval(interval);
3538
return done();
3639
}
3740
ctx.iterations++;
41+
// eslint-disable-next-line
3842
hasOptions ? Todo[func](options) : Todo[func];
3943
}, 0);
4044
}
@@ -45,15 +49,18 @@ describe('mongodb', function() {
4549
});
4650

4751
beforeEach(function createFixtures(done) {
48-
Todo.create([
49-
{ content: 'Buy eggs' },
50-
{ content: 'Buy milk' },
51-
{ content: 'Buy cheese' },
52-
], done);
52+
Todo.create(
53+
[
54+
{content: 'Buy eggs'},
55+
{content: 'Buy milk'},
56+
{content: 'Buy cheese'},
57+
],
58+
done
59+
);
5360
});
5461

5562
it('should not leak when retrieving a specific item', function(done) {
56-
execute(this, 'find', { where: { content: 'Buy eggs' }}, done);
63+
execute(this, 'find', {where: {content: 'Buy eggs'}}, done);
5764
});
5865

5966
it('should not leak when retrieving all items', function(done) {
@@ -67,15 +74,20 @@ describe('mongodb', function() {
6774
});
6875

6976
it('should not leak when creating an item', function(done) {
70-
execute(this, 'create', { content: 'Buy eggs' }, done);
77+
execute(this, 'create', {content: 'Buy eggs'}, done);
7178
});
7279

7380
it('should not leak when creating multiple items', function(done) {
74-
execute(this, 'create', [
75-
{ content: 'Buy eggs' },
76-
{ content: 'Buy milk' },
77-
{ content: 'Buy cheese' },
78-
], done);
81+
execute(
82+
this,
83+
'create',
84+
[
85+
{content: 'Buy eggs'},
86+
{content: 'Buy milk'},
87+
{content: 'Buy cheese'},
88+
],
89+
done
90+
);
7991
});
8092
});
8193
});

‎lib/mongodb.js

+458-252
Large diffs are not rendered by default.

‎lib/test-utils.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
exports.getDistanceBetweenPoints = function getDistanceBetweenPoints(point1, point2) {
6+
'use strict';
7+
8+
exports.getDistanceBetweenPoints = function getDistanceBetweenPoints(
9+
point1,
10+
point2
11+
) {
712
var R = 6371; // Radius of the earth in km
8-
var dLat = deg2rad(point2.lat - point1.lat); // deg2rad below
13+
var dLat = deg2rad(point2.lat - point1.lat); // deg2rad below
914
var dLon = deg2rad(point2.lng - point1.lng);
1015
var a =
1116
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
12-
Math.cos(deg2rad(point1.lat)) * Math.cos(deg2rad(point2.lat)) *
13-
Math.sin(dLon / 2) * Math.sin(dLon / 2);
17+
Math.cos(deg2rad(point1.lat)) *
18+
Math.cos(deg2rad(point2.lat)) *
19+
Math.sin(dLon / 2) *
20+
Math.sin(dLon / 2);
1421

1522
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
1623
var d = R * c; // Distance in km

‎package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"version": "3.4.4",
44
"description": "The official MongoDB connector for the LoopBack framework.",
55
"engines": {
6-
"node": ">=4"
6+
"node": ">=6"
77
},
88
"main": "index.js",
99
"scripts": {
1010
"benchmarks": "make benchmarks",
1111
"leak-detection": "make leak-detection",
12-
"test": "mocha -G --timeout 10000 --require test/init.js test/*.test.js",
12+
"test": "mocha",
1313
"lint": "eslint .",
1414
"posttest": "npm run lint"
1515
},
@@ -29,21 +29,21 @@
2929
"async": "^2.6.0",
3030
"bson": "^1.0.6",
3131
"debug": "^3.1.0",
32-
"loopback-connector": "^4.0.0",
32+
"loopback-connector": "^4.5.0",
3333
"mongodb": "^3.0.1",
34-
"strong-globalize": "^3.1.0"
34+
"strong-globalize": "^4.1.1"
3535
},
3636
"devDependencies": {
3737
"benchmark": "^2.1.4",
3838
"bluebird": "^3.5.1",
39-
"eslint": "^2.7.0",
40-
"eslint-config-loopback": "^1.0.0",
39+
"eslint": "^5.1.0",
40+
"eslint-config-loopback": "^10.0.0",
4141
"loopback-datasource-juggler": "^3.0.0",
4242
"memwatch-next": "^0.3.0",
43-
"mocha": "^2.1.0",
44-
"rc": "^1.0.0",
43+
"mocha": "^5.2.0",
44+
"rc": "^1.2.8",
4545
"semver": "^5.5.0",
46-
"should": "^8.0.2",
47-
"sinon": "^1.15.4"
46+
"should": "^13.2.1",
47+
"sinon": "^6.1.3"
4848
}
4949
}

‎test/connector-functions.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
// This test written in mocha+should.js
79
var should = require('./init.js');
810

911
describe('connector function - findById', function() {
1012
var db, TestAlias, sampleId;
1113
before(function(done) {
12-
db = getDataSource();
13-
TestAlias = db.define('TestAlias', { foo: { type: String }});
14+
db = global.getDataSource();
15+
TestAlias = db.define('TestAlias', {foo: {type: String}});
1416
db.automigrate(function(err) {
1517
if (err) return done(err);
16-
TestAlias.create({ foo: 'foo' }, function(err, t) {
18+
TestAlias.create({foo: 'foo'}, function(err, t) {
1719
if (err) return done(err);
1820
sampleId = t.id;
1921
done();

‎test/id.test.js

+129-85
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,50 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
require('./init.js');
7-
var ds = getDataSource();
9+
var ds = global.getDataSource();
810

911
describe('mongodb custom id name', function() {
1012
var Customer = ds.createModel(
1113
'customer',
12-
{ seq: { type: Number, id: true }, name: String, emails: [String], age: Number },
13-
{ forceId: false });
14+
{
15+
seq: {type: Number, id: true},
16+
name: String,
17+
emails: [String],
18+
age: Number,
19+
},
20+
{forceId: false}
21+
);
1422
before(function(done) {
1523
Customer.deleteAll(done);
1624
});
1725

1826
it('should allow custom name for the id property for create', function(done) {
19-
Customer.create({
20-
seq: 1,
21-
name: 'John1',
22-
emails: ['john@x.com', 'john@y.com'],
23-
age: 30,
24-
}, function(err, customer) {
25-
customer.seq.should.equal(1);
26-
Customer.create({
27-
seq: 2,
28-
name: 'John2',
29-
emails: ['john2@x.com', 'john2@y.com'],
30-
age: 40,
31-
}, function(err, customer) {
32-
customer.seq.should.equal(2);
33-
done(err, customer);
34-
});
35-
});
27+
Customer.create(
28+
{
29+
seq: 1,
30+
name: 'John1',
31+
emails: ['john@x.com', 'john@y.com'],
32+
age: 30,
33+
},
34+
function(err, customer) {
35+
customer.seq.should.equal(1);
36+
Customer.create(
37+
{
38+
seq: 2,
39+
name: 'John2',
40+
emails: ['john2@x.com', 'john2@y.com'],
41+
age: 40,
42+
},
43+
function(err, customer) {
44+
customer.seq.should.equal(2);
45+
done(err, customer);
46+
}
47+
);
48+
}
49+
);
3650
});
3751

3852
it('should allow custom name for the id property for findById', function(done) {
@@ -43,7 +57,7 @@ describe('mongodb custom id name', function() {
4357
});
4458

4559
it('should allow inq with find', function(done) {
46-
Customer.find({ where: { seq: { inq: [1] }}}, function(err, customers) {
60+
Customer.find({where: {seq: {inq: [1]}}}, function(err, customers) {
4761
customers.length.should.equal(1);
4862
customers[0].seq.should.equal(1);
4963
done(err);
@@ -54,35 +68,47 @@ describe('mongodb custom id name', function() {
5468
describe('mongodb string id', function() {
5569
var Customer = ds.createModel(
5670
'customer2',
57-
{ seq: { type: String, id: true }, name: String, emails: [String], age: Number },
58-
{ forceId: false });
71+
{
72+
seq: {type: String, id: true},
73+
name: String,
74+
emails: [String],
75+
age: Number,
76+
},
77+
{forceId: false}
78+
);
5979
var customer1, customer2;
6080

6181
before(function(done) {
6282
Customer.deleteAll(done);
6383
});
6484

6585
it('should allow custom name for the id property for create', function(done) {
66-
Customer.create({
67-
seq: '1',
68-
name: 'John1',
69-
emails: ['john@x.com', 'john@y.com'],
70-
age: 30,
71-
}, function(err, customer) {
72-
customer.seq.should.equal('1');
73-
customer1 = customer;
74-
var customer2Id = new ds.ObjectID().toString();
75-
Customer.create({
76-
seq: customer2Id,
77-
name: 'John2',
78-
emails: ['john2@x.com', 'john2@y.com'],
79-
age: 40,
80-
}, function(err, customer) {
81-
customer2 = customer;
82-
customer.seq.toString().should.eql(customer2Id);
83-
done(err, customer);
84-
});
85-
});
86+
Customer.create(
87+
{
88+
seq: '1',
89+
name: 'John1',
90+
emails: ['john@x.com', 'john@y.com'],
91+
age: 30,
92+
},
93+
function(err, customer) {
94+
customer.seq.should.equal('1');
95+
customer1 = customer;
96+
var customer2Id = new ds.ObjectID().toString();
97+
Customer.create(
98+
{
99+
seq: customer2Id,
100+
name: 'John2',
101+
emails: ['john2@x.com', 'john2@y.com'],
102+
age: 40,
103+
},
104+
function(err, customer) {
105+
customer2 = customer;
106+
customer.seq.toString().should.eql(customer2Id);
107+
done(err, customer);
108+
}
109+
);
110+
}
111+
);
86112
});
87113

88114
it('should allow custom name for the id property for findById', function(done) {
@@ -93,15 +119,18 @@ describe('mongodb string id', function() {
93119
});
94120

95121
it('should allow inq with find', function(done) {
96-
Customer.find({ where: { seq: { inq: [1] }}}, function(err, customers) {
122+
Customer.find({where: {seq: {inq: [1]}}}, function(err, customers) {
97123
customers.length.should.equal(1);
98124
customers[0].seq.should.equal('1');
99125
done(err);
100126
});
101127
});
102128

103-
it('should allow inq with find', function(done) {
104-
Customer.find({ where: { seq: { inq: [customer2.seq] }}}, function(err, customers) {
129+
it('should allow inq with find - test 2', function(done) {
130+
Customer.find({where: {seq: {inq: [customer2.seq]}}}, function(
131+
err,
132+
customers
133+
) {
105134
customers.length.should.equal(1);
106135
// seq is now a string
107136
customers[0].seq.should.eql(customer2.seq.toString());
@@ -113,30 +142,39 @@ describe('mongodb string id', function() {
113142
describe('mongodb default id type', function() {
114143
var Account = ds.createModel(
115144
'account',
116-
{ seq: { id: true, generated: true }, name: String, emails: [String], age: Number },
117-
{ forceId: false });
145+
{
146+
seq: {id: true, generated: true},
147+
name: String,
148+
emails: [String],
149+
age: Number,
150+
},
151+
{forceId: false}
152+
);
118153

119154
before(function(done) {
120155
Account.deleteAll(done);
121156
});
122157

123158
var id;
124159
it('should generate id value for create', function(done) {
125-
Account.create({
126-
name: 'John1',
127-
emails: ['john@x.com', 'john@y.com'],
128-
age: 30,
129-
}, function(err, account) {
130-
if (err) return done(err);
131-
account.should.have.property('seq');
132-
id = account.seq;
133-
Account.findById(id, function(err, account1) {
160+
Account.create(
161+
{
162+
name: 'John1',
163+
emails: ['john@x.com', 'john@y.com'],
164+
age: 30,
165+
},
166+
function(err, account) {
134167
if (err) return done(err);
135-
account1.seq.should.eql(account.seq);
136168
account.should.have.property('seq');
137-
done(err, account1);
138-
});
139-
});
169+
id = account.seq;
170+
Account.findById(id, function(err, account1) {
171+
if (err) return done(err);
172+
account1.seq.should.eql(account.seq);
173+
account.should.have.property('seq');
174+
done(err, account1);
175+
});
176+
}
177+
);
140178
});
141179

142180
it('should be able to find by string id', function(done) {
@@ -161,23 +199,27 @@ describe('mongodb default id type', function() {
161199
describe('mongodb default id name', function() {
162200
var Customer1 = ds.createModel(
163201
'customer1',
164-
{ name: String, emails: [String], age: Number },
165-
{ forceId: false });
202+
{name: String, emails: [String], age: Number},
203+
{forceId: false}
204+
);
166205

167206
before(function(done) {
168207
Customer1.deleteAll(done);
169208
});
170209

171210
it('should allow value for the id property for create', function(done) {
172-
Customer1.create({
173-
id: 1,
174-
name: 'John1',
175-
emails: ['john@x.com', 'john@y.com'],
176-
age: 30,
177-
}, function(err, customer) {
178-
customer.id.should.equal(1);
179-
done(err, customer);
180-
});
211+
Customer1.create(
212+
{
213+
id: 1,
214+
name: 'John1',
215+
emails: ['john@x.com', 'john@y.com'],
216+
age: 30,
217+
},
218+
function(err, customer) {
219+
customer.id.should.equal(1);
220+
done(err, customer);
221+
}
222+
);
181223
});
182224

183225
it('should allow value the id property for findById', function(done) {
@@ -188,18 +230,20 @@ describe('mongodb default id name', function() {
188230
});
189231

190232
it('should generate id value for create', function(done) {
191-
Customer1.create({
192-
name: 'John1',
193-
emails: ['john@x.com', 'john@y.com'],
194-
age: 30,
195-
}, function(err, customer) {
196-
// console.log(customer);
197-
customer.should.have.property('id');
198-
Customer1.findById(customer.id, function(err, customer1) {
199-
customer1.id.should.eql(customer.id);
200-
done(err, customer);
201-
});
202-
});
233+
Customer1.create(
234+
{
235+
name: 'John1',
236+
emails: ['john@x.com', 'john@y.com'],
237+
age: 30,
238+
},
239+
function(err, customer) {
240+
// console.log(customer);
241+
customer.should.have.property('id');
242+
Customer1.findById(customer.id, function(err, customer1) {
243+
customer1.id.should.eql(customer.id);
244+
done(err, customer);
245+
});
246+
}
247+
);
203248
});
204249
});
205-

‎test/imported.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
describe('mongodb imported features', function() {
79
before(function() {
810
require('./init.js');

‎test/init.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
module.exports = require('should');
79

810
var DataSource = require('loopback-datasource-juggler').DataSource;
911

1012
var TEST_ENV = process.env.TEST_ENV || 'test';
11-
var config = require('rc')('loopback', { test: { mongodb: {}}})[TEST_ENV].mongodb;
13+
var config = require('rc')('loopback', {test: {mongodb: {}}})[TEST_ENV]
14+
.mongodb;
1215

1316
config = {
1417
host: process.env.MONGODB_HOST || 'localhost',
1518
port: process.env.MONGODB_PORT || 27017,
16-
database: process.env.MONGODB_DATABASE || 'lb-ds-mongodb-test-' + (
17-
process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER || '1'
18-
),
19+
database:
20+
process.env.MONGODB_DATABASE ||
21+
'lb-ds-mongodb-test-' +
22+
(process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER || '1'),
1923
};
2024

2125
global.config = config;
@@ -34,5 +38,3 @@ global.connectorCapabilities = {
3438
nilike: false,
3539
nestedProperty: true,
3640
};
37-
38-
global.sinon = require('sinon');

‎test/mocha.opts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--exit
2+
--timeout 10000
3+
--require test/init.js
4+
--recursive

‎test/mongodb.test.js

+1,697-1,086
Large diffs are not rendered by default.

‎test/objectid.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
require('./init.js');
79

810
var db, Book, Chapter;
911

1012
describe('ObjectID', function() {
1113
before(function() {
12-
db = getDataSource();
14+
db = global.getDataSource();
1315
Book = db.define('Book');
1416
Chapter = db.define('Chapter');
1517
Book.hasMany('chapters');
@@ -24,7 +26,7 @@ describe('ObjectID', function() {
2426
};
2527

2628
Book.create(function(err, book) {
27-
Chapter.create({ bookId: book.id.toString() }, done);
29+
Chapter.create({bookId: book.id.toString()}, done);
2830
});
2931
});
3032

‎test/persistence-hooks.test.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
'use strict';
7+
68
var semver = require('semver');
79
var should = require('./init');
810
var suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js');
@@ -11,23 +13,27 @@ var customConfig = {
1113
enableOptimisedfindOrCreate: false,
1214
};
1315

14-
if (process.env.MONGODB_VERSION &&
15-
semver.satisfies(process.env.MONGODB_VERSION, '>= 2.6.0')) {
16+
if (
17+
process.env.MONGODB_VERSION &&
18+
semver.satisfies(process.env.MONGODB_VERSION, '>= 2.6.0')
19+
) {
1620
customConfig.enableOptimisedfindOrCreate = true;
1721
}
1822

19-
for (var i in config) {
20-
customConfig[i] = config[i];
23+
for (var i in global.config) {
24+
customConfig[i] = global.config[i];
2125
}
2226
var DB_VERSION = process.env.MONGODB_VERSION;
2327

2428
if (!DB_VERSION) {
25-
console.log('The ENV variable MONGODB_VERSION is not set.' +
26-
' Assuming MongoDB version 2.6 or newer.');
29+
console.log(
30+
'The ENV variable MONGODB_VERSION is not set.' +
31+
' Assuming MongoDB version 2.6 or newer.'
32+
);
2733
}
2834

29-
var DB_HAS_2_6_FEATURES = (!DB_VERSION ||
30-
semver.satisfies(DB_VERSION, '>=2.6.0'));
35+
var DB_HAS_2_6_FEATURES =
36+
!DB_VERSION || semver.satisfies(DB_VERSION, '>=2.6.0');
3137

3238
suite(global.getDataSource(customConfig), should, {
3339
replaceOrCreateReportsNewInstance: DB_HAS_2_6_FEATURES,

0 commit comments

Comments
 (0)
Please sign in to comment.