Skip to content

Commit 665e040

Browse files
create collection
1 parent d0a7562 commit 665e040

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

test/integration/crud/crud.prose.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { expect } from 'chai';
22
import { once } from 'events';
33

44
import { type CommandStartedEvent } from '../../../mongodb';
5-
import { MongoBulkWriteError, type MongoClient, MongoServerError } from '../../mongodb';
5+
import {
6+
type Collection,
7+
MongoBulkWriteError,
8+
type MongoClient,
9+
MongoServerError
10+
} from '../../mongodb';
611
import { filterForCommands } from '../shared';
712

813
describe('CRUD Prose Spec Tests', () => {
@@ -149,11 +154,14 @@ describe('CRUD Prose Spec Tests', () => {
149154
describe('14. `explain` helpers allow users to specify `maxTimeMS`', function () {
150155
let client: MongoClient;
151156
const commands: CommandStartedEvent[] = [];
157+
let collection: Collection;
152158

153159
beforeEach(async function () {
154160
client = this.configuration.newClient({}, { monitorCommands: true });
155161
await client.connect();
156162

163+
collection = await client.db('explain-test').createCollection('collection');
164+
157165
client.on('commandStarted', filterForCommands('explain', commands));
158166
commands.length = 0;
159167
});
@@ -163,9 +171,6 @@ describe('CRUD Prose Spec Tests', () => {
163171
});
164172

165173
it('sets maxTimeMS on explain commands, when specfied', async function () {
166-
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
167-
const collection = client.db('explain-test').collection('collection');
168-
169174
await collection
170175
.find(
171176
{ name: 'john doe' },

test/integration/crud/explain.test.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ describe('CRUD API explain option', function () {
123123
describe('explain helpers w/ maxTimeMS', function () {
124124
let client: MongoClient;
125125
const commands: CommandStartedEvent[] = [];
126+
let collection: Collection;
126127

127128
beforeEach(async function () {
128129
client = this.configuration.newClient({}, { monitorCommands: true });
129130
await client.connect();
130131

132+
collection = await client.db('explain-test').createCollection('bar');
133+
131134
client.on('commandStarted', filterForCommands('explain', commands));
132135
commands.length = 0;
133136
});
@@ -139,7 +142,6 @@ describe('CRUD API explain option', function () {
139142
describe('cursor explain commands', function () {
140143
describe('when maxTimeMS is specified via a cursor explain method, it sets the property on the command', function () {
141144
test('find()', async function () {
142-
const collection = client.db('explain-test').collection('collection');
143145
await collection
144146
.find({ name: 'john doe' })
145147
.explain({ maxTimeMS: 2000, verbosity: 'queryPlanner' });
@@ -149,8 +151,6 @@ describe('CRUD API explain option', function () {
149151
});
150152

151153
test('aggregate()', async function () {
152-
const collection = client.db('explain-test').collection('collection');
153-
154154
await collection
155155
.aggregate([{ $match: { name: 'john doe' } }])
156156
.explain({ maxTimeMS: 2000, verbosity: 'queryPlanner' });
@@ -161,19 +161,13 @@ describe('CRUD API explain option', function () {
161161
});
162162

163163
it('when maxTimeMS is not specified, it is not attached to the explain command', async function () {
164-
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
165-
const collection = client.db('explain-test').collection('collection');
166-
167164
await collection.find({ name: 'john doe' }).explain({ verbosity: 'queryPlanner' });
168165

169166
const [{ command }] = commands;
170167
expect(command).not.to.have.property('maxTimeMS');
171168
});
172169

173170
it('when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence', async function () {
174-
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
175-
const collection = client.db('explain-test').collection('collection');
176-
177171
await collection
178172
.find(
179173
{},
@@ -194,15 +188,12 @@ describe('CRUD API explain option', function () {
194188

195189
describe('regular commands w/ explain', function () {
196190
it('when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence', async function () {
197-
// Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
198-
const collection = client.db('explain-test').collection('collection');
199-
200191
await collection.deleteMany(
201192
{},
202193
{
203194
maxTimeMS: 1000,
204195
explain: {
205-
verbosity: true,
196+
verbosity: 'queryPlanner',
206197
maxTimeMS: 2000
207198
}
208199
}
@@ -214,7 +205,6 @@ describe('CRUD API explain option', function () {
214205

215206
describe('when maxTimeMS is specified as an explain option', function () {
216207
it('attaches maxTimeMS to the explain command', async function () {
217-
const collection = client.db('explain-test').collection('collection');
218208
await collection.deleteMany(
219209
{},
220210
{ explain: { maxTimeMS: 2000, verbosity: 'queryPlanner' } }
@@ -226,8 +216,6 @@ describe('CRUD API explain option', function () {
226216
});
227217

228218
it('when maxTimeMS is not specified, it is not attached to the explain command', async function () {
229-
const collection = client.db('explain-test').collection('collection');
230-
231219
await collection.deleteMany({}, { explain: { verbosity: 'queryPlanner' } });
232220

233221
const [{ command }] = commands;

0 commit comments

Comments
 (0)