mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Update fourslash for getEmitOutput
This commit is contained in:
@@ -189,6 +189,15 @@ module FourSlash {
|
||||
// Whether or not we should format on keystrokes
|
||||
public enableFormatting = true;
|
||||
|
||||
// Whether or not to generate .d.ts file
|
||||
public enableDeclaration = false;
|
||||
|
||||
// Whether or not to generate one output javascript file
|
||||
public enableSingleOutputFile = false;
|
||||
|
||||
// Output filename for single-output-file option
|
||||
public singleOutputFilename: string = undefined;
|
||||
|
||||
public formatCodeOptions: ts.FormatCodeOptions;
|
||||
|
||||
public cancellationToken: TestCancellationToken;
|
||||
@@ -452,6 +461,48 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyEmitOutput(state: ts.EmitOutputResult, filename?: string) {
|
||||
if (this.enableDeclaration) {
|
||||
this.languageServiceShimHost.setCompilationSettings({generateDeclarationFiles: true});
|
||||
}
|
||||
|
||||
if (this.enableSingleOutputFile) {
|
||||
this.languageServiceShimHost.setCompilationSettings({ outFileOption: this.singleOutputFilename });
|
||||
}
|
||||
|
||||
var expectedFilenames:string[] = [];
|
||||
if (filename !== undefined) {
|
||||
expectedFilenames = filename.split(" ");
|
||||
}
|
||||
|
||||
var emit = this.languageService.getEmitOutput(this.activeFile.fileName);
|
||||
|
||||
if (emit.emitOutputResult !== state) {
|
||||
throw new Error("Expected emitOutputResult '" + state + "', but actual emitOutputResult '" + emit.emitOutputResult + "'");
|
||||
}
|
||||
|
||||
var passed = true;
|
||||
if (emit.outputFiles.length > 0) {
|
||||
passed = expectedFilenames.every(expectedFilename => {
|
||||
return emit.outputFiles.some(outputFile => {
|
||||
return outputFile.name === expectedFilename;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
var errorMessage = "Expected outputFilename '" + filename + "', but actualy outputFilename '";
|
||||
emit.outputFiles.forEach((outputFile, idx, array) => {
|
||||
errorMessage += outputFile.name;
|
||||
if (idx !== emit.outputFiles.length - 1) {
|
||||
errorMessage += " ";
|
||||
}
|
||||
});
|
||||
errorMessage += "'";
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyMemberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
|
||||
this.scenarioActions.push('<ShowCompletionList />');
|
||||
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
|
||||
|
||||
@@ -135,6 +135,8 @@ module Harness.LanguageService {
|
||||
|
||||
private fileNameToScript: ts.Map<ScriptInfo> = {};
|
||||
|
||||
private settings: any = {};
|
||||
|
||||
constructor(private cancellationToken: ts.CancellationToken = CancellationToken.None) {
|
||||
}
|
||||
|
||||
@@ -179,6 +181,14 @@ module Harness.LanguageService {
|
||||
throw new Error("No script with name '" + fileName + "'");
|
||||
}
|
||||
|
||||
public getDefaultLibFilename(): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getCurrentDirectory(): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ILogger implementation
|
||||
//
|
||||
@@ -199,7 +209,7 @@ module Harness.LanguageService {
|
||||
|
||||
/// Returns json for Tools.CompilationSettings
|
||||
public getCompilationSettings(): string {
|
||||
return JSON.stringify({}); // i.e. default settings
|
||||
return JSON.stringify(this.settings);
|
||||
}
|
||||
|
||||
public getCancellationToken(): ts.CancellationToken {
|
||||
@@ -236,6 +246,12 @@ module Harness.LanguageService {
|
||||
return this.ls;
|
||||
}
|
||||
|
||||
public setCompilationSettings(settings: any) {
|
||||
for (var key in settings) {
|
||||
this.settings[key] = settings[key];
|
||||
}
|
||||
}
|
||||
|
||||
/** Return a new instance of the classifier service shim */
|
||||
public getClassifier(): ts.ClassifierShim {
|
||||
return new TypeScript.Services.TypeScriptServicesFactory().createClassifierShim(this);
|
||||
|
||||
@@ -226,7 +226,7 @@ class ProjectRunner extends RunnerBase {
|
||||
? filename
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename);
|
||||
|
||||
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory(), false);
|
||||
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory, false);
|
||||
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
|
||||
// If the generated output file recides in the parent folder or is rooted path,
|
||||
// we need to instead create files that can live in the project reference folder
|
||||
|
||||
Reference in New Issue
Block a user