@@ -8,8 +8,13 @@ import * as fs from 'fs-extra';
88import * as path from 'path' ;
99import { SemVer } from 'semver' ;
1010import * as TypeMoq from 'typemoq' ;
11- import { EventEmitter , Position , Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
12- import { IApplicationShell , ICommandManager , IDocumentManager } from '../../../client/common/application/types' ;
11+ import { Position , Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
12+ import {
13+ IApplicationShell ,
14+ ICommandManager ,
15+ IDocumentManager ,
16+ IWorkspaceService ,
17+ } from '../../../client/common/application/types' ;
1318import { EXTENSION_ROOT_DIR , PYTHON_LANGUAGE } from '../../../client/common/constants' ;
1419import '../../../client/common/extensions' ;
1520import { ProcessService } from '../../../client/common/process/proc' ;
@@ -38,6 +43,7 @@ suite('Terminal - Code Execution Helper', () => {
3843 let processService : TypeMoq . IMock < IProcessService > ;
3944 let interpreterService : TypeMoq . IMock < IInterpreterService > ;
4045 let commandManager : TypeMoq . IMock < ICommandManager > ;
46+ let workspaceService : TypeMoq . IMock < IWorkspaceService > ;
4147 const workingPython : PythonEnvironment = {
4248 path : PYTHON_PATH ,
4349 version : new SemVer ( '3.6.6-final' ) ,
@@ -51,6 +57,7 @@ suite('Terminal - Code Execution Helper', () => {
5157 setup ( ( ) => {
5258 const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
5359 commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
60+ workspaceService = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
5461 documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
5562 applicationShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
5663 const envVariablesProvider = TypeMoq . Mock . ofType < IEnvironmentVariablesProvider > ( ) ;
@@ -69,6 +76,9 @@ suite('Terminal - Code Execution Helper', () => {
6976 envVariablesProvider
7077 . setup ( ( e ) => e . getEnvironmentVariables ( TypeMoq . It . isAny ( ) ) )
7178 . returns ( ( ) => Promise . resolve ( { } ) ) ;
79+ serviceContainer
80+ . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IWorkspaceService ) ) )
81+ . returns ( ( ) => workspaceService . object ) ;
7282 serviceContainer
7383 . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IProcessServiceFactory ) , TypeMoq . It . isAny ( ) ) )
7484 . returns ( ( ) => processServiceFactory . object ) ;
@@ -367,20 +377,13 @@ suite('Terminal - Code Execution Helper', () => {
367377 . setup ( ( d ) => d . textDocuments )
368378 . returns ( ( ) => [ document . object ] )
369379 . verifiable ( TypeMoq . Times . once ( ) ) ;
370- const saveEmitter = new EventEmitter < TextDocument > ( ) ;
371- documentManager . setup ( ( d ) => d . onDidSaveTextDocument ) . returns ( ( ) => saveEmitter . event ) ;
372380 document . setup ( ( doc ) => doc . isUntitled ) . returns ( ( ) => true ) ;
373381 document . setup ( ( doc ) => doc . isDirty ) . returns ( ( ) => true ) ;
374382 document . setup ( ( doc ) => doc . languageId ) . returns ( ( ) => PYTHON_LANGUAGE ) ;
375383 const untitledUri = Uri . file ( 'Untitled-1' ) ;
376384 document . setup ( ( doc ) => doc . uri ) . returns ( ( ) => untitledUri ) ;
377- const savedDocument = TypeMoq . Mock . ofType < TextDocument > ( ) ;
378385 const expectedSavedUri = Uri . file ( 'one.py' ) ;
379- savedDocument . setup ( ( doc ) => doc . uri ) . returns ( ( ) => expectedSavedUri ) ;
380- commandManager
381- . setup ( ( c ) => c . executeCommand ( 'workbench.action.files.save' , untitledUri ) )
382- . callback ( ( ) => saveEmitter . fire ( savedDocument . object ) )
383- . returns ( ( ) => Promise . resolve ( ) ) ;
386+ workspaceService . setup ( ( w ) => w . saveAs ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => Promise . resolve ( expectedSavedUri ) ) ;
384387
385388 const savedUri = await helper . saveFileIfDirty ( untitledUri ) ;
386389
0 commit comments