@@ -10,7 +10,8 @@ import {
10
10
import type { CompletionItem } from 'vscode-languageclient/node' ;
11
11
import chai from 'chai' ;
12
12
import { createConnection } from 'vscode-languageserver/node' ;
13
- import fs from 'fs' ;
13
+ import fs from 'fs/promises' ;
14
+ import os from 'os' ;
14
15
import path from 'path' ;
15
16
import { TextDocument } from 'vscode-languageserver-textdocument' ;
16
17
import type { Db } from 'mongodb' ;
@@ -45,7 +46,7 @@ suite('MongoDBService Test Suite', () => {
45
46
'dist' ,
46
47
languageServerWorkerFileName
47
48
) ;
48
- await fs . promises . stat ( languageServerModuleBundlePath ) ;
49
+ await fs . stat ( languageServerModuleBundlePath ) ;
49
50
} ) ;
50
51
51
52
suite ( 'Extension path' , ( ) => {
@@ -3008,6 +3009,44 @@ suite('MongoDBService Test Suite', () => {
3008
3009
expect ( result ) . to . deep . equal ( expectedResult ) ;
3009
3010
} ) ;
3010
3011
} ) ;
3012
+
3013
+ suite ( 'evaluate allows to import local files' , function ( ) {
3014
+ let tmpDir : string ;
3015
+ beforeEach ( async ( ) => {
3016
+ tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'local-import' ) ) ;
3017
+ await fs . writeFile (
3018
+ path . join ( tmpDir , 'utils.js' ) ,
3019
+ `module.exports.add = function (a, b) {
3020
+ return a + b;
3021
+ };
3022
+ `
3023
+ ) ;
3024
+ } ) ;
3025
+ afterEach ( async ( ) => {
3026
+ await fs . rm ( tmpDir , { recursive : true } ) ;
3027
+ } ) ;
3028
+ test ( 'evaluate allows to import file' , async ( ) => {
3029
+ const source = new CancellationTokenSource ( ) ;
3030
+ const result = await testMongoDBService . evaluate (
3031
+ {
3032
+ connectionId : 'pineapple' ,
3033
+ codeToEvaluate : 'const { add } = require("./utils.js"); add(1, 2);' ,
3034
+ filePath : path . join ( tmpDir , 'utils.js' ) ,
3035
+ } ,
3036
+ source . token
3037
+ ) ;
3038
+ const expectedResult = {
3039
+ result : {
3040
+ namespace : null ,
3041
+ type : 'number' ,
3042
+ content : 3 ,
3043
+ language : 'plaintext' ,
3044
+ } ,
3045
+ } ;
3046
+
3047
+ expect ( result ) . to . deep . equal ( expectedResult ) ;
3048
+ } ) ;
3049
+ } ) ;
3011
3050
} ) ;
3012
3051
3013
3052
suite ( 'Export to language mode' , function ( ) {
0 commit comments