@@ -3,6 +3,7 @@ import { MongoDBAutocompleter } from './index';
33import type { AutocompletionContext } from './autocompletion-context' ;
44import { analyzeDocuments } from 'mongodb-schema' ;
55import { expect } from 'chai' ;
6+ import { relativeNodePath } from '@mongodb-js/ts-autocomplete' ;
67
78/*
89This is intended as deliberately diabolical database and collection names to
@@ -25,6 +26,7 @@ describe('MongoDBAutocompleter', function () {
2526 let fallbackServiceHost : ts . LanguageServiceHost ;
2627 let autocompleterContext : AutocompletionContext ;
2728 let autocompleter : MongoDBAutocompleter ;
29+ let autocompleterWithFallback : MongoDBAutocompleter ;
2830 let encounteredPaths : EncounteredPaths ;
2931
3032 beforeEach ( function ( ) {
@@ -51,19 +53,19 @@ describe('MongoDBAutocompleter', function () {
5153 ts . sys . readFile ( fileName ) || '' ,
5254 ) ;
5355
54- encounteredPaths . getScriptSnapshot . push ( fileName ) ;
56+ encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
5557 return result ;
5658 } ,
5759 fileExists : ( fileName : string ) => {
5860 const result = ts . sys . fileExists ( fileName ) ;
5961 if ( result ) {
60- encounteredPaths . fileExists . push ( fileName ) ;
62+ encounteredPaths . fileExists . push ( relativeNodePath ( fileName ) ) ;
6163 }
6264 return result ;
6365 } ,
6466 readFile : ( fileName : string ) => {
6567 const result = ts . sys . readFile ( fileName ) ;
66- encounteredPaths . readFile . push ( fileName ) ;
68+ encounteredPaths . readFile . push ( relativeNodePath ( fileName ) ) ;
6769 return result ;
6870 } ,
6971 readDirectory : ( ...args ) => {
@@ -126,11 +128,21 @@ describe('MongoDBAutocompleter', function () {
126128
127129 autocompleter = new MongoDBAutocompleter ( {
128130 context : autocompleterContext ,
131+ } ) ;
132+
133+ autocompleterWithFallback = new MongoDBAutocompleter ( {
134+ context : autocompleterContext ,
129135 fallbackServiceHost,
130136 } ) ;
131137 } ) ;
132138
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+
134146 // this is what tells us what we're missing in extract-types.ts
135147 expect ( encounteredPaths ) . to . deep . equal ( {
136148 fileExists : [ ] ,
@@ -139,33 +151,6 @@ describe('MongoDBAutocompleter', function () {
139151 } ) ;
140152 } ) ;
141153
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-
169154 it ( 'completes a bson expression' , async function ( ) {
170155 for ( let i = 0 ; i < 2 ; i ++ ) {
171156 const completions = await autocompleter . autocomplete ( 'Ob' ) ;
@@ -285,6 +270,33 @@ describe('MongoDBAutocompleter', function () {
285270 ] ) ;
286271 } ) ;
287272
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+
288300 describe ( 'getConnectionSchemaCode' , function ( ) {
289301 it ( 'generates code for a connection' , async function ( ) {
290302 const docs = [
0 commit comments