Skip to content

Commit 609d1bc

Browse files
author
Yui T
committed
Chage test framework from manual comparing the result to using baseline;
Add compilerOptions into fourslash
1 parent 6cba535 commit 609d1bc

File tree

3 files changed

+255
-42
lines changed

3 files changed

+255
-42
lines changed

src/harness/fourslash.ts

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ module FourSlash {
130130
outDir: 'outDir',
131131
declaration: 'declaration',
132132
sourceMap: 'sourceMap',
133-
sourceRoot: 'sourceRoot'
133+
sourceRoot: 'sourceRoot',
134+
mapRoot: 'mapRoot',
135+
module: 'module',
134136
};
135137

136138
// List of allowed metadata names
137139
var fileMetadataNames = ['Filename'];
138140
var globalMetadataNames = ['BaselineFile', compilerOptMetadataNames.out, compilerOptMetadataNames.outDir, compilerOptMetadataNames.declaration, compilerOptMetadataNames.outDir,
139-
compilerOptMetadataNames.declaration, compilerOptMetadataNames.sourceMap, compilerOptMetadataNames.sourceRoot]
141+
compilerOptMetadataNames.declaration, compilerOptMetadataNames.sourceMap, compilerOptMetadataNames.sourceRoot, compilerOptMetadataNames.mapRoot, compilerOptMetadataNames.module]
140142

141143
function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings {
142144
var settings: ts.CompilationSettings = {};
@@ -156,8 +158,26 @@ module FourSlash {
156158
case compilerOptMetadataNames.sourceMap:
157159
settings.mapSourceFiles = true;
158160
break;
159-
case compilerOptMetadataNames.sourceRoot:
160-
settings.sourceRoot = globalOptions[prop]
161+
case compilerOptMetadataNames.sourceRoot:
162+
settings.sourceRoot = globalOptions[prop];
163+
break;
164+
case compilerOptMetadataNames.mapRoot:
165+
settings.mapRoot = globalOptions[prop];
166+
break;
167+
case compilerOptMetadataNames.module:
168+
// create appropriate external module target for CompilationSettings
169+
switch (globalOptions[prop]) {
170+
case "AMD":
171+
settings.moduleGenTarget = ts.ModuleGenTarget.Asynchronous;
172+
break;
173+
case "CommonJS":
174+
settings.moduleGenTarget = ts.ModuleGenTarget.Synchronous;
175+
break;
176+
default:
177+
settings.moduleGenTarget = ts.ModuleGenTarget.Unspecified;
178+
break;
179+
}
180+
break;
161181
}
162182
}
163183
}
@@ -494,40 +514,6 @@ module FourSlash {
494514
}
495515
}
496516

497-
public verifyEmitOutput(state: ts.EmitReturnStatus, filename?: string) {
498-
var expectedFilenames:string[] = [];
499-
if (filename !== undefined) {
500-
expectedFilenames = filename.split(" ");
501-
}
502-
503-
var emit = this.languageService.getEmitOutput(this.activeFile.fileName);
504-
505-
if (emit.emitOutputStatus !== state) {
506-
throw new Error("Expected emitOutputResult '" + state + "', but actual emitOutputResult '" + emit.emitOutputStatus + "'");
507-
}
508-
509-
var passed = true;
510-
if (emit.outputFiles.length > 0) {
511-
passed = expectedFilenames.every(expectedFilename => {
512-
return emit.outputFiles.some(outputFile => {
513-
return outputFile.name === expectedFilename;
514-
});
515-
});
516-
}
517-
518-
if (!passed) {
519-
var errorMessage = "Expected outputFilename '" + filename + "', but actual outputFilename '";
520-
emit.outputFiles.forEach((outputFile, idx, array) => {
521-
errorMessage += outputFile.name;
522-
if (idx !== emit.outputFiles.length - 1) {
523-
errorMessage += " ";
524-
}
525-
});
526-
errorMessage += "'";
527-
throw new Error(errorMessage);
528-
}
529-
}
530-
531517
public verifyMemberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
532518
this.scenarioActions.push('<ShowCompletionList />');
533519
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
@@ -964,6 +950,54 @@ module FourSlash {
964950
true /* run immediately */);
965951
}
966952

953+
public baselineGetEmitOutput() {
954+
this.taoInvalidReason = 'baselineCurrentFileBreakpointLocations impossible';
955+
956+
Harness.Baseline.runBaseline(
957+
"Breakpoint Locations for " + this.activeFile.fileName,
958+
this.testData.globalOptions['BaselineFile'],
959+
() => {
960+
var emitOutput = this.languageService.getEmitOutput(this.activeFile.fileName);
961+
var emitOutputStatus = emitOutput.emitOutputStatus;
962+
var resultString = "";
963+
964+
// Print emitOutputStatus in readable format
965+
switch (emitOutputStatus) {
966+
case ts.EmitReturnStatus.Succeeded:
967+
resultString += "EmitOutputStatus : Succeeded\n";
968+
break;
969+
case ts.EmitReturnStatus.AllOutputGenerationSkipped:
970+
resultString += "EmitOutputStatus : AllOutputGenerationSkipped\n";
971+
break;
972+
case ts.EmitReturnStatus.JSGeneratedWithSemanticErrors:
973+
resultString += "EmitOutputStatus : JSGeneratedWithSemanticErrors\n";
974+
break;
975+
case ts.EmitReturnStatus.DeclarationGenerationSkipped:
976+
resultString += "EmitOutputStatus : DeclaratiionGenerationSkipped\n";
977+
break;
978+
case ts.EmitReturnStatus.EmitErrorsEncountered:
979+
resultString += "EmitOutputStatus : EmitErrorEncountered\n";
980+
break;
981+
default:
982+
resultString += "Invalid EmitOutputStatus\n";
983+
break;
984+
}
985+
986+
emitOutput.outputFiles.forEach((outputFile, idx, array) => {
987+
var filename = "Filename : " + outputFile.name + "\n";
988+
if (filename.match("/*.js.map/") === undefined) {
989+
var content = outputFile.text;
990+
}
991+
else {
992+
var content = outputFile.text + "\n";
993+
}
994+
resultString = resultString + filename + content + "\n";
995+
});
996+
return resultString;
997+
},
998+
true /* run immediately */);
999+
}
1000+
9671001
public printBreakpointLocation(pos: number) {
9681002
Harness.IO.log(this.getBreakpointStatementLocation(pos));
9691003
}

tests/cases/fourslash/fourslash.d.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
declare var FourSlash: any;
2+
declare enum IncrementalEditValidation {
3+
None,
4+
SyntacticOnly,
5+
Complete,
6+
}
7+
declare enum TypingFidelity {
8+
/** Performs typing and formatting (if formatting is enabled) */
9+
Low,
10+
/** Performs typing, checks completion lists, signature help, and formatting (if enabled) */
11+
High,
12+
}
13+
declare enum EmitReturnStatus {
14+
Succeeded = 0,
15+
AllOutputGenerationSkipped = 1,
16+
JSGeneratedWithSemanticErrors = 2,
17+
DeclarationGenerationSkipped = 3,
18+
EmitErrorsEncountered = 4,
19+
}
20+
declare module FourSlashInterface {
21+
interface Marker {
22+
fileName: string;
23+
position: number;
24+
data?: any;
25+
}
26+
interface Range {
27+
fileName: string;
28+
start: number;
29+
end: number;
30+
marker?: Marker;
31+
}
32+
interface TextSpan {
33+
start: number;
34+
end: number;
35+
}
36+
class test_ {
37+
markers(): Marker[];
38+
ranges(): Range[];
39+
}
40+
class diagnostics {
41+
validateTypeAtCurrentPosition(): any;
42+
validateTypesAtPositions(...positions: number[]): any;
43+
setEditValidation(validation: IncrementalEditValidation): void;
44+
setTypingFidelity(fidelity: TypingFidelity): void;
45+
}
46+
class goTo {
47+
marker(name?: string): void;
48+
bof(): void;
49+
eof(): void;
50+
definition(definitionIndex?: number): void;
51+
position(position: number, fileIndex?: number): any;
52+
position(position: number, fileName?: string): any;
53+
file(index: number): any;
54+
file(name: string): any;
55+
}
56+
class verifyNegatable {
57+
private negative;
58+
not: verifyNegatable;
59+
constructor(negative?: boolean);
60+
memberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string): void;
61+
memberListCount(expectedCount: number): void;
62+
completionListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string): void;
63+
completionListItemsCountIsGreaterThan(count: number): void;
64+
completionListIsEmpty(): void;
65+
memberListIsEmpty(): void;
66+
referencesCountIs(count: number): void;
67+
referencesAtPositionContains(range: Range, isWriteAccess?: boolean): void;
68+
implementorsCountIs(count: number): void;
69+
currentParameterIsVariable(): void;
70+
signatureHelpPresent(): void;
71+
errorExistsBetweenMarkers(startMarker: string, endMarker: string): void;
72+
errorExistsAfterMarker(markerName?: string): void;
73+
errorExistsBeforeMarker(markerName?: string): void;
74+
quickInfoIs(typeName?: string, docComment?: string, symbolName?: string, kind?: string): void;
75+
quickInfoSymbolNameIs(symbolName: any): void;
76+
quickInfoExists(): void;
77+
definitionLocationExists(): void;
78+
}
79+
class verify extends verifyNegatable {
80+
caretAtMarker(markerName?: string): void;
81+
indentationIs(numberOfSpaces: number): void;
82+
indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number): void;
83+
textAtCaretIs(text: string): void;
84+
/**
85+
Compiles the current file and evaluates 'expr' in a context containing
86+
the emitted output, then compares (using ===) the result of that expression
87+
to 'value'. Do not use this function with external modules as it is not supported.
88+
*/
89+
eval(expr: string, value: any): void;
90+
emitOutput(expectedState: EmitReturnStatus, expectedFilename?: string): void;
91+
currentLineContentIs(text: string): void;
92+
currentFileContentIs(text: string): void;
93+
currentParameterHelpArgumentNameIs(name: string): void;
94+
currentParameterSpanIs(parameter: string): void;
95+
currentParameterHelpArgumentDocCommentIs(docComment: string): void;
96+
currentSignatureHelpDocCommentIs(docComment: string): void;
97+
signatureHelpCountIs(expected: number): void;
98+
currentSignatureParamterCountIs(expected: number): void;
99+
currentSignatureTypeParamterCountIs(expected: number): void;
100+
currentSignatureHelpIs(expected: string): void;
101+
numberOfErrorsInCurrentFile(expected: number): void;
102+
baselineCurrentFileBreakpointLocations(): void;
103+
baselineCurrentFileNameOrDottedNameSpans(): void;
104+
nameOrDottedNameSpanTextIs(text: string): void;
105+
outliningSpansInCurrentFile(spans: TextSpan[]): void;
106+
todoCommentsInCurrentFile(descriptors: string[]): void;
107+
matchingBracePositionInCurrentFile(bracePosition: number, expectedMatchPosition: number): void;
108+
noMatchingBracePositionInCurrentFile(bracePosition: number): void;
109+
setVerifyDocComments(val: boolean): void;
110+
getScriptLexicalStructureListCount(count: number): void;
111+
getScriptLexicalStructureListContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): void;
112+
navigationItemsListCount(count: number, searchValue: string, matchKind?: string): void;
113+
navigationItemsListContains(name: string, kind: string, searchValue: string, matchKind: string, fileName?: string, parenetName?: string): void;
114+
occurrencesAtPositionContains(range: Range, isWriteAccess?: boolean): void;
115+
occurrencesAtPositionCount(expectedCount: number): void;
116+
completionEntryDetailIs(entryName: string, type: string, docComment?: string, fullSymbolName?: string, kind?: string): void;
117+
}
118+
class edit {
119+
backspace(count?: number): void;
120+
deleteAtCaret(times?: number): void;
121+
replace(start: number, length: number, text: string): void;
122+
paste(text: string): void;
123+
insert(text: string): void;
124+
insertLine(text: string): void;
125+
insertLines(...lines: string[]): void;
126+
moveRight(count?: number): void;
127+
moveLeft(count?: number): void;
128+
enableFormatting(): void;
129+
disableFormatting(): void;
130+
}
131+
class debug {
132+
printCurrentParameterHelp(): void;
133+
printCurrentFileState(): void;
134+
printCurrentFileStateWithWhitespace(): void;
135+
printCurrentFileStateWithoutCaret(): void;
136+
printCurrentQuickInfo(): void;
137+
printCurrentSignatureHelp(): void;
138+
printMemberListMembers(): void;
139+
printCompletionListMembers(): void;
140+
printBreakpointLocation(pos: number): void;
141+
printBreakpointAtCurrentLocation(): void;
142+
printNameOrDottedNameSpans(pos: number): void;
143+
printErrorList(): void;
144+
printNavigationItems(searchValue?: string): void;
145+
printScriptLexicalStructureItems(): void;
146+
printReferences(): void;
147+
printContext(): void;
148+
}
149+
class format {
150+
document(): void;
151+
selection(startMarker: string, endMarker: string): void;
152+
setOption(name: string, value: number): any;
153+
setOption(name: string, value: string): any;
154+
setOption(name: string, value: boolean): any;
155+
}
156+
class cancellation {
157+
resetCancelled(): void;
158+
setCancelled(numberOfCalls?: number): void;
159+
}
160+
}
161+
declare module fs {
162+
var test: FourSlashInterface.test_;
163+
var goTo: FourSlashInterface.goTo;
164+
var verify: FourSlashInterface.verify;
165+
var edit: FourSlashInterface.edit;
166+
var debug: FourSlashInterface.debug;
167+
var format: FourSlashInterface.format;
168+
var diagnostics: FourSlashInterface.diagnostics;
169+
var cancellation: FourSlashInterface.cancellation;
170+
}
171+
declare function verifyOperationIsCancelled(f: any): void;
172+
declare var test: FourSlashInterface.test_;
173+
declare var goTo: FourSlashInterface.goTo;
174+
declare var verify: FourSlashInterface.verify;
175+
declare var edit: FourSlashInterface.edit;
176+
declare var debug: FourSlashInterface.debug;
177+
declare var format: FourSlashInterface.format;
178+
declare var diagnostics: FourSlashInterface.diagnostics;
179+
declare var cancellation: FourSlashInterface.cancellation;

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ module FourSlashInterface {
266266
FourSlash.currentTestState.verifyEval(expr, value);
267267
}
268268

269-
public emitOutput(expectedState: EmitReturnStatus, expectedFilename?: string) {
270-
FourSlash.currentTestState.verifyEmitOutput(expectedState, expectedFilename);
271-
}
272-
273269
public currentLineContentIs(text: string) {
274270
FourSlash.currentTestState.verifyCurrentLineContent(text);
275271
}
@@ -322,6 +318,10 @@ module FourSlashInterface {
322318
FourSlash.currentTestState.baselineCurrentFileNameOrDottedNameSpans();
323319
}
324320

321+
public baselineGetEmitOutput() {
322+
FourSlash.currentTestState.baselineGetEmitOutput();
323+
}
324+
325325
public nameOrDottedNameSpanTextIs(text: string) {
326326
FourSlash.currentTestState.verifyCurrentNameOrDottedNameSpanText(text);
327327
}

0 commit comments

Comments
 (0)