Skip to content

Commit 460f2a8

Browse files
committed
Refactor for simpler tests
1 parent 03fa5b3 commit 460f2a8

File tree

6 files changed

+32
-79
lines changed

6 files changed

+32
-79
lines changed

src/harness/virtualFileSystemWithWatch.ts

+3-49
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ interface String { charAt: any; }
1414
interface Array<T> { length: number; [n: number]: T; }`
1515
};
1616

17-
export const safeList = {
18-
path: "/safeList.json" as Path,
19-
content: JSON.stringify({
20-
commander: "commander",
21-
express: "express",
22-
jquery: "jquery",
23-
lodash: "lodash",
24-
moment: "moment",
25-
chroma: "chroma-js"
26-
})
27-
};
28-
2917
function getExecutingFilePathFromLibFile(): string {
3018
return combinePaths(getDirectoryPath(libFile.path), "tsc.js");
3119
}
@@ -43,11 +31,11 @@ interface Array<T> { length: number; [n: number]: T; }`
4331
}
4432

4533
export function createWatchedSystem(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
46-
return new TestServerHost(/*withSafelist*/ false, fileOrFolderList, params);
34+
return new TestServerHost(fileOrFolderList, params);
4735
}
4836

4937
export function createServerHost(fileOrFolderList: readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters): TestServerHost {
50-
const host = new TestServerHost(/*withSafelist*/ true, fileOrFolderList, params);
38+
const host = new TestServerHost(fileOrFolderList, params);
5139
// Just like sys, patch the host to use writeFile
5240
patchWriteFileEnsuringDirectory(host);
5341
return host;
@@ -338,7 +326,6 @@ interface Array<T> { length: number; [n: number]: T; }`
338326
private readonly inodes?: ESMap<Path, number>;
339327
watchDirectory: HostWatchDirectory;
340328
constructor(
341-
public withSafeList: boolean,
342329
fileOrFolderorSymLinkList: readonly FileOrFolderOrSymLink[],
343330
{
344331
useCaseSensitiveFileNames, executingFilePath, currentDirectory,
@@ -430,47 +417,14 @@ interface Array<T> { length: number; [n: number]: T; }`
430417

431418
private reloadFS(fileOrFolderOrSymLinkList: readonly FileOrFolderOrSymLink[]) {
432419
Debug.assert(this.fs.size === 0);
433-
fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList.concat(this.withSafeList ? safeList : []);
434420
const filesOrFoldersToLoad: readonly FileOrFolderOrSymLink[] = !this.windowsStyleRoot ? fileOrFolderOrSymLinkList :
435421
fileOrFolderOrSymLinkList.map<FileOrFolderOrSymLink>(f => {
436422
const result = clone(f);
437423
result.path = this.getHostSpecificPath(f.path);
438424
return result;
439425
});
440426
for (const fileOrDirectory of filesOrFoldersToLoad) {
441-
const path = this.toFullPath(fileOrDirectory.path);
442-
// If its a change
443-
const currentEntry = this.fs.get(path);
444-
if (currentEntry) {
445-
if (isFsFile(currentEntry)) {
446-
if (isFile(fileOrDirectory)) {
447-
// Update file
448-
if (currentEntry.content !== fileOrDirectory.content) {
449-
this.modifyFile(fileOrDirectory.path, fileOrDirectory.content);
450-
}
451-
}
452-
else {
453-
// TODO: Changing from file => folder/Symlink
454-
}
455-
}
456-
else if (isFsSymLink(currentEntry)) {
457-
// TODO: update symlinks
458-
}
459-
else {
460-
// Folder
461-
if (isFile(fileOrDirectory)) {
462-
// TODO: Changing from folder => file
463-
}
464-
else {
465-
// Folder update: Nothing to do.
466-
currentEntry.modifiedTime = this.now();
467-
this.invokeFsWatches(currentEntry.fullPath, "change");
468-
}
469-
}
470-
}
471-
else {
472-
this.ensureFileOrFolder(fileOrDirectory);
473-
}
427+
this.ensureFileOrFolder(fileOrDirectory);
474428
}
475429
}
476430

src/testRunner/unittests/tsbuildWatch/noEmit.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ namespace ts.tscWatch {
66
commandLineArgs: ["-b", "-w", "-verbose"],
77
sys: () => createWatchedSystem(
88
[
9-
libFile,
9+
{ path: libFile.path, content: libContent },
1010
{ path: `${projectRoot}/a.js`, content: "" },
1111
{ path: `${projectRoot}/b.ts`, content: "" },
1212
{ path: `${projectRoot}/tsconfig.json`, content: JSON.stringify({ compilerOptions: { allowJs: true, noEmit: true } }) },
13-
{ path: libFile.path, content: libContent }
1413
],
1514
{ currentDirectory: projectRoot }
1615
),

src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ts.tscWatch {
2020
scenario: "forceConsistentCasingInFileNames",
2121
subScenario,
2222
commandLineArgs: ["--w", "--p", tsconfig.path],
23-
sys: () => createWatchedSystem([loggerFile, anotherFile, tsconfig, libFile, tsconfig]),
23+
sys: () => createWatchedSystem([loggerFile, anotherFile, tsconfig, libFile]),
2424
changes
2525
});
2626
}

src/testRunner/unittests/tsserver/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace ts.projectSystem {
145145
installTypingHost: server.ServerHost,
146146
readonly typesRegistry = new Map<string, MapLike<string>>(),
147147
log?: TI.Log) {
148-
super(installTypingHost, globalTypingsCacheLocation, TestFSWithWatch.safeList.path, customTypesMap.path, throttleLimit, log);
148+
super(installTypingHost, globalTypingsCacheLocation, "/safeList.json" as Path, customTypesMap.path, throttleLimit, log);
149149
}
150150

151151
protected postExecActions: PostExecAction[] = [];

tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ declare const console: { log(msg: any): void; };
2727
/a/lib/tsc.js -b -w -verbose --incremental
2828
Output::
2929
>> Screen clear
30-
[[90m12:00:25 AM[0m] Starting compilation in watch mode...
30+
[[90m12:00:23 AM[0m] Starting compilation in watch mode...
3131

32-
[[90m12:00:26 AM[0m] Projects in this build:
32+
[[90m12:00:24 AM[0m] Projects in this build:
3333
* tsconfig.json
3434

35-
[[90m12:00:27 AM[0m] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts'
35+
[[90m12:00:25 AM[0m] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts'
3636

37-
[[90m12:00:28 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
37+
[[90m12:00:26 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
3838

39-
[[90m12:00:33 AM[0m] Found 0 errors. Watching for file changes.
39+
[[90m12:00:31 AM[0m] Found 0 errors. Watching for file changes.
4040

4141

4242

@@ -130,13 +130,13 @@ Input::
130130

131131
Output::
132132
>> Screen clear
133-
[[90m12:00:37 AM[0m] File change detected. Starting incremental compilation...
133+
[[90m12:00:35 AM[0m] File change detected. Starting incremental compilation...
134134

135-
[[90m12:00:38 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
135+
[[90m12:00:36 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
136136

137-
[[90m12:00:39 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
137+
[[90m12:00:37 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
138138

139-
[[90m12:00:40 AM[0m] Found 0 errors. Watching for file changes.
139+
[[90m12:00:38 AM[0m] Found 0 errors. Watching for file changes.
140140

141141

142142

@@ -178,13 +178,13 @@ const x = 10;
178178

179179
Output::
180180
>> Screen clear
181-
[[90m12:00:44 AM[0m] File change detected. Starting incremental compilation...
181+
[[90m12:00:42 AM[0m] File change detected. Starting incremental compilation...
182182

183-
[[90m12:00:45 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
183+
[[90m12:00:43 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
184184

185-
[[90m12:00:46 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
185+
[[90m12:00:44 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
186186

187-
[[90m12:00:53 AM[0m] Found 0 errors. Watching for file changes.
187+
[[90m12:00:51 AM[0m] Found 0 errors. Watching for file changes.
188188

189189

190190

tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ declare const console: { log(msg: any): void; };
2727
/a/lib/tsc.js -b -w -verbose
2828
Output::
2929
>> Screen clear
30-
[[90m12:00:25 AM[0m] Starting compilation in watch mode...
30+
[[90m12:00:23 AM[0m] Starting compilation in watch mode...
3131

32-
[[90m12:00:26 AM[0m] Projects in this build:
32+
[[90m12:00:24 AM[0m] Projects in this build:
3333
* tsconfig.json
3434

35-
[[90m12:00:27 AM[0m] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts'
35+
[[90m12:00:25 AM[0m] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts'
3636

37-
[[90m12:00:28 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
37+
[[90m12:00:26 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
3838

39-
[[90m12:00:29 AM[0m] Found 0 errors. Watching for file changes.
39+
[[90m12:00:27 AM[0m] Found 0 errors. Watching for file changes.
4040

4141

4242

@@ -82,13 +82,13 @@ Input::
8282

8383
Output::
8484
>> Screen clear
85-
[[90m12:00:33 AM[0m] File change detected. Starting incremental compilation...
85+
[[90m12:00:31 AM[0m] File change detected. Starting incremental compilation...
8686

87-
[[90m12:00:34 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
87+
[[90m12:00:32 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
8888

89-
[[90m12:00:35 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
89+
[[90m12:00:33 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
9090

91-
[[90m12:00:36 AM[0m] Found 0 errors. Watching for file changes.
91+
[[90m12:00:34 AM[0m] Found 0 errors. Watching for file changes.
9292

9393

9494

@@ -130,13 +130,13 @@ const x = 10;
130130

131131
Output::
132132
>> Screen clear
133-
[[90m12:00:40 AM[0m] File change detected. Starting incremental compilation...
133+
[[90m12:00:38 AM[0m] File change detected. Starting incremental compilation...
134134

135-
[[90m12:00:41 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
135+
[[90m12:00:39 AM[0m] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
136136

137-
[[90m12:00:42 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
137+
[[90m12:00:40 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
138138

139-
[[90m12:00:43 AM[0m] Found 0 errors. Watching for file changes.
139+
[[90m12:00:41 AM[0m] Found 0 errors. Watching for file changes.
140140

141141

142142

0 commit comments

Comments
 (0)