Skip to content

Commit 3ac91d1

Browse files
committed
Generate tsconfig in tsc-instrumented instead
1 parent 8ccf0af commit 3ac91d1

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/harness/loggedIO.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace Playback {
159159
}
160160

161161
const canonicalizeForHarness = ts.createGetCanonicalFileName(/*caseSensitive*/ false); // This is done so tests work on windows _and_ linux
162-
export function sanitizeTestFilePath(name: string) {
162+
function sanitizeTestFilePath(name: string) {
163163
const path = ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", canonicalizeForHarness);
164164
if (ts.startsWith(path, "/")) {
165165
return path.substring(1);
@@ -249,13 +249,33 @@ namespace Playback {
249249
wrapper.endRecord = () => {
250250
if (recordLog !== undefined) {
251251
let i = 0;
252-
const fn = () => recordLogFileNameBase + i;
253-
while (underlying.fileExists(ts.combinePaths(fn(), "test.json"))) i++;
254-
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
252+
const getBase = () => recordLogFileNameBase + i;
253+
while (underlying.fileExists(ts.combinePaths(getBase(), "test.json"))) i++;
254+
const newLog = oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), getBase());
255+
underlying.writeFile(ts.combinePaths(getBase(), "test.json"), JSON.stringify(newLog, null, 4)); // tslint:disable-line:no-null-keyword
256+
const syntheticTsconfig = generateTsconfig(newLog);
257+
if (syntheticTsconfig) {
258+
underlying.writeFile(ts.combinePaths(getBase(), "tsconfig.json"), JSON.stringify(syntheticTsconfig, null, 4)); // tslint:disable-line:no-null-keyword
259+
}
255260
recordLog = undefined;
256261
}
257262
};
258263

264+
function generateTsconfig(newLog: IOLog): undefined | { compilerOptions: ts.CompilerOptions, files: string[] } {
265+
if (newLog.filesRead.some(file => /tsconfig.json$/.test(file.path))) {
266+
return;
267+
}
268+
const files = [];
269+
for (const file of newLog.filesRead) {
270+
if (file.result.contentsPath &&
271+
!/lib\.d\.ts$/.test(file.result.contentsPath) &&
272+
/\.[tj]s$/.test(file.result.contentsPath)) {
273+
files.push(file.result.contentsPath);
274+
}
275+
}
276+
return { compilerOptions: ts.parseCommandLine(newLog.arguments).options, files };
277+
}
278+
259279
wrapper.fileExists = recordReplay(wrapper.fileExists, underlying)(
260280
path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }),
261281
memoize(path => {

src/harness/rwcRunner.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ namespace RWC {
7070
opts.options.noEmitOnError = false;
7171
});
7272

73-
let tsconfigFile: IOLogFile;
7473
runWithIOLog(ioLog, oldIO => {
7574
let fileNames = opts.fileNames;
7675

77-
tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined);
76+
const tsconfigFile = ts.forEach(ioLog.filesRead, f => isTsConfigFile(f) ? f : undefined);
7877
if (tsconfigFile) {
7978
const tsconfigFileContents = getHarnessCompilerInputUnit(tsconfigFile.path);
8079
tsconfigFiles.push({ unitName: tsconfigFile.path, content: tsconfigFileContents.content });
@@ -156,11 +155,6 @@ namespace RWC {
156155
compilerResult = output.result;
157156
});
158157

159-
if (!tsconfigFile) {
160-
const files = inputFiles.map(f => Playback.sanitizeTestFilePath(f.unitName));
161-
Harness.IO.writeFile(`internal/cases/rwc/${baseName}/read/tsconfig.json`, JSON.stringify({ compilerOptions, files }));
162-
}
163-
164158
function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile {
165159
const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName));
166160
let content: string;

0 commit comments

Comments
 (0)