Skip to content

Commit

Permalink
allow test harness to provide a mock fileExists function
Browse files Browse the repository at this point in the history
  • Loading branch information
basarat committed May 15, 2015
1 parent dbe2ed2 commit a17c6aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ module Harness.LanguageService {
log(s: string): void { }
trace(s: string): void { }
error(s: string): void { }
fileExists = (fn: string) => this.getFilenames().some(serviceAdaptorFileName=> serviceAdaptorFileName === fn);
}

export class NativeLanugageServiceAdapter implements LanguageServiceAdapter {
Expand Down Expand Up @@ -236,6 +237,7 @@ module Harness.LanguageService {
log(s: string): void { this.nativeHost.log(s); }
trace(s: string): void { this.nativeHost.trace(s); }
error(s: string): void { this.nativeHost.error(s); }
fileExists(fn: string) { return this.nativeHost.fileExists(fn); }
}

class ClassifierShimProxy implements ts.Classifier {
Expand Down
5 changes: 4 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,9 @@ module ts {
log? (s: string): void;
trace? (s: string): void;
error? (s: string): void;

// Needed for mocking support
fileExists? (s: string): boolean;
}

//
Expand Down Expand Up @@ -2436,7 +2439,7 @@ module ts {
getDefaultLibFileName: (options) => host.getDefaultLibFileName(options),
writeFile: (fileName, data, writeByteOrderMark) => { },
readFile: (fileName) => sys.readFile(fileName),
fileExists: (fileName) => !!hostCache.getOrCreateEntry(fileName),
fileExists: host.fileExists ? (fn) => host.fileExists(fn) : sys.fileExists,
getCurrentDirectory: () => host.getCurrentDirectory(),
});

Expand Down
5 changes: 5 additions & 0 deletions src/services/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module ts {
getDefaultLibFileName(options: string): string;
getNewLine?(): string;
getProjectVersion?(): string;
fileExists(fileName: string): boolean;
}

/** Public interface of the the of a config service shim instance.*/
Expand Down Expand Up @@ -260,6 +261,10 @@ module ts {
public error(s: string): void {
this.shimHost.error(s);
}

public fileExists(fn: string): boolean {
return this.shimHost.fileExists(fn);
}

public getProjectVersion(): string {
if (!this.shimHost.getProjectVersion) {
Expand Down

0 comments on commit a17c6aa

Please sign in to comment.