@@ -8,8 +8,13 @@ import * as fs from 'fs-extra';
8
8
import * as path from 'path' ;
9
9
import { SemVer } from 'semver' ;
10
10
import * 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' ;
13
18
import { EXTENSION_ROOT_DIR , PYTHON_LANGUAGE } from '../../../client/common/constants' ;
14
19
import '../../../client/common/extensions' ;
15
20
import { ProcessService } from '../../../client/common/process/proc' ;
@@ -38,6 +43,7 @@ suite('Terminal - Code Execution Helper', () => {
38
43
let processService : TypeMoq . IMock < IProcessService > ;
39
44
let interpreterService : TypeMoq . IMock < IInterpreterService > ;
40
45
let commandManager : TypeMoq . IMock < ICommandManager > ;
46
+ let workspaceService : TypeMoq . IMock < IWorkspaceService > ;
41
47
const workingPython : PythonEnvironment = {
42
48
path : PYTHON_PATH ,
43
49
version : new SemVer ( '3.6.6-final' ) ,
@@ -51,6 +57,7 @@ suite('Terminal - Code Execution Helper', () => {
51
57
setup ( ( ) => {
52
58
const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
53
59
commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
60
+ workspaceService = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
54
61
documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
55
62
applicationShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
56
63
const envVariablesProvider = TypeMoq . Mock . ofType < IEnvironmentVariablesProvider > ( ) ;
@@ -69,6 +76,9 @@ suite('Terminal - Code Execution Helper', () => {
69
76
envVariablesProvider
70
77
. setup ( ( e ) => e . getEnvironmentVariables ( TypeMoq . It . isAny ( ) ) )
71
78
. returns ( ( ) => Promise . resolve ( { } ) ) ;
79
+ serviceContainer
80
+ . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IWorkspaceService ) ) )
81
+ . returns ( ( ) => workspaceService . object ) ;
72
82
serviceContainer
73
83
. setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IProcessServiceFactory ) , TypeMoq . It . isAny ( ) ) )
74
84
. returns ( ( ) => processServiceFactory . object ) ;
@@ -367,20 +377,13 @@ suite('Terminal - Code Execution Helper', () => {
367
377
. setup ( ( d ) => d . textDocuments )
368
378
. returns ( ( ) => [ document . object ] )
369
379
. verifiable ( TypeMoq . Times . once ( ) ) ;
370
- const saveEmitter = new EventEmitter < TextDocument > ( ) ;
371
- documentManager . setup ( ( d ) => d . onDidSaveTextDocument ) . returns ( ( ) => saveEmitter . event ) ;
372
380
document . setup ( ( doc ) => doc . isUntitled ) . returns ( ( ) => true ) ;
373
381
document . setup ( ( doc ) => doc . isDirty ) . returns ( ( ) => true ) ;
374
382
document . setup ( ( doc ) => doc . languageId ) . returns ( ( ) => PYTHON_LANGUAGE ) ;
375
383
const untitledUri = Uri . file ( 'Untitled-1' ) ;
376
384
document . setup ( ( doc ) => doc . uri ) . returns ( ( ) => untitledUri ) ;
377
- const savedDocument = TypeMoq . Mock . ofType < TextDocument > ( ) ;
378
385
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 ) ) ;
384
387
385
388
const savedUri = await helper . saveFileIfDirty ( untitledUri ) ;
386
389
0 commit comments