Test support for TSX files
This commit is contained in:
parent
6d01a44be0
commit
e34d8cdccb
3 changed files with 37 additions and 14 deletions
|
@ -149,7 +149,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||||
// check errors
|
// check errors
|
||||||
it('Correct errors for ' + fileName, () => {
|
it('Correct errors for ' + fileName, () => {
|
||||||
if (this.errors) {
|
if (this.errors) {
|
||||||
Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => {
|
Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.tsx?$/, '.errors.txt'), (): string => {
|
||||||
if (result.errors.length === 0) return null;
|
if (result.errors.length === 0) return null;
|
||||||
return getErrorBaseline(toBeCompiled, otherFiles, result);
|
return getErrorBaseline(toBeCompiled, otherFiles, result);
|
||||||
});
|
});
|
||||||
|
@ -159,7 +159,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||||
// Source maps?
|
// Source maps?
|
||||||
it('Correct sourcemap content for ' + fileName, () => {
|
it('Correct sourcemap content for ' + fileName, () => {
|
||||||
if (options.sourceMap || options.inlineSourceMap) {
|
if (options.sourceMap || options.inlineSourceMap) {
|
||||||
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => {
|
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.tsx?$/, '.sourcemap.txt'), () => {
|
||||||
var record = result.getSourceMapRecord();
|
var record = result.getSourceMapRecord();
|
||||||
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
|
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
|
||||||
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
|
// 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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check js output
|
// check js output
|
||||||
Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.ts/, '.js'), () => {
|
Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.tsx?/, '.js'), () => {
|
||||||
var tsCode = '';
|
var tsCode = '';
|
||||||
var tsSources = otherFiles.concat(toBeCompiled);
|
var tsSources = otherFiles.concat(toBeCompiled);
|
||||||
if (tsSources.length > 1) {
|
if (tsSources.length > 1) {
|
||||||
|
@ -235,7 +235,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||||
throw new Error('Number of sourcemap files should be same as js files.');
|
throw new Error('Number of sourcemap files should be same as js files.');
|
||||||
}
|
}
|
||||||
|
|
||||||
Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => {
|
Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.tsx?/, '.js.map'), () => {
|
||||||
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
|
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
|
||||||
// We need to return null here or the runBaseLine will actually create a empty file.
|
// We need to return null here or the runBaseLine will actually create a empty file.
|
||||||
// Baselining isn't required here because there is no output.
|
// Baselining isn't required here because there is no output.
|
||||||
|
@ -320,11 +320,11 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||||
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';
|
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';
|
||||||
|
|
||||||
if (fullBaseLine !== pullBaseLine) {
|
if (fullBaseLine !== pullBaseLine) {
|
||||||
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
|
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
|
||||||
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine);
|
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
|
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||||
|
|
||||||
// this will set up a series of describe/it blocks to run between the setup and cleanup phases
|
// this will set up a series of describe/it blocks to run between the setup and cleanup phases
|
||||||
if (this.tests.length === 0) {
|
if (this.tests.length === 0) {
|
||||||
var testFiles = this.enumerateFiles(this.basePath, /\.ts$/, { recursive: true });
|
var testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true });
|
||||||
testFiles.forEach(fn => {
|
testFiles.forEach(fn => {
|
||||||
fn = fn.replace(/\\/g, "/");
|
fn = fn.replace(/\\/g, "/");
|
||||||
this.checkTestCodeOutput(fn);
|
this.checkTestCodeOutput(fn);
|
||||||
|
|
|
@ -212,7 +212,7 @@ module Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = "";
|
var result = "";
|
||||||
ts.forEach(Object.getOwnPropertyNames(flags),(v: any) => {
|
ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => {
|
||||||
if (isFinite(v)) {
|
if (isFinite(v)) {
|
||||||
v = +v;
|
v = +v;
|
||||||
if (f === +v) {
|
if (f === +v) {
|
||||||
|
@ -410,7 +410,7 @@ module Harness {
|
||||||
deleteFile(fileName: string): void;
|
deleteFile(fileName: string): void;
|
||||||
listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[];
|
listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[];
|
||||||
log(text: string): void;
|
log(text: string): void;
|
||||||
getMemoryUsage? (): number;
|
getMemoryUsage?(): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
module IOImpl {
|
module IOImpl {
|
||||||
|
@ -794,7 +794,7 @@ module Harness {
|
||||||
|
|
||||||
public reset() { this.fileCollection = {}; }
|
public reset() { this.fileCollection = {}; }
|
||||||
|
|
||||||
public toArray(): { fileName: string; file: WriterAggregator; }[]{
|
public toArray(): { fileName: string; file: WriterAggregator; }[] {
|
||||||
var result: { fileName: string; file: WriterAggregator; }[] = [];
|
var result: { fileName: string; file: WriterAggregator; }[] = [];
|
||||||
for (var p in this.fileCollection) {
|
for (var p in this.fileCollection) {
|
||||||
if (this.fileCollection.hasOwnProperty(p)) {
|
if (this.fileCollection.hasOwnProperty(p)) {
|
||||||
|
@ -1166,6 +1166,12 @@ module Harness {
|
||||||
options.inlineSources = setting.value === 'true';
|
options.inlineSources = setting.value === 'true';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'jsx':
|
||||||
|
options.jsx = setting.value.toLowerCase() === 'react' ? ts.JsxEmit.React :
|
||||||
|
setting.value.toLowerCase() === 'preserve' ? ts.JsxEmit.Preserve :
|
||||||
|
ts.JsxEmit.None;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Unsupported compiler setting ' + setting.flag);
|
throw new Error('Unsupported compiler setting ' + setting.flag);
|
||||||
}
|
}
|
||||||
|
@ -1428,6 +1434,10 @@ module Harness {
|
||||||
return stringEndsWith(fileName, '.ts');
|
return stringEndsWith(fileName, '.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isTSX(fileName: string) {
|
||||||
|
return stringEndsWith(fileName, '.tsx');
|
||||||
|
}
|
||||||
|
|
||||||
export function isDTS(fileName: string) {
|
export function isDTS(fileName: string) {
|
||||||
return stringEndsWith(fileName, '.d.ts');
|
return stringEndsWith(fileName, '.d.ts');
|
||||||
}
|
}
|
||||||
|
@ -1435,6 +1445,9 @@ module Harness {
|
||||||
export function isJS(fileName: string) {
|
export function isJS(fileName: string) {
|
||||||
return stringEndsWith(fileName, '.js');
|
return stringEndsWith(fileName, '.js');
|
||||||
}
|
}
|
||||||
|
export function isJSX(fileName: string) {
|
||||||
|
return stringEndsWith(fileName, '.jsx');
|
||||||
|
}
|
||||||
|
|
||||||
export function isJSMap(fileName: string) {
|
export function isJSMap(fileName: string) {
|
||||||
return stringEndsWith(fileName, '.js.map');
|
return stringEndsWith(fileName, '.js.map');
|
||||||
|
@ -1455,7 +1468,7 @@ module Harness {
|
||||||
if (isDTS(emittedFile.fileName)) {
|
if (isDTS(emittedFile.fileName)) {
|
||||||
// .d.ts file, add to declFiles emit
|
// .d.ts file, add to declFiles emit
|
||||||
this.declFilesCode.push(emittedFile);
|
this.declFilesCode.push(emittedFile);
|
||||||
} else if (isJS(emittedFile.fileName)) {
|
} else if (isJS(emittedFile.fileName) || isJSX(emittedFile.fileName)) {
|
||||||
// .js file, add to files
|
// .js file, add to files
|
||||||
this.files.push(emittedFile);
|
this.files.push(emittedFile);
|
||||||
} else if (isJSMap(emittedFile.fileName)) {
|
} else if (isJSMap(emittedFile.fileName)) {
|
||||||
|
@ -1495,6 +1508,16 @@ module Harness {
|
||||||
// Regex for parsing options in the format "@Alpha: Value of any sort"
|
// Regex for parsing options in the format "@Alpha: Value of any sort"
|
||||||
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
|
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
|
||||||
|
|
||||||
|
// List of allowed metadata names
|
||||||
|
var fileMetadataNames = ["filename", "comments", "declaration", "module",
|
||||||
|
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
|
||||||
|
"noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom",
|
||||||
|
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
|
||||||
|
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
|
||||||
|
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
|
||||||
|
"inlinesources", "emitdecoratormetadata", "experimentaldecorators",
|
||||||
|
"skipdefaultlibcheck", "jsx"];
|
||||||
|
|
||||||
function extractCompilerSettings(content: string): CompilerSetting[] {
|
function extractCompilerSettings(content: string): CompilerSetting[] {
|
||||||
|
|
||||||
var opts: CompilerSetting[] = [];
|
var opts: CompilerSetting[] = [];
|
||||||
|
|
|
@ -27,7 +27,7 @@ class RunnerBase {
|
||||||
var fixedPath = path;
|
var fixedPath = path;
|
||||||
|
|
||||||
// full paths either start with a drive letter or / for *nix, shouldn't have \ in the path at this point
|
// full paths either start with a drive letter or / for *nix, shouldn't have \ in the path at this point
|
||||||
var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.ts/g;
|
var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.tsx?/g;
|
||||||
var fullPathList = fixedPath.match(fullPath);
|
var fullPathList = fixedPath.match(fullPath);
|
||||||
if (fullPathList) {
|
if (fullPathList) {
|
||||||
fullPathList.forEach((match: string) => fixedPath = fixedPath.replace(match, Harness.Path.getFileName(match)));
|
fullPathList.forEach((match: string) => fixedPath = fixedPath.replace(match, Harness.Path.getFileName(match)));
|
||||||
|
|
Loading…
Reference in a new issue