Skip to content

Commit

Permalink
fixup: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Mar 28, 2024
1 parent 48f39f5 commit df73374
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 7 additions & 1 deletion packages/shell-api/src/abstract-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ export abstract class AbstractCursor<

@returnsPromise
async toArray(): Promise<Document[]> {
if (this._canDelegateIterationToUnderlyingCursor())
// toArray is always defined for driver cursors, but not necessarily
// in tests
if (
typeof this._cursor.toArray === 'function' &&
this._canDelegateIterationToUnderlyingCursor()
) {
return await this._cursor.toArray();
}

const result = [];
for await (const doc of this) {
Expand Down
5 changes: 2 additions & 3 deletions packages/shell-api/src/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
const sinonChai = require('sinon-chai'); // weird with import

use(sinonChai);
describe('Collection', function () {
describe.only('Collection', function () {
describe('help', function () {
const apiClass = new Collection({} as any, {} as any, 'name');
it('calls help function', async function () {
Expand Down Expand Up @@ -209,8 +209,7 @@ describe('Collection', function () {

it('returns an AggregationCursor that wraps the service provider one', async function () {
const toArrayResult = [{ foo: 'bar' }];
serviceProviderCursor.tryNext.onFirstCall().resolves({ foo: 'bar' });
serviceProviderCursor.tryNext.onSecondCall().resolves(null);
serviceProviderCursor.toArray.resolves(toArrayResult);
serviceProvider.aggregate.returns(serviceProviderCursor);

const cursor = await collection.aggregate([
Expand Down
5 changes: 2 additions & 3 deletions packages/shell-api/src/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type { MongoServerError } from 'mongodb';

chai.use(sinonChai);

describe('Database', function () {
describe.only('Database', function () {
const MD5_HASH = crypto
.createHash('md5')
.update('anna:mongo:pwd')
Expand Down Expand Up @@ -415,8 +415,7 @@ describe('Database', function () {

it('returns an AggregationCursor that wraps the service provider one', async function () {
const toArrayResult = [{ foo: 'bar' }];
serviceProviderCursor.tryNext.onFirstCall().resolves({ foo: 'bar' });
serviceProviderCursor.tryNext.onSecondCall().resolves(null);
serviceProviderCursor.toArray.resolves(toArrayResult);
serviceProvider.aggregateDb.returns(serviceProviderCursor);

const cursor = await database.aggregate([{ $piplelineStage: {} }]);
Expand Down

0 comments on commit df73374

Please sign in to comment.