Skip to content

Commit 6e371ad

Browse files
address PR comments
1 parent bf9e916 commit 6e371ad

File tree

2 files changed

+40
-70
lines changed

2 files changed

+40
-70
lines changed

test/integration/crud/misc_cursors.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,9 +3585,6 @@ describe('Cursor', function () {
35853585
});
35863586

35873587
it('should return implicit session to pool when client-side cursor exhausts results after a getMore', async function () {
3588-
const configuration = this.configuration;
3589-
const client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
3590-
35913588
const db = client.db(configuration.db);
35923589
const collection = db.collection('cursor_session_tests2');
35933590

@@ -3613,7 +3610,6 @@ describe('Cursor', function () {
36133610
);
36143611

36153612
await cursor.close();
3616-
await client.close();
36173613
});
36183614

36193615
describe('#clone', function () {

test/integration/node-specific/abstract_cursor.test.ts

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -57,99 +57,73 @@ describe('class AbstractCursor', function () {
5757
await client.close();
5858
});
5959

60-
describe('tryNext()', function () {
60+
context(`hasNext()`, function () {
6161
context('when there is a transform on the cursor', function () {
62-
it('does not transform any documents', async function () {
62+
it(`the transform is NOT called`, async () => {
6363
const cursor = collection.find().map(transformSpy);
6464

65-
await cursor.hasNext();
66-
expect(transformSpy.called).to.be.false;
65+
const hasNext = await cursor.hasNext();
66+
expect(transformSpy).not.to.have.been.called;
67+
expect(hasNext).to.be.true;
6768
});
6869
});
6970
});
7071

7172
const operations: ReadonlyArray<readonly [string, (arg0: FindCursor) => Promise<unknown>]> = [
7273
[
7374
'tryNext',
74-
(cursor: FindCursor) => {
75-
return cursor.tryNext();
76-
}
75+
(cursor: FindCursor) => cursor.tryNext()
7776
],
7877
['next', (cursor: FindCursor) => cursor.next()],
7978
[
8079
'Symbol.asyncIterator().next',
8180
async (cursor: FindCursor) => {
8281
const iterator = cursor[Symbol.asyncIterator]();
83-
const doc = await iterator.next();
84-
return doc.value;
82+
return iterator.next().then(({ value }) => value);
8583
}
86-
]
84+
],
85+
['Cursor.stream', (cursor: FindCursor) => {
86+
const stream = cursor.stream();
87+
return once(stream, 'data').then(([doc]) => doc)
88+
}]
8789
] as const;
8890

89-
context('when there is a transform on the cursor', function () {
90-
for (const [method, func] of operations) {
91-
it(`${method}() calls the cursor transform when iterated`, async () => {
92-
const cursor = collection.find().map(transformSpy);
93-
94-
const doc = await func(cursor);
95-
expect(transformSpy).to.have.been.calledOnce;
96-
expect(doc.name).to.equal('JOHN DOE');
97-
});
91+
for (const [method, func] of operations) {
92+
context(`${method}()`, function () {
93+
context('when there is a transform on the cursor', function () {
94+
it(`the transform is called`, async () => {
95+
const cursor = collection.find().map(transformSpy);
9896

99-
it(`when the transform throws, ${method}() propagates the error to the user`, async () => {
100-
const cursor = collection.find().map(() => {
101-
throw new Error('error thrown in transform');
97+
const doc = await func(cursor);
98+
expect(transformSpy).to.have.been.calledOnce;
99+
expect(doc.name).to.equal('JOHN DOE');
102100
});
103-
104-
const error = await func(cursor).catch(e => e);
105-
expect(error)
106-
.to.be.instanceOf(Error)
107-
.to.match(/error thrown in transform/);
108-
expect(cursor.closed).to.be.true;
109-
});
110-
}
111-
112-
it('Cursor.stream() calls the cursor transform when iterated', async function () {
113-
const cursor = collection.find().map(transformSpy).stream();
114-
115-
const [doc] = await once(cursor, 'data');
116-
expect(transformSpy).to.have.been.calledOnce;
117-
expect(doc.name).to.equal('JOHN DOE');
118-
});
119-
120-
it(`when the transform throws, Cursor.stream() propagates the error to the user`, async () => {
121-
const cursor = collection
122-
.find()
123-
.map(() => {
124-
throw new Error('error thrown in transform');
101+
context('when the transform throws', function () {
102+
it(`the error is propagated to the user`, async () => {
103+
const cursor = collection.find().map(() => {
104+
throw new Error('error thrown in transform');
105+
});
106+
107+
const error = await func(cursor).catch(e => e);
108+
expect(error)
109+
.to.be.instanceOf(Error)
110+
.to.match(/error thrown in transform/);
111+
expect(cursor.closed).to.be.true;
112+
});
125113
})
126-
.stream();
114+
});
127115

128-
const error = await once(cursor, 'data').catch(e => e);
129-
expect(error)
130-
.to.be.instanceOf(Error)
131-
.to.match(/error thrown in transform/);
132-
expect(cursor._cursor).to.have.property('closed', true);
133-
});
134-
});
116+
context('when there is not a transform on the cursor', function () {
117+
it(`it returns the cursor's documents unmodified`, async () => {
118+
const cursor = collection.find();
135119

136-
context('when there is not a transform on the cursor', function () {
137-
for (const [method, func] of operations) {
138-
it(`${method}() returns the documents, unmodified`, async () => {
139-
const cursor = collection.find();
140-
141-
const doc = await func(cursor);
142-
expect(doc.name).to.equal('john doe');
120+
const doc = await func(cursor);
121+
expect(doc.name).to.equal('john doe');
122+
});
143123
});
144-
}
145124

146-
it('Cursor.stream() returns the documents, unmodified', async function () {
147-
const cursor = collection.find().stream();
148-
149-
const [doc] = await once(cursor, 'data');
150-
expect(doc.name).to.equal('john doe');
151125
});
152-
});
126+
}
153127
});
154128

155129
describe('custom transforms with falsy values', function () {

0 commit comments

Comments
 (0)