Skip to content

Commit a17c6aa

Browse files
committed
allow test harness to provide a mock fileExists function
1 parent dbe2ed2 commit a17c6aa

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/harness/harnessLanguageService.ts

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ module Harness.LanguageService {
190190
log(s: string): void { }
191191
trace(s: string): void { }
192192
error(s: string): void { }
193+
fileExists = (fn: string) => this.getFilenames().some(serviceAdaptorFileName=> serviceAdaptorFileName === fn);
193194
}
194195

195196
export class NativeLanugageServiceAdapter implements LanguageServiceAdapter {
@@ -236,6 +237,7 @@ module Harness.LanguageService {
236237
log(s: string): void { this.nativeHost.log(s); }
237238
trace(s: string): void { this.nativeHost.trace(s); }
238239
error(s: string): void { this.nativeHost.error(s); }
240+
fileExists(fn: string) { return this.nativeHost.fileExists(fn); }
239241
}
240242

241243
class ClassifierShimProxy implements ts.Classifier {

src/services/services.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ module ts {
960960
log? (s: string): void;
961961
trace? (s: string): void;
962962
error? (s: string): void;
963+
964+
// Needed for mocking support
965+
fileExists? (s: string): boolean;
963966
}
964967

965968
//
@@ -2436,7 +2439,7 @@ module ts {
24362439
getDefaultLibFileName: (options) => host.getDefaultLibFileName(options),
24372440
writeFile: (fileName, data, writeByteOrderMark) => { },
24382441
readFile: (fileName) => sys.readFile(fileName),
2439-
fileExists: (fileName) => !!hostCache.getOrCreateEntry(fileName),
2442+
fileExists: host.fileExists ? (fn) => host.fileExists(fn) : sys.fileExists,
24402443
getCurrentDirectory: () => host.getCurrentDirectory(),
24412444
});
24422445

src/services/shims.ts

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module ts {
5656
getDefaultLibFileName(options: string): string;
5757
getNewLine?(): string;
5858
getProjectVersion?(): string;
59+
fileExists(fileName: string): boolean;
5960
}
6061

6162
/** Public interface of the the of a config service shim instance.*/
@@ -260,6 +261,10 @@ module ts {
260261
public error(s: string): void {
261262
this.shimHost.error(s);
262263
}
264+
265+
public fileExists(fn: string): boolean {
266+
return this.shimHost.fileExists(fn);
267+
}
263268

264269
public getProjectVersion(): string {
265270
if (!this.shimHost.getProjectVersion) {

0 commit comments

Comments
 (0)