Skip to content

Commit e34d8cd

Browse files
committed
Test support for TSX files
1 parent 6d01a44 commit e34d8cd

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

src/harness/compilerRunner.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CompilerBaselineRunner extends RunnerBase {
149149
// check errors
150150
it('Correct errors for ' + fileName, () => {
151151
if (this.errors) {
152-
Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => {
152+
Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.tsx?$/, '.errors.txt'), (): string => {
153153
if (result.errors.length === 0) return null;
154154
return getErrorBaseline(toBeCompiled, otherFiles, result);
155155
});
@@ -159,7 +159,7 @@ class CompilerBaselineRunner extends RunnerBase {
159159
// Source maps?
160160
it('Correct sourcemap content for ' + fileName, () => {
161161
if (options.sourceMap || options.inlineSourceMap) {
162-
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => {
162+
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.tsx?$/, '.sourcemap.txt'), () => {
163163
var record = result.getSourceMapRecord();
164164
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
165165
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
@@ -177,7 +177,7 @@ class CompilerBaselineRunner extends RunnerBase {
177177
}
178178

179179
// check js output
180-
Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.ts/, '.js'), () => {
180+
Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.tsx?/, '.js'), () => {
181181
var tsCode = '';
182182
var tsSources = otherFiles.concat(toBeCompiled);
183183
if (tsSources.length > 1) {
@@ -235,7 +235,7 @@ class CompilerBaselineRunner extends RunnerBase {
235235
throw new Error('Number of sourcemap files should be same as js files.');
236236
}
237237

238-
Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => {
238+
Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.tsx?/, '.js.map'), () => {
239239
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
240240
// We need to return null here or the runBaseLine will actually create a empty file.
241241
// Baselining isn't required here because there is no output.
@@ -320,11 +320,11 @@ class CompilerBaselineRunner extends RunnerBase {
320320
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';
321321

322322
if (fullBaseLine !== pullBaseLine) {
323-
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
324-
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine);
323+
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
324+
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine);
325325
}
326326
else {
327-
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
327+
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
328328
}
329329
}
330330

@@ -391,7 +391,7 @@ class CompilerBaselineRunner extends RunnerBase {
391391

392392
// this will set up a series of describe/it blocks to run between the setup and cleanup phases
393393
if (this.tests.length === 0) {
394-
var testFiles = this.enumerateFiles(this.basePath, /\.ts$/, { recursive: true });
394+
var testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true });
395395
testFiles.forEach(fn => {
396396
fn = fn.replace(/\\/g, "/");
397397
this.checkTestCodeOutput(fn);

src/harness/harness.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ module Utils {
212212
}
213213

214214
var result = "";
215-
ts.forEach(Object.getOwnPropertyNames(flags),(v: any) => {
215+
ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => {
216216
if (isFinite(v)) {
217217
v = +v;
218218
if (f === +v) {
@@ -410,7 +410,7 @@ module Harness {
410410
deleteFile(fileName: string): void;
411411
listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[];
412412
log(text: string): void;
413-
getMemoryUsage? (): number;
413+
getMemoryUsage?(): number;
414414
}
415415

416416
module IOImpl {
@@ -794,7 +794,7 @@ module Harness {
794794

795795
public reset() { this.fileCollection = {}; }
796796

797-
public toArray(): { fileName: string; file: WriterAggregator; }[]{
797+
public toArray(): { fileName: string; file: WriterAggregator; }[] {
798798
var result: { fileName: string; file: WriterAggregator; }[] = [];
799799
for (var p in this.fileCollection) {
800800
if (this.fileCollection.hasOwnProperty(p)) {
@@ -1166,6 +1166,12 @@ module Harness {
11661166
options.inlineSources = setting.value === 'true';
11671167
break;
11681168

1169+
case 'jsx':
1170+
options.jsx = setting.value.toLowerCase() === 'react' ? ts.JsxEmit.React :
1171+
setting.value.toLowerCase() === 'preserve' ? ts.JsxEmit.Preserve :
1172+
ts.JsxEmit.None;
1173+
break;
1174+
11691175
default:
11701176
throw new Error('Unsupported compiler setting ' + setting.flag);
11711177
}
@@ -1229,7 +1235,7 @@ module Harness {
12291235
}
12301236

12311237
var dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";
1232-
1238+
12331239
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
12341240
}
12351241

@@ -1428,13 +1434,20 @@ module Harness {
14281434
return stringEndsWith(fileName, '.ts');
14291435
}
14301436

1437+
export function isTSX(fileName: string) {
1438+
return stringEndsWith(fileName, '.tsx');
1439+
}
1440+
14311441
export function isDTS(fileName: string) {
14321442
return stringEndsWith(fileName, '.d.ts');
14331443
}
14341444

14351445
export function isJS(fileName: string) {
14361446
return stringEndsWith(fileName, '.js');
14371447
}
1448+
export function isJSX(fileName: string) {
1449+
return stringEndsWith(fileName, '.jsx');
1450+
}
14381451

14391452
export function isJSMap(fileName: string) {
14401453
return stringEndsWith(fileName, '.js.map');
@@ -1455,7 +1468,7 @@ module Harness {
14551468
if (isDTS(emittedFile.fileName)) {
14561469
// .d.ts file, add to declFiles emit
14571470
this.declFilesCode.push(emittedFile);
1458-
} else if (isJS(emittedFile.fileName)) {
1471+
} else if (isJS(emittedFile.fileName) || isJSX(emittedFile.fileName)) {
14591472
// .js file, add to files
14601473
this.files.push(emittedFile);
14611474
} else if (isJSMap(emittedFile.fileName)) {
@@ -1495,6 +1508,16 @@ module Harness {
14951508
// Regex for parsing options in the format "@Alpha: Value of any sort"
14961509
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
14971510

1511+
// List of allowed metadata names
1512+
var fileMetadataNames = ["filename", "comments", "declaration", "module",
1513+
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
1514+
"noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom",
1515+
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
1516+
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
1517+
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
1518+
"inlinesources", "emitdecoratormetadata", "experimentaldecorators",
1519+
"skipdefaultlibcheck", "jsx"];
1520+
14981521
function extractCompilerSettings(content: string): CompilerSetting[] {
14991522

15001523
var opts: CompilerSetting[] = [];

src/harness/runnerbase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RunnerBase {
2727
var fixedPath = path;
2828

2929
// full paths either start with a drive letter or / for *nix, shouldn't have \ in the path at this point
30-
var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.ts/g;
30+
var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.tsx?/g;
3131
var fullPathList = fixedPath.match(fullPath);
3232
if (fullPathList) {
3333
fullPathList.forEach((match: string) => fixedPath = fixedPath.replace(match, Harness.Path.getFileName(match)));

0 commit comments

Comments
 (0)