-
Notifications
You must be signed in to change notification settings - Fork 7
/
tests_prepare.js
113 lines (101 loc) · 4.48 KB
/
tests_prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// We are repurposing Minimongo tests to test reactive server-side MongoDB
// collections. So we have to do some preparations here.
originalLocalCollection = LocalCollection;
LocalCollection = function (name, options) {
// We want always to use MongoDB, not local collections.
name = name || Random.id();
// To make Mongo.Collection generate ObjectIDs by default.
options = options || {};
options.idGeneration = 'MONGO';
return new Mongo.Collection(name, options);
};
LocalCollection.wrapTransform = originalLocalCollection.wrapTransform;
LocalCollection._f = originalLocalCollection._f;
LocalCollection._compileProjection = originalLocalCollection._compileProjection;
LocalCollection._binarySearch = originalLocalCollection._binarySearch;
// Currently server and client side behaves differently when counting with skip. So we make it
// behave the same for tests. See https://github.com/meteor/meteor/issues/1201
var SynchronousCursor = Object.getPrototypeOf(MongoInternals.defaultRemoteCollectionDriver().mongo._createSynchronousCursor({'collectionName': 'foobar', 'options': {}})).constructor;
SynchronousCursor.prototype.count = function () {
return this._synchronousCount({'applySkipLimit': true}).wait();
};
var originalFind = Mongo.Collection.prototype.find;
Mongo.Collection.prototype.find = function (selector, options) {
// Few tests are expecting an exception for unsupported operators.
if (options && options.fields && (options.fields.grades || options.fields['grades.$'])) {
throw new Error("Unsupported in Minimongo");
}
if (selector && selector.location && selector.location['$not']) {
throw new Error("Unsupported in Minimongo");
}
if (selector && selector['$and'] && selector['$and'][0].location) {
throw new Error("Unsupported in Minimongo");
}
if (selector && selector['$or'] && selector['$or'][0].location) {
throw new Error("Unsupported in Minimongo");
}
if (selector && selector['$nor'] && selector['$nor'][0].location) {
throw new Error("Unsupported in Minimongo");
}
if (selector && selector['$and'] && selector['$and'][0]['$and'] && selector['$and'][0]['$and'][0].location) {
throw new Error("Unsupported in Minimongo");
}
// Geo queries need indexes.
if (selector && selector['rest.loc']) {
this._ensureIndex({'rest.loc': '2d'});
}
if (selector && selector['location']) {
this._ensureIndex({'location': '2dsphere'});
}
if (selector && selector['a.b']) {
this._ensureIndex({'a.b': '2d'});
}
return originalFind.apply(this, arguments);
};
var originalUpdate = Mongo.Collection.prototype.update;
Mongo.Collection.prototype.update = function (selector, mod, options, callback) {
if (selector && selector['a.b'] && selector['a.b'].$near) {
this._ensureIndex({'a.b': '2d'});
}
if (selector && selector['a.c'] && selector['a.c'].$near) {
this._ensureIndex({'a.c': '2d'});
}
return originalUpdate.apply(this, arguments);
};
var IGNORED_TESTS = [
// Tests which do not test any reactive behavior, just Minimongo specifics,
// and use code which does not exist on the server.
'minimongo - saveOriginals',
'minimongo - saveOriginals errors',
'minimongo - pause',
'minimongo - ids matched by selector',
// Flaky. Failing on Travis CI.
'minimongo - reactive count with cached cursor',
// Fail because of difference between Minimongo and server. For some of these
// tests (those with autorun) we have a fixed version in tests.js.
'minimongo - sort function',
'minimongo - cannot $set with null bytes',
'minimongo - cannot insert using invalid field names',
'minimongo - $near operator tests',
'minimongo - $near and $geometry for legacy coordinates',
'minimongo - modify',
// See: https://github.com/meteor/meteor-feature-requests/issues/252
'minimongo - basics',
// See: https://github.com/meteor/meteor/issues/3597
'minimongo - observe ordered',
'minimongo - observe ordered: true',
'minimongo - observe ordered: false',
'minimongo - observe ordered with projection',
'minimongo - reactive stop',
'minimongo - fetch in observe',
'minimongo - count on cursor with limit',
'minimongo - reactive skip/limit count while updating',
'minimongo - fine-grained reactivity of query with fields projection',
// See: https://github.com/meteor/meteor/issues/11855
'minimongo - fetch with projection, subarrays',
];
var originalTinytestAdd = Tinytest.add;
Tinytest.add = function (name, func) {
if (_.contains(IGNORED_TESTS, name)) return;
return originalTinytestAdd.call(Tinytest, name, func);
};