44'use strict' ; 
55
66import  {  expect  }  from  'chai' ; 
7+ import  *  as  sinon  from  'sinon' ; 
78import  {  anything ,  instance ,  mock ,  verify ,  when  }  from  'ts-mockito' ; 
9+ import  {  ApplicationEnvironment  }  from  '../../../client/common/application/applicationEnvironment' ; 
10+ import  {  WorkspaceService  }  from  '../../../client/common/application/workspace' ; 
811import  {  PlatformService  }  from  '../../../client/common/platform/platformService' ; 
912import  {  IPlatformService  }  from  '../../../client/common/platform/types' ; 
1013import  {  ShellDetector  }  from  '../../../client/common/terminal/shellDetector' ; 
14+ import  {  SettingsShellDetector  }  from  '../../../client/common/terminal/shellDetectors/settingsShellDetector' ; 
15+ import  {  TerminalNameShellDetector  }  from  '../../../client/common/terminal/shellDetectors/terminalNameShellDetector' ; 
1116import  {  UserEnvironmentShellDetector  }  from  '../../../client/common/terminal/shellDetectors/userEnvironmentShellDetector' ; 
17+ import  {  VSCEnvironmentShellDetector  }  from  '../../../client/common/terminal/shellDetectors/vscEnvironmentShellDetector' ; 
1218import  {  TerminalShellType  }  from  '../../../client/common/terminal/types' ; 
1319import  {  getNamesAndValues  }  from  '../../../client/common/utils/enum' ; 
1420import  {  OSType  }  from  '../../../client/common/utils/platform' ; 
21+ import  {  MockProcess  }  from  '../../../test/mocks/process' ; 
1522
1623// tslint:disable:max-func-body-length no-any 
1724
@@ -23,11 +30,47 @@ suite('Shell Detector', () => {
2330 [ OSType . Windows ] : TerminalShellType . commandPrompt , 
2431 [ OSType . Unknown ] : TerminalShellType . other 
2532 } ; 
26- 
33+   const   sandbox   =   sinon . createSandbox ( ) ; 
2734 setup ( ( )  =>  platformService  =  mock ( PlatformService ) ) ; 
35+  teardown ( ( )  =>  sandbox . restore ( ) ) ; 
2836
2937 getNamesAndValues < OSType > ( OSType ) . forEach ( os  =>  { 
3038 const  testSuffix  =  `(OS ${ os . name }  ; 
39+  test ( 'Test identification of Terminal Shells in order of priority' ,  async  ( )  =>  { 
40+  const  callOrder : string [ ]  =  [ ] ; 
41+  const  nameDetectorIdentify  =  sandbox . stub ( TerminalNameShellDetector . prototype ,  'identify' ) ; 
42+  nameDetectorIdentify . callsFake ( ( )  =>  { 
43+  callOrder . push ( 'calledFirst' ) ; 
44+  return  undefined ; 
45+  } ) ; 
46+  const  vscEnvDetectorIdentify  =  sandbox . stub ( VSCEnvironmentShellDetector . prototype ,  'identify' ) ; 
47+  vscEnvDetectorIdentify . callsFake ( ( )  =>  { 
48+  callOrder . push ( 'calledSecond' ) ; 
49+  return  undefined ; 
50+  } ) ; 
51+  const  userEnvDetectorIdentify  =  sandbox . stub ( UserEnvironmentShellDetector . prototype ,  'identify' ) ; 
52+  userEnvDetectorIdentify . callsFake ( ( )  =>  { 
53+  callOrder . push ( 'calledLast' ) ; 
54+  return  undefined ; 
55+  } ) ; 
56+  const  settingsDetectorIdentify  =  sandbox . stub ( SettingsShellDetector . prototype ,  'identify' ) ; 
57+  settingsDetectorIdentify . callsFake ( ( )  =>  { 
58+  callOrder . push ( 'calledThird' ) ; 
59+  return  undefined ; 
60+  } ) ; 
61+ 
62+  when ( platformService . osType ) . thenReturn ( os . value ) ; 
63+  const  nameDetector  =  new  TerminalNameShellDetector ( ) ; 
64+  const  vscEnvDetector  =  new  VSCEnvironmentShellDetector ( instance ( mock ( ApplicationEnvironment ) ) ) ; 
65+  const  userEnvDetector  =  new  UserEnvironmentShellDetector ( mock ( MockProcess ) ,  instance ( platformService ) ) ; 
66+  const  settingsDetector  =  new  SettingsShellDetector ( instance ( mock ( WorkspaceService ) ) ,  instance ( platformService ) ) ; 
67+  const  detectors  =  [ settingsDetector ,  userEnvDetector ,  nameDetector ,  vscEnvDetector ] ; 
68+  const  shellDetector  =  new  ShellDetector ( instance ( platformService ) ,  detectors ) ; 
69+ 
70+  shellDetector . identifyTerminalShell ( ) ; 
71+ 
72+  expect ( callOrder ) . to . deep . equal ( [ 'calledFirst' ,  'calledSecond' ,  'calledThird' ,  'calledLast' ] ) ; 
73+  } ) ; 
3174 test ( `Use default shell based on OS if there are no shell detectors ${ testSuffix }  ,  ( )  =>  { 
3275 when ( platformService . osType ) . thenReturn ( os . value ) ; 
3376 when ( platformService . osType ) . thenReturn ( os . value ) ; 
0 commit comments