Skip to content

Commit af95f17

Browse files
committed
update tests
1 parent 9a18012 commit af95f17

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/harness/unittests/tsserverProjectSystem.ts

+31-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace ts {
3131
protected projectService: server.ProjectService;
3232
constructor(private readonly host: server.ServerHost) {
3333
super();
34+
this.init();
3435
}
3536

3637
abstract cachePath: string;
@@ -259,6 +260,8 @@ namespace ts {
259260

260261
readonly watchedDirectories: MapLike<{ cb: DirectoryWatcherCallback, recursive: boolean }[]> = {};
261262
readonly watchedFiles: MapLike<FileWatcherCallback[]> = {};
263+
264+
private filesOrFolders: FileOrFolder[];
262265

263266
constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[]) {
264267
this.getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
@@ -268,6 +271,7 @@ namespace ts {
268271
}
269272

270273
reloadFS(filesOrFolders: FileOrFolder[]) {
274+
this.filesOrFolders = filesOrFolders;
271275
this.fs = createFileMap<FSEntry>();
272276
for (const fileOrFolder of filesOrFolders) {
273277
const path = this.toPath(fileOrFolder.path);
@@ -419,15 +423,36 @@ namespace ts {
419423
this.immediateCallbacks.unregister(timeoutId);
420424
};
421425

426+
createDirectory(directoryName: string): void {
427+
this.createFileOrFolder({ path: directoryName });
428+
}
422429

430+
writeFile(path: string, content: string): void {
431+
this.createFileOrFolder({ path, content, fileSize: content.length })
432+
}
433+
434+
createFileOrFolder(f: FileOrFolder, createParentDirectory = false): void {
435+
const base = getDirectoryPath(f.path);
436+
if (base !== f.path && !this.directoryExists(base)) {
437+
if (createParentDirectory) {
438+
// TODO: avoid reloading FS on every creation
439+
this.createFileOrFolder({ path: base }, createParentDirectory);
440+
}
441+
else {
442+
throw new Error(`directory ${base} does not exist`);
443+
}
444+
}
445+
const filesOrFolders = this.filesOrFolders.slice(0);
446+
filesOrFolders.push(f);
447+
this.reloadFS(filesOrFolders);
448+
}
449+
423450
readonly readFile = (s: string) => (<File>this.fs.get(this.toPath(s))).content;
424451
readonly resolvePath = (s: string) => s;
425452
readonly getExecutingFilePath = () => this.executingFilePath;
426453
readonly getCurrentDirectory = () => this.currentDirectory;
427-
readonly writeFile = (path: string, content: string) => notImplemented();
428454
readonly writeCompressedData = () => notImplemented();
429455
readonly write = (s: string) => notImplemented();
430-
readonly createDirectory = (s: string) => notImplemented();
431456
readonly exit = () => notImplemented();
432457
}
433458

@@ -1496,7 +1521,7 @@ namespace ts {
14961521
class TypingInstaller extends TestTypingsInstaller {
14971522
cachePath = "/a/data/";
14981523
constructor(host: server.ServerHost) {
1499-
super(host)
1524+
super(host);
15001525
}
15011526
};
15021527
const installer = new TypingInstaller(host);
@@ -1507,9 +1532,11 @@ namespace ts {
15071532
const p = projectService.configuredProjects[0];
15081533
checkProjectActualFiles(p, [ file1.path ]);
15091534

1535+
assert(host.fileExists(combinePaths(installer.cachePath, "tsd.json")));
1536+
15101537
installer.runPostInstallActions(t => {
15111538
assert.deepEqual(t, ["jquery"]);
1512-
host.reloadFS([file1, tsconfig, packageJson, jquery]);
1539+
host.createFileOrFolder(jquery, /*createParentDirectory*/ true);
15131540
return ["jquery/jquery.d.ts"];
15141541
});
15151542
checkNumberOfProjects(projectService, { configuredProjects: 1 })

src/server/editorServices.ts

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ namespace ts.server {
212212
return;
213213
}
214214
this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings);
215+
project.setTypings(response.typings);
215216
project.updateGraph();
216217
}
217218

0 commit comments

Comments
 (0)