Skip to content

Commit bf5ff15

Browse files
committed
test(NODE-7204): migrate to typescript
1 parent e1ea14c commit bf5ff15

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

test/integration/node-specific/cursor_stream.test.js renamed to test/integration/node-specific/cursor_stream.test.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
'use strict';
2-
const { expect } = require('chai');
3-
const { Binary } = require('../../mongodb');
4-
const { setTimeout, setImmediate } = require('timers');
1+
import { setImmediate, setTimeout } from 'node:timers';
2+
3+
import { expect } from 'chai';
4+
5+
import { Binary, type MongoClient } from '../../mongodb';
56

67
describe('Cursor Streams', function () {
7-
let client;
8+
let client: MongoClient;
89

910
beforeEach(async function () {
1011
client = this.configuration.newClient();
@@ -20,39 +21,39 @@ describe('Cursor Streams', function () {
2021
},
2122

2223
test: function (done) {
23-
var self = this;
24-
var docs = [];
25-
var j = 0;
24+
const self = this;
25+
const docs = [];
26+
let j = 0;
2627

27-
for (var i = 0; i < 3000; i++) {
28+
for (let i = 0; i < 3000; i++) {
2829
docs.push({ a: i });
2930
}
3031

31-
var allDocs = [];
32+
const allDocs = [];
3233
while (docs.length > 0) {
3334
allDocs.push(docs.splice(0, 1000));
3435
}
3536

36-
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
37+
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
3738
maxPoolSize: 1
3839
});
3940

4041
client.connect(function (err, client) {
41-
var db = client.db(self.configuration.db);
42+
const db = client.db(self.configuration.db);
4243
db.createCollection(
4344
'test_streaming_function_with_limit_for_fetching2',
4445
function (err, collection) {
45-
var left = allDocs.length;
46-
for (var i = 0; i < allDocs.length; i++) {
46+
let left = allDocs.length;
47+
for (let i = 0; i < allDocs.length; i++) {
4748
collection.insert(allDocs[i], { writeConcern: { w: 1 } }, function (err) {
4849
expect(err).to.not.exist;
4950

5051
left = left - 1;
5152

5253
if (left === 0) {
5354
// Perform a find to get a cursor
54-
var stream = collection.find({}).stream();
55-
var data = [];
55+
const stream = collection.find({}).stream();
56+
const data = [];
5657

5758
// For each data item
5859
stream.on('data', function () {
@@ -94,39 +95,39 @@ describe('Cursor Streams', function () {
9495
},
9596

9697
test: function (done) {
97-
var self = this;
98-
var docs = [];
98+
const self = this;
99+
const docs = [];
99100

100-
for (var i = 0; i < 10000; i++) {
101+
for (let i = 0; i < 10000; i++) {
101102
docs.push({ a: i, bin: new Binary(Buffer.alloc(256)) });
102103
}
103104

104-
var j = 0;
105+
let j = 0;
105106

106-
var allDocs = [];
107+
const allDocs = [];
107108
while (docs.length > 0) {
108109
allDocs.push(docs.splice(0, 1000));
109110
}
110111

111-
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
112+
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
112113
maxPoolSize: 1
113114
});
114115

115116
client.connect(function (err, client) {
116-
var db = client.db(self.configuration.db);
117+
const db = client.db(self.configuration.db);
117118
db.createCollection(
118119
'test_streaming_function_with_limit_for_fetching_2',
119120
function (err, collection) {
120-
var left = allDocs.length;
121-
for (var i = 0; i < allDocs.length; i++) {
121+
let left = allDocs.length;
122+
for (let i = 0; i < allDocs.length; i++) {
122123
collection.insert(allDocs[i], { writeConcern: { w: 1 } }, function (err) {
123124
expect(err).to.not.exist;
124125
left = left - 1;
125126

126127
if (left === 0) {
127128
// Perform a find to get a cursor
128-
var stream = collection.find({}).stream();
129-
var data = [];
129+
const stream = collection.find({}).stream();
130+
const data = [];
130131

131132
// For each data item
132133
stream.on('data', function () {
@@ -168,29 +169,29 @@ describe('Cursor Streams', function () {
168169
},
169170

170171
test: function (done) {
171-
var self = this;
172-
var docs = [];
173-
var counter = 0;
174-
var counter2 = 0;
172+
const self = this;
173+
const docs = [];
174+
let counter = 0;
175+
let counter2 = 0;
175176

176-
for (var i = 0; i < 1000; i++) {
177+
for (let i = 0; i < 1000; i++) {
177178
docs.push({ a: i, bin: new Binary(Buffer.alloc(256)) });
178179
}
179180

180-
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
181+
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
181182
maxPoolSize: 1
182183
});
183184

184185
client.connect(function (err, client) {
185-
var db = client.db(self.configuration.db);
186+
const db = client.db(self.configuration.db);
186187
db.createCollection(
187188
'test_streaming_function_with_limit_for_fetching_3',
188189
function (err, collection) {
189190
collection.insert(docs, { writeConcern: { w: 1 } }, function (err) {
190191
expect(err).to.not.exist;
191192

192193
// Perform a find to get a cursor
193-
var stream = collection.find({}).stream();
194+
const stream = collection.find({}).stream();
194195

195196
// For each data item
196197
stream.on('data', function () {
@@ -282,8 +283,8 @@ describe('Cursor Streams', function () {
282283
},
283284

284285
test: function (done) {
285-
var self = this;
286-
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
286+
const self = this;
287+
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
287288
maxPoolSize: 1
288289
});
289290

@@ -314,24 +315,24 @@ describe('Cursor Streams', function () {
314315
},
315316

316317
test: function (done) {
317-
var self = this;
318-
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
318+
const self = this;
319+
const client = self.configuration.newClient(self.configuration.writeConcernMax(), {
319320
maxPoolSize: 1
320321
});
321322

322323
client.connect(function (err, client) {
323-
var db = client.db(self.configuration.db);
324-
var docs = [];
325-
var received = [];
324+
const db = client.db(self.configuration.db);
325+
const docs = [];
326+
const received = [];
326327

327-
for (var i = 0; i < 1000; i++) {
328+
for (let i = 0; i < 1000; i++) {
328329
docs.push({ a: i, field: 'hello world' });
329330
}
330331

331332
db.collection('cursor_sort_stream').insertMany(docs, function (err) {
332333
expect(err).to.not.exist;
333334

334-
var cursor = db
335+
const cursor = db
335336
.collection('cursor_sort_stream')
336337
.find({})
337338
.project({ a: 1 })

0 commit comments

Comments
 (0)