Skip to content

Commit 0d126e2

Browse files
committed
add support for tsconfig files in the rwc instrumenter/replay
1 parent 36acaff commit 0d126e2

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/harness/harness.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ module Harness {
428428
args(): string[];
429429
getExecutingFilePath(): string;
430430
exit(exitCode?: number): void;
431+
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
431432
}
432433
export var IO: IO;
433434

@@ -464,6 +465,7 @@ module Harness {
464465
export const directoryExists: typeof IO.directoryExists = fso.FolderExists;
465466
export const fileExists: typeof IO.fileExists = fso.FileExists;
466467
export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
468+
export const readDirectory: typeof IO.readDirectory = (path, extension, exclude) => ts.sys.readDirectory(path, extension, exclude);
467469

468470
export function createDirectory(path: string) {
469471
if (directoryExists(path)) {
@@ -532,6 +534,8 @@ module Harness {
532534
export const fileExists: typeof IO.fileExists = fs.existsSync;
533535
export const log: typeof IO.log = s => console.log(s);
534536

537+
export const readDirectory: typeof IO.readDirectory = (path, extension, exclude) => ts.sys.readDirectory(path, extension, exclude);
538+
535539
export function createDirectory(path: string) {
536540
if (!directoryExists(path)) {
537541
fs.mkdirSync(path);
@@ -730,6 +734,10 @@ module Harness {
730734
export function writeFile(path: string, contents: string) {
731735
Http.writeToServerSync(serverRoot + path, "WRITE", contents);
732736
}
737+
738+
export function readDirectory(path: string, extension?: string, exclude?: string[]) {
739+
return listFiles(path).filter(f => !extension || ts.fileExtensionIs(f, extension));
740+
}
733741
}
734742
}
735743

src/harness/loggedIO.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ interface IOLog {
5959
path: string;
6060
result?: string;
6161
}[];
62+
directoriesRead: {
63+
path: string,
64+
extension: string,
65+
exclude: string[],
66+
result: string[]
67+
}[];
6268
}
6369

6470
interface PlaybackControl {
@@ -103,6 +109,7 @@ module Playback {
103109
arguments: [],
104110
currentDirectory: "",
105111
filesRead: [],
112+
directoriesRead: [],
106113
filesWritten: [],
107114
filesDeleted: [],
108115
filesAppended: [],
@@ -118,7 +125,7 @@ module Playback {
118125

119126
function initWrapper(wrapper: PlaybackSystem, underlying: ts.System): void;
120127
function initWrapper(wrapper: PlaybackIO, underlying: Harness.IO): void;
121-
function initWrapper(wrapper: PlaybackSystem | PlaybackIO, underlying: ts.System | Harness.IO): void {
128+
function initWrapper(wrapper: PlaybackSystem | PlaybackIO, underlying: ts.System | Harness.IO): void {
122129
ts.forEach(Object.keys(underlying), prop => {
123130
(<any>wrapper)[prop] = (<any>underlying)[prop];
124131
});
@@ -203,6 +210,15 @@ module Playback {
203210
},
204211
memoize((path) => findResultByPath(wrapper, replayLog.filesRead, path).contents));
205212

213+
wrapper.readDirectory = recordReplay(wrapper.readDirectory, underlying)(
214+
(path, extension, exclude) => {
215+
let result = (<ts.System>underlying).readDirectory(path, extension, exclude);
216+
let logEntry = { path, extension, exclude, result };
217+
recordLog.directoriesRead.push(logEntry);
218+
return result;
219+
},
220+
(path, extension, exclude) => findResultByPath(wrapper, replayLog.directoriesRead.filter(d => d.extension === extension && ts.arrayIsEqualTo(d.exclude, exclude)), path));
221+
206222
wrapper.writeFile = recordReplay(wrapper.writeFile, underlying)(
207223
(path, contents) => callAndRecord(underlying.writeFile(path, contents), recordLog.filesWritten, { path: path, contents: contents, bom: false }),
208224
(path, contents) => noOpReplay("writeFile"));

src/harness/rwcRunner.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ module RWC {
1919
}
2020
}
2121

22+
function isTsConfigFile(file: { path: string }): boolean {
23+
const tsConfigFileName = "tsconfig.json";
24+
return file.path.substr(file.path.length - tsConfigFileName.length).toLowerCase() === tsConfigFileName;
25+
}
26+
2227
export function runRWCTest(jsonPath: string) {
2328
describe("Testing a RWC project: " + jsonPath, () => {
2429
let inputFiles: { unitName: string; content: string; }[] = [];
@@ -67,8 +72,17 @@ module RWC {
6772
runWithIOLog(ioLog, oldIO => {
6873
harnessCompiler.reset();
6974

75+
let fileNames = opts.fileNames;
76+
77+
let tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined);
78+
if (tsconfigFile) {
79+
let tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path);
80+
let configParseResult = ts.parseConfigFile(tsconfigFileContents.content, Harness.IO, ts.getDirectoryPath(tsconfigFile.path));
81+
fileNames = configParseResult.fileNames;
82+
}
83+
7084
// Load the files
71-
ts.forEach(opts.fileNames, fileName => {
85+
ts.forEach(fileNames, fileName => {
7286
inputFiles.push(getHarnessCompilerInputUnit(fileName));
7387
});
7488

@@ -79,6 +93,10 @@ module RWC {
7993
const resolvedPath = ts.normalizeSlashes(Harness.IO.resolvePath(fileRead.path));
8094
let inInputList = ts.forEach(inputFiles, isInInputList(resolvedPath));
8195

96+
if (isTsConfigFile(fileRead)) {
97+
continue;
98+
}
99+
82100
if (!Harness.isLibraryFile(fileRead.path)) {
83101
if (inInputList) {
84102
continue;

0 commit comments

Comments
 (0)