Skip to content

Commit 340565a

Browse files
committed
assert usage doesn't increase
1 parent a15f1e9 commit 340565a

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/tools/runner/hooks/legacy.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import { expect } from 'chai';
2+
13
import { Collection } from '../../../../src';
24

35
// Setup legacy shims for tests that use removed or changed APIs
4-
const counts = {
6+
const legacyUsageCounts = {
57
insert: 0,
6-
update: 0,
7-
remove: 0
8+
update: 0
9+
};
10+
11+
const legacyUsageMaximums = {
12+
insert: 326,
13+
update: 19
814
};
915

1016
// @ts-expect-error: Method no longer exists on Collection
1117
Collection.prototype.insert = function (docs, options, callback) {
12-
counts.insert += 1;
18+
legacyUsageCounts.insert += 1;
1319
callback =
1420
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined;
1521
options = options != null && typeof options === 'object' ? options : { ordered: false };
@@ -21,14 +27,25 @@ Collection.prototype.insert = function (docs, options, callback) {
2127

2228
// @ts-expect-error: Method no longer exists on Collection
2329
Collection.prototype.update = function (filter, update, options, callback) {
24-
counts.update += 1;
30+
legacyUsageCounts.update += 1;
2531
callback =
2632
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined;
2733
options = options != null && typeof options === 'object' ? options : {};
2834

2935
return this.updateMany(filter, update, options, callback);
3036
};
3137

32-
process.on('beforeExit', () => {
33-
console.dir(counts);
34-
});
38+
function assertLegacyAPIUsageDoesNotIncrease() {
39+
expect(
40+
legacyUsageCounts.insert,
41+
'Please do not use more instance of the legacy CRUD API: insert'
42+
).is.lessThanOrEqual(legacyUsageMaximums.insert);
43+
expect(
44+
legacyUsageCounts.update,
45+
'Please do not use more instance of the legacy CRUD API: update'
46+
).is.lessThanOrEqual(legacyUsageMaximums.update);
47+
}
48+
49+
export const mochaHooks = {
50+
afterAll: [assertLegacyAPIUsageDoesNotIncrease]
51+
};

0 commit comments

Comments
 (0)