Skip to content

Commit d0988b8

Browse files
committed
PR Feedback
1 parent 545868c commit d0988b8

11 files changed

Lines changed: 69 additions & 392 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: node_js
22

33
node_js:
44
- 'stable'
5-
- 'lts/*'
5+
- '8'
66

77
sudo: false
88

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@types/gulp-help": "latest",
4040
"@types/gulp-newer": "latest",
4141
"@types/gulp-sourcemaps": "latest",
42-
"@types/jake": "0.0.30",
42+
"@types/jake": "latest",
4343
"@types/merge2": "latest",
4444
"@types/minimatch": "latest",
4545
"@types/minimist": "latest",
@@ -48,7 +48,7 @@
4848
"@types/node": "8.5.5",
4949
"@types/q": "latest",
5050
"@types/run-sequence": "latest",
51-
"@types/source-map-support": "^0.4.0",
51+
"@types/source-map-support": "latest",
5252
"@types/through2": "latest",
5353
"@types/xml2js": "^0.4.0",
5454
"@typescript/vfs-path": "file:scripts/vfs-path",

scripts/typemock/src/mock.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { Inject } from "./inject";
55
const weakHandler = new WeakMap<object, MockHandler<object>>();
66
const weakMock = new WeakMap<object, Mock<object>>();
77

8-
function noop() {}
9-
const empty = {};
10-
118
export type Callable = (...args: any[]) => any;
129

1310
export type Constructable = new (...args: any[]) => any;
@@ -111,7 +108,7 @@ export class Mock<T extends object> {
111108
public static spy<T extends { [P in K]: (...args: any[]) => any }, K extends keyof T>(object?: T, propertyKey?: K) {
112109
return object !== undefined && propertyKey !== undefined
113110
? new Spy(object, propertyKey)
114-
: new Mock(object || noop);
111+
: new Mock(object || function () {});
115112
}
116113

117114
/**
@@ -221,7 +218,7 @@ export class Spy<T extends { [P in K]: (...args: any[]) => any }, K extends keyo
221218

222219
class Recording {
223220
public static readonly noThisArg = {};
224-
public readonly trap: string;
221+
public readonly trap: "apply" | "construct" | "invoke" | "get" | "set";
225222
public readonly name: PropertyKey | undefined;
226223
public readonly thisArg: any;
227224
public readonly argArray: ReadonlyArray<any>;
@@ -233,7 +230,7 @@ class Recording {
233230
private _newTargetCondition: Arg | undefined;
234231
private _conditions: ReadonlyArray<Arg> | undefined;
235232

236-
constructor(trap: string, name: PropertyKey | undefined, thisArg: any, argArray: ReadonlyArray<any>, newTarget: any, result: Partial<Returns<any> & Throws & Fallback> | undefined, callback: Callable | undefined) {
233+
constructor(trap: "apply" | "construct" | "invoke" | "get" | "set", name: PropertyKey | undefined, thisArg: any, argArray: ReadonlyArray<any>, newTarget: any, result: Partial<Returns<any> & Throws & Fallback> | undefined, callback: Callable | undefined) {
237234
this.trap = trap;
238235
this.name = name;
239236
this.thisArg = thisArg;
@@ -450,7 +447,7 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
450447
}
451448

452449
protected capture<U>(callback: (value: T) => U, result: Setup<any> | undefined) {
453-
return this.captureCore(<T>empty, new CapturingHandler<T, U>(result), callback);
450+
return this.captureCore(<T>{}, new CapturingHandler<T, U>(result), callback);
454451
}
455452

456453
protected captureCore<T extends object, U>(target: T, handler: CapturingHandler<T, U>, callback: (value: T) => U): Recording {
@@ -471,7 +468,7 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
471468
const setups = this.setups;
472469
this.setupMembers({
473470
[name](...argArray: any[]) {
474-
return Recording.evaluate(setups, "invoke", name, this, argArray, /*newTarget*/ undefined, noop);
471+
return Recording.evaluate(setups, "invoke", name, this, argArray, /*newTarget*/ undefined, () => {});
475472
}
476473
});
477474
}
@@ -480,10 +477,10 @@ class MockHandler<T extends object> implements ProxyHandler<T> {
480477
const setups = this.setups;
481478
this.setupMembers({
482479
get [name]() {
483-
return Recording.evaluate(setups, "get", name, this, [], /*newTarget*/ undefined, noop);
480+
return Recording.evaluate(setups, "get", name, this, [], /*newTarget*/ undefined, () => {});
484481
},
485482
set [name](value: any) {
486-
Recording.evaluate(setups, "set", name, this, [value], /*newTarget*/ undefined, noop);
483+
Recording.evaluate(setups, "set", name, this, [value], /*newTarget*/ undefined, () => {});
487484
}
488485
});
489486
}
@@ -519,7 +516,7 @@ class MockFunctionHandler<T extends Callable | Constructable> extends MockHandle
519516
}
520517

521518
protected capture<U>(callback: (value: T) => U, result: Returns<any> & ThisArg | Returns<any> | Throws & ThisArg | Throws | ThisArg | undefined) {
522-
return this.captureCore(<T>noop, new CapturingFunctionHandler<T, U>(result), callback);
519+
return this.captureCore(<T>function() {}, new CapturingFunctionHandler<T, U>(result), callback);
523520
}
524521
}
525522

src/harness/fakes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace fakes {
3737
}
3838

3939
export class FakeServerHost implements ts.server.ServerHost, ts.FormatDiagnosticsHost, ts.ModuleResolutionHost {
40-
public static readonly dosExecutingFilePath = "c:/.ts/tsc.js";
41-
public static readonly defaultExecutingFilePath = "/.ts/tsc.js";
40+
public static readonly dosExecutingFilePath = vpath.combine(vfsutils.dosBuiltFolder, "tsc.js");
41+
public static readonly defaultExecutingFilePath = vpath.combine(vfsutils.builtFolder, "tsc.js");
4242
public static readonly dosDefaultCurrentDirectory = "c:/";
4343
public static readonly defaultCurrentDirectory = "/";
4444
public static readonly dosSafeListPath = "c:/safelist.json";
@@ -53,8 +53,8 @@ namespace fakes {
5353
` "chroma": "chroma-js"\n` +
5454
`}`;
5555

56-
public static readonly dosLibPath = "c:/.ts/lib.d.ts";
57-
public static readonly libPath = "/.ts/lib.d.ts";
56+
public static readonly dosLibPath = vpath.combine(vfsutils.dosBuiltFolder, "lib.d.ts");
57+
public static readonly libPath = vpath.combine(vfsutils.builtFolder, "lib.d.ts");
5858
public static readonly libContent =
5959
`/// <reference no-default-lib="true"/>\n` +
6060
`interface Boolean {}\n` +

src/harness/harness.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ namespace Harness {
12201220
options.skipDefaultLibCheck = typeof options.skipDefaultLibCheck === "undefined" ? true : options.skipDefaultLibCheck;
12211221

12221222
if (typeof currentDirectory === "undefined") {
1223-
currentDirectory = "/.src";
1223+
currentDirectory = vfsutils.srcFolder;
12241224
}
12251225

12261226
// Parse settings
@@ -1237,13 +1237,13 @@ namespace Harness {
12371237
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
12381238
// Treat them as library files, so include them in build, but not in baselines.
12391239
if (options.includeBuiltFile) {
1240-
programFileNames.push(vpath.combine("/.ts/", options.includeBuiltFile));
1240+
programFileNames.push(vpath.combine(vfsutils.builtFolder, options.includeBuiltFile));
12411241
}
12421242

12431243
// Files from tests\lib that are requested by "@libFiles"
12441244
if (options.libFiles) {
12451245
for (const fileName of options.libFiles.split(",")) {
1246-
programFileNames.push(vpath.combine("/.lib/", fileName));
1246+
programFileNames.push(vpath.combine(vfsutils.testLibFolder, fileName));
12471247
}
12481248
}
12491249

@@ -2113,7 +2113,7 @@ namespace Harness {
21132113

21142114
export function isBuiltFile(filePath: string): boolean {
21152115
return filePath.indexOf(Harness.libFolder) === 0 ||
2116-
filePath.indexOf("/.ts/") === 0;
2116+
filePath.indexOf(vpath.addTrailingSeparator(vfsutils.builtFolder)) === 0;
21172117
}
21182118

21192119
export function getDefaultLibraryFile(filePath: string, io: Harness.IO): Harness.Compiler.TestFile {

src/harness/projectsRunner.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace project {
100100

101101
public readDirectory(path: string, extensions: string[], excludes: string[], includes: string[], depth: number): string[] {
102102
const result = super.readDirectory(path, extensions, excludes, includes, depth);
103-
const projectRoot = vpath.resolve("/.src", this._testCase.projectRoot);
103+
const projectRoot = vpath.resolve(vfsutils.srcFolder, this._testCase.projectRoot);
104104
return result.map(item => vpath.relative(
105105
projectRoot,
106106
vpath.resolve(projectRoot, item),
@@ -189,9 +189,9 @@ namespace project {
189189
}
190190

191191
const fs = vfsutils.createFromFileSystem(/*useCaseSensitiveFileNames*/ true);
192-
fs.mountSync(vpath.resolve(__dirname, "../../tests"), "/.src/tests", vfsutils.createResolver(Harness.IO));
193-
fs.mkdirpSync(vpath.combine("/.src", testCase.projectRoot));
194-
fs.chdir(vpath.combine("/.src", testCase.projectRoot));
192+
fs.mountSync(vpath.resolve(__dirname, "../../tests"), vpath.combine(vfsutils.srcFolder, "tests"), vfsutils.createResolver(Harness.IO));
193+
fs.mkdirpSync(vpath.combine(vfsutils.srcFolder, testCase.projectRoot));
194+
fs.chdir(vpath.combine(vfsutils.srcFolder, testCase.projectRoot));
195195
fs.makeReadonly();
196196

197197
return [
@@ -389,7 +389,7 @@ namespace project {
389389
});
390390

391391
const _vfs = vfsutils.createFromDocuments(/*useCaseSensitiveFileNames*/ true, allInputFiles, {
392-
currentDirectory: vpath.combine("/.src", this.testCase.projectRoot)
392+
currentDirectory: vpath.combine(vfsutils.srcFolder, this.testCase.projectRoot)
393393
});
394394

395395
// Dont allow config files since we are compiling existing source options
@@ -438,11 +438,11 @@ namespace project {
438438
moduleResolution: ts.ModuleResolutionKind.Classic,
439439
module: moduleKind,
440440
mapRoot: testCase.resolveMapRoot && testCase.mapRoot
441-
? vpath.resolve("/.src", testCase.mapRoot)
441+
? vpath.resolve(vfsutils.srcFolder, testCase.mapRoot)
442442
: testCase.mapRoot,
443443

444444
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot
445-
? vpath.resolve("/.src", testCase.sourceRoot)
445+
? vpath.resolve(vfsutils.srcFolder, testCase.sourceRoot)
446446
: testCase.sourceRoot
447447
};
448448

src/harness/unittests/tscWatchMode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,21 @@ namespace ts.tscWatch {
515515
});
516516

517517
it("correctly handles changes in lib section of config file", () => {
518+
const es5LibPath = vpath.combine(vfsutils.builtFolder, "lib.es5.d.ts");
519+
const es2015PromiseLibPath = vpath.combine(vfsutils.builtFolder, "lib.es2015.promise.d.ts");
518520
const host = new fakes.FakeServerHost({}, /*files*/ {
519-
"/.ts/lib.es5.d.ts": `declare const eval: any`,
520-
"/.ts/lib.es2015.promise.d.ts": `declare class Promise<T> {}`,
521+
[es5LibPath]: `declare const eval: any`,
522+
[es2015PromiseLibPath]: `declare class Promise<T> {}`,
521523
"/src/app.ts": `var x: Promise<string>;`,
522524
"/src/tsconfig.json": `{ "compilerOptions": { "lib": ["es5"] } }`,
523525
});
524526

525527
const watch = createWatchOfConfigFile("/src/tsconfig.json", host);
526-
checkProgramActualFiles(watch(), ["/.ts/lib.es5.d.ts", "/src/app.ts"]);
528+
checkProgramActualFiles(watch(), [es5LibPath, "/src/app.ts"]);
527529

528530
host.vfs.writeFileSync("/src/tsconfig.json", `{ "compilerOptions": { "lib": ["es5", "es2015.promise"] } }`);
529531
host.checkTimeoutQueueLengthAndRun(1);
530-
checkProgramActualFiles(watch(), ["/.ts/lib.es5.d.ts", "/.ts/lib.es2015.promise.d.ts", "/src/app.ts"]);
532+
checkProgramActualFiles(watch(), [es5LibPath, es2015PromiseLibPath, "/src/app.ts"]);
531533
});
532534

533535
it("should handle non-existing directories in config file", () => {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5762,7 +5762,7 @@ namespace ts.projectSystem {
57625762
content: "export class Cookie { }"
57635763
};
57645764
const es2016LibFile: FileOrFolder = {
5765-
path: "/.ts/lib.es2016.full.d.ts",
5765+
path: vpath.combine(vfsutils.builtFolder, "lib.es2016.full.d.ts"),
57665766
content: libFile.content
57675767
};
57685768
const typeRoots = ["types", "node_modules/@types"];

src/harness/unittests/typingsInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ namespace ts.projectSystem {
732732
checkNumberOfProjects(projectService, { configuredProjects: 1 });
733733
const p = configuredProjectAt(projectService, 0);
734734
checkProjectActualFiles(p, [app, jsconfig]);
735-
host.checkWatchedFiles([jsconfig, "/bower_components", "/node_modules", "/.ts/lib.d.ts"]);
735+
host.checkWatchedFiles([jsconfig, "/bower_components", "/node_modules", vpath.combine(vfsutils.builtFolder, "lib.d.ts")]);
736736

737737
installer.installAll(/*expectedCount*/ 1);
738738

src/harness/vfsutils.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ namespace vfsutils {
1313
let builtLocalCI: vfs.FileSystem | undefined;
1414
let builtLocalCS: vfs.FileSystem | undefined;
1515

16+
/**
17+
* Posix-style path to the TypeScript compiler build outputs (including tsc.js, lib.d.ts, etc.)
18+
*/
19+
export const builtFolder = "/.ts";
20+
21+
/**
22+
* Posix-style path to additional test libraries
23+
*/
24+
export const testLibFolder = "/.lib";
25+
26+
/**
27+
* Posix-style path to sources under test
28+
*/
29+
export const srcFolder = "/.src";
30+
31+
/**
32+
* DOS-style path to the TypeScript compiler build outputs (including tsc.js, lib.d.ts, etc.)
33+
*/
34+
export const dosBuiltFolder = "c:" + builtFolder;
35+
36+
/**
37+
* DOS-style path to additional test libraries
38+
*/
39+
export const dosTestLibFolder = "c:" + testLibFolder;
40+
41+
/**
42+
* DOS-style path to sources under test
43+
*/
44+
export const dosSrcFolder = "c:" + srcFolder;
45+
1646
export function createResolver(io: Harness.IO): vfs.FileSystemResolver {
1747
return {
1848
readdirSync(path: string): string[] {
@@ -60,12 +90,12 @@ namespace vfsutils {
6090
const resolver = createResolver(Harness.IO);
6191
builtLocalCI = new vfs.FileSystem(/*ignoreCase*/ true, {
6292
files: {
63-
"/.ts": new vfs.Mount(__dirname, patchResolver(Harness.IO, resolver)),
64-
"/.lib": new vfs.Mount(vpath.resolve(__dirname, "../../tests/lib"), resolver),
65-
"/.src": {}
93+
[builtFolder]: new vfs.Mount(__dirname, patchResolver(Harness.IO, resolver)),
94+
[testLibFolder]: new vfs.Mount(vpath.resolve(__dirname, "../../tests/lib"), resolver),
95+
[srcFolder]: {}
6696
},
67-
cwd: "/.src",
68-
meta: { defaultLibLocation: "/.ts" }
97+
cwd: srcFolder,
98+
meta: { defaultLibLocation: builtFolder }
6999
});
70100
builtLocalCI.makeReadonly();
71101
}

0 commit comments

Comments
 (0)