1
+ import { expect } from 'chai' ;
2
+
1
3
import { Collection } from '../../../../src' ;
2
4
3
5
// Setup legacy shims for tests that use removed or changed APIs
4
- const counts = {
6
+ const legacyUsageCounts = {
5
7
insert : 0 ,
6
- update : 0 ,
7
- remove : 0
8
+ update : 0
9
+ } ;
10
+
11
+ const legacyUsageMaximums = {
12
+ insert : 326 ,
13
+ update : 19
8
14
} ;
9
15
10
16
// @ts -expect-error: Method no longer exists on Collection
11
17
Collection . prototype . insert = function ( docs , options , callback ) {
12
- counts . insert += 1 ;
18
+ legacyUsageCounts . insert += 1 ;
13
19
callback =
14
20
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined ;
15
21
options = options != null && typeof options === 'object' ? options : { ordered : false } ;
@@ -21,14 +27,25 @@ Collection.prototype.insert = function (docs, options, callback) {
21
27
22
28
// @ts -expect-error: Method no longer exists on Collection
23
29
Collection . prototype . update = function ( filter , update , options , callback ) {
24
- counts . update += 1 ;
30
+ legacyUsageCounts . update += 1 ;
25
31
callback =
26
32
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined ;
27
33
options = options != null && typeof options === 'object' ? options : { } ;
28
34
29
35
return this . updateMany ( filter , update , options , callback ) ;
30
36
} ;
31
37
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