Add source maps and declarations to test

This commit is contained in:
Andy Hanson 2016-11-07 07:14:47 -08:00
parent 0b71df5099
commit 07630e95e0
6 changed files with 81 additions and 15 deletions

View file

@ -170,7 +170,7 @@ class CompilerBaselineRunner extends RunnerBase {
});
it("Correct Sourcemap output for " + fileName, () => {
Harness.Compiler.doSourcemapBaseline(justName, options, result);
Harness.Compiler.doSourcemapBaseline(justName, options, result, harnessSettings);
});
it("Correct type/symbol baselines for " + fileName, () => {

View file

@ -1554,7 +1554,7 @@ namespace Harness {
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
}
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult) {
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) {
if (options.inlineSourceMap) {
if (result.sourceMaps.length > 0) {
throw new Error("No sourcemap files should be generated if inlineSourceMaps was set.");
@ -1576,10 +1576,8 @@ namespace Harness {
}
let sourceMapCode = "";
for (let i = 0; i < result.sourceMaps.length; i++) {
sourceMapCode += "//// [" + ts.getBaseFileName(result.sourceMaps[i].fileName) + "]\r\n";
sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]);
sourceMapCode += result.sourceMaps[i].code;
for (const sourceMap of result.sourceMaps) {
sourceMapCode += fileOutput(sourceMap, harnessSettings);
}
return sourceMapCode;
@ -1606,18 +1604,13 @@ namespace Harness {
let jsCode = "";
for (const file of result.files) {
const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
jsCode += "//// [" + fileName + "]\r\n";
jsCode += getByteOrderMarkText(file);
jsCode += file.code;
jsCode += fileOutput(file, harnessSettings);
}
if (result.declFilesCode.length > 0) {
jsCode += "\r\n\r\n";
for (let i = 0; i < result.declFilesCode.length; i++) {
jsCode += "//// [" + ts.getBaseFileName(result.declFilesCode[i].fileName) + "]\r\n";
jsCode += getByteOrderMarkText(result.declFilesCode[i]);
jsCode += result.declFilesCode[i].code;
for (const declFile of result.declFilesCode) {
jsCode += fileOutput(declFile, harnessSettings);
}
}
@ -1642,6 +1635,11 @@ namespace Harness {
});
}
function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code;
}
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string {
// Collect, test, and sort the fileNames
outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName)));

View file

@ -23,3 +23,7 @@ x + y;
var foo_1 = require("foo");
var bar_1 = require("bar");
foo_1.x + bar_1.y;
//# sourceMappingURL=/app/myMapRoot/index.js.map
//// [/app/bin/index.d.ts]
/// <reference path="../../types/bar.d.ts" />

View file

@ -0,0 +1,2 @@
//// [/app/bin/index.js.map]
{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,2BAAwB;AACxB,2BAAwB;AACxB,OAAC,GAAG,OAAC,CAAC"}

View file

@ -0,0 +1,58 @@
===================================================================
JsFile: index.js
mapUrl: /app/myMapRoot/index.js.map
sourceRoot: /app/mySourceRoot/
sources: index.ts
===================================================================
-------------------------------------------------------------------
emittedFile:/app/bin/index.js
sourceFile:index.ts
-------------------------------------------------------------------
>>>"use strict";
>>>/// <reference path="../types/bar.d.ts"/>
1 >
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 >
2 >/// <reference path="../types/bar.d.ts"/>
1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(2, 42) Source(1, 42) + SourceIndex(0)
---
>>>var foo_1 = require("foo");
1 >
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 > ^->
1 >
>
2 >import { x } from "foo";
1 >Emitted(3, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(3, 28) Source(2, 25) + SourceIndex(0)
---
>>>var bar_1 = require("bar");
1->
2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^
1->
>
2 >import { y } from "bar";
1->Emitted(4, 1) Source(3, 1) + SourceIndex(0)
2 >Emitted(4, 28) Source(3, 25) + SourceIndex(0)
---
>>>foo_1.x + bar_1.y;
1 >
2 >^^^^^^^
3 > ^^^
4 > ^^^^^^^
5 > ^
6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>
2 >x
3 > +
4 > y
5 > ;
1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0)
2 >Emitted(5, 8) Source(4, 2) + SourceIndex(0)
3 >Emitted(5, 11) Source(4, 5) + SourceIndex(0)
4 >Emitted(5, 18) Source(4, 6) + SourceIndex(0)
5 >Emitted(5, 19) Source(4, 7) + SourceIndex(0)
---
>>>//# sourceMappingURL=/app/myMapRoot/index.js.map

View file

@ -21,6 +21,10 @@ x + y;
{
"compilerOptions": {
"outDir": "bin",
"typeRoots": ["../types"]
"typeRoots": ["../types"],
"sourceMap": true,
"mapRoot": "myMapRoot",
"sourceRoot": "mySourceRoot",
"declaration": true
}
}