@@ -3,6 +3,7 @@ import { MongoDBAutocompleter } from './index';
3
3
import type { AutocompletionContext } from './autocompletion-context' ;
4
4
import { analyzeDocuments } from 'mongodb-schema' ;
5
5
import { expect } from 'chai' ;
6
+ import { relativeNodePath } from '@mongodb-js/ts-autocomplete' ;
6
7
7
8
/*
8
9
This is intended as deliberately diabolical database and collection names to
@@ -25,6 +26,7 @@ describe('MongoDBAutocompleter', function () {
25
26
let fallbackServiceHost : ts . LanguageServiceHost ;
26
27
let autocompleterContext : AutocompletionContext ;
27
28
let autocompleter : MongoDBAutocompleter ;
29
+ let autocompleterWithFallback : MongoDBAutocompleter ;
28
30
let encounteredPaths : EncounteredPaths ;
29
31
30
32
beforeEach ( function ( ) {
@@ -51,19 +53,19 @@ describe('MongoDBAutocompleter', function () {
51
53
ts . sys . readFile ( fileName ) || '' ,
52
54
) ;
53
55
54
- encounteredPaths . getScriptSnapshot . push ( fileName ) ;
56
+ encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
55
57
return result ;
56
58
} ,
57
59
fileExists : ( fileName : string ) => {
58
60
const result = ts . sys . fileExists ( fileName ) ;
59
61
if ( result ) {
60
- encounteredPaths . fileExists . push ( fileName ) ;
62
+ encounteredPaths . fileExists . push ( relativeNodePath ( fileName ) ) ;
61
63
}
62
64
return result ;
63
65
} ,
64
66
readFile : ( fileName : string ) => {
65
67
const result = ts . sys . readFile ( fileName ) ;
66
- encounteredPaths . readFile . push ( fileName ) ;
68
+ encounteredPaths . readFile . push ( relativeNodePath ( fileName ) ) ;
67
69
return result ;
68
70
} ,
69
71
readDirectory : ( ...args ) => {
@@ -126,11 +128,21 @@ describe('MongoDBAutocompleter', function () {
126
128
127
129
autocompleter = new MongoDBAutocompleter ( {
128
130
context : autocompleterContext ,
131
+ } ) ;
132
+
133
+ autocompleterWithFallback = new MongoDBAutocompleter ( {
134
+ context : autocompleterContext ,
129
135
fallbackServiceHost,
130
136
} ) ;
131
137
} ) ;
132
138
133
- afterEach ( function ( ) {
139
+ it ( 'autocompletes' , async function ( ) {
140
+ await autocompleterWithFallback . autocomplete ( 'db.foo.find({ fo' ) ;
141
+
142
+ encounteredPaths . fileExists . sort ( ) ;
143
+ encounteredPaths . getScriptSnapshot . sort ( ) ;
144
+ encounteredPaths . readFile . sort ( ) ;
145
+
134
146
// this is what tells us what we're missing in extract-types.ts
135
147
expect ( encounteredPaths ) . to . deep . equal ( {
136
148
fileExists : [ ] ,
@@ -139,33 +151,6 @@ describe('MongoDBAutocompleter', function () {
139
151
} ) ;
140
152
} ) ;
141
153
142
- it ( 'deals with no connection' , async function ( ) {
143
- // The body of tests are all wrapped in loops so that we exercise the
144
- // caching logic in the autocompleter.
145
- for ( let i = 0 ; i < 2 ; i ++ ) {
146
- autocompleterContext . currentDatabaseAndConnection = ( ) => {
147
- return undefined ;
148
- } ;
149
-
150
- const completions = await autocompleter . autocomplete ( 'db.' ) ;
151
- expect ( completions ) . to . deep . equal ( [ ] ) ;
152
- }
153
- } ) ;
154
-
155
- it ( 'does not leak the bson package' , async function ( ) {
156
- for ( let i = 0 ; i < 2 ; i ++ ) {
157
- const completions = await autocompleter . autocomplete ( 'bson.' ) ;
158
- expect ( completions ) . to . deep . equal ( [ ] ) ;
159
- }
160
- } ) ;
161
-
162
- it ( 'does not leak the ShellAPI package' , async function ( ) {
163
- for ( let i = 0 ; i < 2 ; i ++ ) {
164
- const completions = await autocompleter . autocomplete ( 'ShellAPI.' ) ;
165
- expect ( completions ) . to . deep . equal ( [ ] ) ;
166
- }
167
- } ) ;
168
-
169
154
it ( 'completes a bson expression' , async function ( ) {
170
155
for ( let i = 0 ; i < 2 ; i ++ ) {
171
156
const completions = await autocompleter . autocomplete ( 'Ob' ) ;
@@ -285,6 +270,33 @@ describe('MongoDBAutocompleter', function () {
285
270
] ) ;
286
271
} ) ;
287
272
273
+ it ( 'deals with no connection' , async function ( ) {
274
+ // The body of tests are all wrapped in loops so that we exercise the
275
+ // caching logic in the autocompleter.
276
+ for ( let i = 0 ; i < 2 ; i ++ ) {
277
+ autocompleterContext . currentDatabaseAndConnection = ( ) => {
278
+ return undefined ;
279
+ } ;
280
+
281
+ const completions = await autocompleter . autocomplete ( 'db.' ) ;
282
+ expect ( completions ) . to . deep . equal ( [ ] ) ;
283
+ }
284
+ } ) ;
285
+
286
+ it ( 'does not leak the bson package' , async function ( ) {
287
+ for ( let i = 0 ; i < 2 ; i ++ ) {
288
+ const completions = await autocompleter . autocomplete ( 'bson.' ) ;
289
+ expect ( completions ) . to . deep . equal ( [ ] ) ;
290
+ }
291
+ } ) ;
292
+
293
+ it ( 'does not leak the ShellAPI package' , async function ( ) {
294
+ for ( let i = 0 ; i < 2 ; i ++ ) {
295
+ const completions = await autocompleter . autocomplete ( 'ShellAPI.' ) ;
296
+ expect ( completions ) . to . deep . equal ( [ ] ) ;
297
+ }
298
+ } ) ;
299
+
288
300
describe ( 'getConnectionSchemaCode' , function ( ) {
289
301
it ( 'generates code for a connection' , async function ( ) {
290
302
const docs = [
0 commit comments