@@ -162,12 +162,14 @@ describe('Change Streams', function () {
162
162
it ( 'should close the listeners after the cursor is closed' , {
163
163
metadata : { requires : { topology : 'replicaset' } } ,
164
164
async test ( ) {
165
+ const collection = db . collection ( 'closesListeners' ) ;
166
+ const changeStream = collection . watch ( pipeline ) ;
165
167
const willBeChanges = on ( changeStream , 'change' ) ;
166
168
await once ( changeStream . cursor , 'init' ) ;
167
169
await collection . insertOne ( { a : 1 } ) ;
168
170
169
171
await willBeChanges . next ( ) ;
170
- expect ( changeStream . cursorStream . listenerCount ( 'data' ) ) . to . equal ( 1 ) ;
172
+ expect ( changeStream . cursorStream ? .listenerCount ( 'data' ) ) . to . equal ( 1 ) ;
171
173
172
174
await changeStream . close ( ) ;
173
175
expect ( changeStream . cursorStream ) . to . not . exist ;
@@ -1670,7 +1672,7 @@ describe('Change Streams', function () {
1670
1672
it ( 'does not convert Longs to numbers' , {
1671
1673
metadata : { requires : { topology : '!single' } } ,
1672
1674
test : async function ( ) {
1673
- cs = collection . watch ( [ ] , { promoteLongs : true } ) ;
1675
+ cs = collection . watch ( [ ] , { promoteLongs : true , useBigInt64 : false } ) ;
1674
1676
1675
1677
const willBeChange = once ( cs , 'change' ) . then ( args => args [ 0 ] ) ;
1676
1678
await once ( cs . cursor , 'init' ) ;
@@ -1689,7 +1691,7 @@ describe('Change Streams', function () {
1689
1691
it ( 'converts Long values to native numbers' , {
1690
1692
metadata : { requires : { topology : '!single' } } ,
1691
1693
test : async function ( ) {
1692
- cs = collection . watch ( [ ] , { promoteLongs : false } ) ;
1694
+ cs = collection . watch ( [ ] , { promoteLongs : false , useBigInt64 : false } ) ;
1693
1695
1694
1696
const willBeChange = once ( cs , 'change' ) . then ( args => args [ 0 ] ) ;
1695
1697
await once ( cs . cursor , 'init' ) ;
@@ -1707,7 +1709,7 @@ describe('Change Streams', function () {
1707
1709
it ( 'defaults to true' , {
1708
1710
metadata : { requires : { topology : '!single' } } ,
1709
1711
test : async function ( ) {
1710
- cs = collection . watch ( [ ] ) ;
1712
+ cs = collection . watch ( [ ] , { useBigInt64 : false } ) ;
1711
1713
1712
1714
const willBeChange = once ( cs , 'change' ) . then ( args => args [ 0 ] ) ;
1713
1715
await once ( cs . cursor , 'init' ) ;
@@ -1722,6 +1724,60 @@ describe('Change Streams', function () {
1722
1724
} ) ;
1723
1725
} ) ;
1724
1726
1727
+ context ( 'useBigInt64' , ( ) => {
1728
+ const useBigInt64FalseTest = async ( options : ChangeStreamOptions ) => {
1729
+ cs = collection . watch ( [ ] , options ) ;
1730
+ const willBeChange = once ( cs , 'change' ) . then ( args => args [ 0 ] ) ;
1731
+ await once ( cs . cursor , 'init' ) ;
1732
+
1733
+ await collection . insertOne ( { a : Long . fromNumber ( 10 ) } ) ;
1734
+
1735
+ const change = await willBeChange ;
1736
+
1737
+ expect ( typeof change . fullDocument . a ) . to . equal ( 'number' ) ;
1738
+ } ;
1739
+
1740
+ context ( 'when set to false' , function ( ) {
1741
+ it ( 'converts Long to number' , {
1742
+ metadata : {
1743
+ requires : { topology : '!single' }
1744
+ } ,
1745
+ test : async function ( ) {
1746
+ await useBigInt64FalseTest ( { useBigInt64 : false } ) ;
1747
+ }
1748
+ } ) ;
1749
+ } ) ;
1750
+
1751
+ context ( 'when set to true' , function ( ) {
1752
+ it ( 'converts Long to bigint' , {
1753
+ metadata : {
1754
+ requires : { topology : '!single' }
1755
+ } ,
1756
+ test : async function ( ) {
1757
+ cs = collection . watch ( [ ] , { useBigInt64 : true } ) ;
1758
+ const willBeChange = once ( cs , 'change' ) . then ( args => args [ 0 ] ) ;
1759
+ await once ( cs . cursor , 'init' ) ;
1760
+
1761
+ await collection . insertOne ( { a : Long . fromNumber ( 10 ) } ) ;
1762
+
1763
+ const change = await willBeChange ;
1764
+
1765
+ expect ( change . fullDocument ) . property ( 'a' ) . to . be . a ( 'bigint' ) ;
1766
+ expect ( change . fullDocument ) . property ( 'a' , 10n ) ;
1767
+ }
1768
+ } ) ;
1769
+ } ) ;
1770
+
1771
+ context ( 'when unset' , function ( ) {
1772
+ it ( 'defaults to false' , {
1773
+ metadata : { requires : { topology : '!single' } } ,
1774
+ test : async function ( ) {
1775
+ await useBigInt64FalseTest ( { } ) ;
1776
+ }
1777
+ } ) ;
1778
+ } ) ;
1779
+ } ) ;
1780
+
1725
1781
context ( 'invalid options' , function ( ) {
1726
1782
it ( 'does not send invalid options on the aggregate command' , {
1727
1783
metadata : { requires : { topology : '!single' } } ,
0 commit comments