@@ -8,8 +8,8 @@ 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 { Position , Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
12
- import { IApplicationShell , IDocumentManager } from '../../../client/common/application/types' ;
11
+ import { EventEmitter , Position , Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
12
+ import { IApplicationShell , ICommandManager , IDocumentManager } from '../../../client/common/application/types' ;
13
13
import { EXTENSION_ROOT_DIR , PYTHON_LANGUAGE } from '../../../client/common/constants' ;
14
14
import '../../../client/common/extensions' ;
15
15
import { ProcessService } from '../../../client/common/process/proc' ;
@@ -37,6 +37,7 @@ suite('Terminal - Code Execution Helper', () => {
37
37
let editor : TypeMoq . IMock < TextEditor > ;
38
38
let processService : TypeMoq . IMock < IProcessService > ;
39
39
let interpreterService : TypeMoq . IMock < IInterpreterService > ;
40
+ let commandManager : TypeMoq . IMock < ICommandManager > ;
40
41
const workingPython : PythonEnvironment = {
41
42
path : PYTHON_PATH ,
42
43
version : new SemVer ( '3.6.6-final' ) ,
@@ -49,6 +50,7 @@ suite('Terminal - Code Execution Helper', () => {
49
50
50
51
setup ( ( ) => {
51
52
const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
53
+ commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
52
54
documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
53
55
applicationShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
54
56
const envVariablesProvider = TypeMoq . Mock . ofType < IEnvironmentVariablesProvider > ( ) ;
@@ -79,6 +81,7 @@ suite('Terminal - Code Execution Helper', () => {
79
81
serviceContainer
80
82
. setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IApplicationShell ) , TypeMoq . It . isAny ( ) ) )
81
83
. returns ( ( ) => applicationShell . object ) ;
84
+ serviceContainer . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( ICommandManager ) ) ) . returns ( ( ) => commandManager . object ) ;
82
85
serviceContainer
83
86
. setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IEnvironmentVariablesProvider ) , TypeMoq . It . isAny ( ) ) )
84
87
. returns ( ( ) => envVariablesProvider . object ) ;
@@ -364,15 +367,24 @@ suite('Terminal - Code Execution Helper', () => {
364
367
. setup ( ( d ) => d . textDocuments )
365
368
. returns ( ( ) => [ document . object ] )
366
369
. verifiable ( TypeMoq . Times . once ( ) ) ;
367
- document . setup ( ( doc ) => doc . isUntitled ) . returns ( ( ) => false ) ;
370
+ const saveEmitter = new EventEmitter < TextDocument > ( ) ;
371
+ documentManager . setup ( ( d ) => d . onDidSaveTextDocument ) . returns ( ( ) => saveEmitter . event ) ;
372
+ document . setup ( ( doc ) => doc . isUntitled ) . returns ( ( ) => true ) ;
368
373
document . setup ( ( doc ) => doc . isDirty ) . returns ( ( ) => true ) ;
369
374
document . setup ( ( doc ) => doc . languageId ) . returns ( ( ) => PYTHON_LANGUAGE ) ;
370
- const expectedUri = Uri . file ( 'one.py' ) ;
371
- document . setup ( ( doc ) => doc . uri ) . returns ( ( ) => expectedUri ) ;
372
-
373
- await helper . saveFileIfDirty ( expectedUri ) ;
374
- documentManager . verifyAll ( ) ;
375
- document . verify ( ( doc ) => doc . save ( ) , TypeMoq . Times . once ( ) ) ;
375
+ const untitledUri = Uri . file ( 'Untitled-1' ) ;
376
+ document . setup ( ( doc ) => doc . uri ) . returns ( ( ) => untitledUri ) ;
377
+ const savedDocument = TypeMoq . Mock . ofType < TextDocument > ( ) ;
378
+ 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 ( ) ) ;
384
+
385
+ const savedUri = await helper . saveFileIfDirty ( untitledUri ) ;
386
+
387
+ expect ( savedUri ?. fsPath ) . to . be . equal ( expectedSavedUri . fsPath ) ;
376
388
} ) ;
377
389
378
390
test ( 'File will be not saved if file is not dirty' , async ( ) => {
0 commit comments