@@ -10,7 +10,8 @@ import {
1010import type { CompletionItem } from 'vscode-languageclient/node' ;
1111import chai from 'chai' ;
1212import { createConnection } from 'vscode-languageserver/node' ;
13- import fs from 'fs' ;
13+ import fs from 'fs/promises' ;
14+ import os from 'os' ;
1415import path from 'path' ;
1516import { TextDocument } from 'vscode-languageserver-textdocument' ;
1617import type { Db } from 'mongodb' ;
@@ -45,7 +46,7 @@ suite('MongoDBService Test Suite', () => {
4546 'dist' ,
4647 languageServerWorkerFileName
4748 ) ;
48- await fs . promises . stat ( languageServerModuleBundlePath ) ;
49+ await fs . stat ( languageServerModuleBundlePath ) ;
4950 } ) ;
5051
5152 suite ( 'Extension path' , ( ) => {
@@ -3008,6 +3009,44 @@ suite('MongoDBService Test Suite', () => {
30083009 expect ( result ) . to . deep . equal ( expectedResult ) ;
30093010 } ) ;
30103011 } ) ;
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+ } ) ;
30113050 } ) ;
30123051
30133052 suite ( 'Export to language mode' , function ( ) {
0 commit comments