@@ -30,11 +30,18 @@ namespace fakes {
3030 * Indicates whether to include a bare _lib.d.ts_.
3131 */
3232 lib ?: boolean ;
33+ /**
34+ * Indicates whether to use DOS paths by default.
35+ */
36+ dos ?: boolean ;
3337 }
3438
35- export class FakeServerHost implements ts . server . ServerHost , ts . FormatDiagnosticsHost {
39+ export class FakeServerHost implements ts . server . ServerHost , ts . FormatDiagnosticsHost , ts . ModuleResolutionHost {
40+ public static readonly dosExecutingFilePath = "c:/.ts/tsc.js" ;
3641 public static readonly defaultExecutingFilePath = "/.ts/tsc.js" ;
42+ public static readonly dosDefaultCurrentDirectory = "c:/" ;
3743 public static readonly defaultCurrentDirectory = "/" ;
44+ public static readonly dosSafeListPath = "c:/safelist.json" ;
3845 public static readonly safeListPath = "/safelist.json" ;
3946 public static readonly safeListContent =
4047 `{\n` +
@@ -46,6 +53,7 @@ namespace fakes {
4653 ` "chroma": "chroma-js"\n` +
4754 `}` ;
4855
56+ public static readonly dosLibPath = "c:/.ts/lib.d.ts" ;
4957 public static readonly libPath = "/.ts/lib.d.ts" ;
5058 public static readonly libContent =
5159 `/// <reference no-default-lib="true"/>\n` +
@@ -64,34 +72,48 @@ namespace fakes {
6472
6573 private static readonly processExitSentinel = new Error ( "System exit" ) ;
6674 private readonly _output : string [ ] = [ ] ;
75+ private readonly _trace : string [ ] = [ ] ;
6776 private readonly _executingFilePath : string ;
6877 private readonly _getCanonicalFileName : ( file : string ) => string ;
6978
7079 constructor ( options : FakeServerHostOptions = { } ) {
7180 const {
81+ dos = false ,
7282 vfs : _vfs = { } ,
73- executingFilePath = FakeServerHost . defaultExecutingFilePath ,
83+ executingFilePath = dos
84+ ? FakeServerHost . dosExecutingFilePath
85+ : FakeServerHost . defaultExecutingFilePath ,
7486 newLine = "\n" ,
7587 safeList = false ,
7688 lib = false
7789 } = options ;
7890
79- const { currentDirectory = FakeServerHost . defaultCurrentDirectory , useCaseSensitiveFileNames = false } = _vfs ;
91+ const {
92+ currentDirectory = dos
93+ ? FakeServerHost . dosDefaultCurrentDirectory
94+ : FakeServerHost . defaultCurrentDirectory ,
95+ useCaseSensitiveFileNames = false
96+ } = _vfs ;
8097
81- this . vfs = _vfs instanceof vfs . VirtualFileSystem ? _vfs :
82- new vfs . VirtualFileSystem ( currentDirectory , useCaseSensitiveFileNames ) ;
98+ this . vfs = _vfs instanceof vfs . VirtualFileSystem
99+ ? _vfs
100+ : new vfs . VirtualFileSystem ( currentDirectory , useCaseSensitiveFileNames ) ;
83101
84102 this . useCaseSensitiveFileNames = this . vfs . useCaseSensitiveFileNames ;
85103 this . newLine = newLine ;
86104 this . _executingFilePath = executingFilePath ;
87105 this . _getCanonicalFileName = ts . createGetCanonicalFileName ( this . useCaseSensitiveFileNames ) ;
88106
89107 if ( safeList ) {
90- this . vfs . addFile ( FakeServerHost . safeListPath , FakeServerHost . safeListContent ) ;
108+ this . vfs . addFile (
109+ dos ? FakeServerHost . dosSafeListPath : FakeServerHost . safeListPath ,
110+ FakeServerHost . safeListContent ) ;
91111 }
92112
93113 if ( lib ) {
94- this . vfs . addFile ( FakeServerHost . libPath , FakeServerHost . libContent ) ;
114+ this . vfs . addFile (
115+ dos ? FakeServerHost . dosLibPath : FakeServerHost . libPath ,
116+ FakeServerHost . libContent ) ;
95117 }
96118 }
97119
@@ -143,6 +165,12 @@ namespace fakes {
143165 }
144166 // #endregion DirectoryStructureHost members
145167
168+ // #region ModuleResolutionHost members
169+ public trace ( message : string ) {
170+ this . _trace . push ( message ) ;
171+ }
172+ // #endregion
173+
146174 // #region System members
147175 public readonly args : string [ ] = [ ] ;
148176
@@ -226,6 +254,14 @@ namespace fakes {
226254 this . _output . length = 0 ;
227255 }
228256
257+ public getTrace ( ) : ReadonlyArray < string > {
258+ return this . _trace ;
259+ }
260+
261+ public clearTrace ( ) {
262+ this . _trace . length = 0 ;
263+ }
264+
229265 public checkTimeoutQueueLength ( expected : number ) {
230266 const callbacksCount = this . timers . getPending ( { kind : "timeout" , ms : this . timers . remainingTime } ) . length ;
231267 assert . equal ( callbacksCount , expected , `expected ${ expected } timeout callbacks queued but found ${ callbacksCount } .` ) ;
@@ -236,6 +272,17 @@ namespace fakes {
236272 this . runQueuedTimeoutCallbacks ( ) ;
237273 }
238274
275+ public runQueuedImmediateCallbacks ( ) {
276+ try {
277+ this . timers . executeImmediates ( ) ;
278+ }
279+ catch ( e ) {
280+ if ( e !== FakeServerHost . processExitSentinel ) {
281+ throw e ;
282+ }
283+ }
284+ }
285+
239286 public runQueuedTimeoutCallbacks ( ) {
240287 try {
241288 this . timers . advanceToEnd ( ) ;
0 commit comments