@@ -98,35 +98,48 @@ namespace ts {
9898 }
9999
100100 export function testExtractSymbol ( caption : string , text : string , baselineFolder : string , description : DiagnosticMessage ) {
101- it ( caption , ( ) => {
102- Harness . Baseline . runBaseline ( `${ baselineFolder } /${ caption } .ts` , ( ) => {
103- const t = extractTest ( text ) ;
104- const selectionRange = t . ranges . get ( "selection" ) ;
105- if ( ! selectionRange ) {
106- throw new Error ( `Test ${ caption } does not specify selection range` ) ;
107- }
108- const f = {
109- path : "/a.ts" ,
110- content : t . source
111- } ;
112- const host = projectSystem . createServerHost ( [ f , projectSystem . libFile ] ) ;
113- const projectService = projectSystem . createProjectService ( host ) ;
114- projectService . openClientFile ( f . path ) ;
115- const program = projectService . inferredProjects [ 0 ] . getLanguageService ( ) . getProgram ( ) ;
116- const sourceFile = program . getSourceFile ( f . path ) ;
117- const context : RefactorContext = {
118- cancellationToken : { throwIfCancellationRequested ( ) { } , isCancellationRequested ( ) { return false ; } } ,
119- newLineCharacter,
120- program,
121- file : sourceFile ,
122- startPosition : selectionRange . start ,
123- endPosition : selectionRange . end ,
124- rulesProvider : getRuleProvider ( )
125- } ;
126- const rangeToExtract = refactor . extractSymbol . getRangeToExtract ( sourceFile , createTextSpanFromBounds ( selectionRange . start , selectionRange . end ) ) ;
127- assert . equal ( rangeToExtract . errors , undefined , rangeToExtract . errors && "Range error: " + rangeToExtract . errors [ 0 ] . messageText ) ;
128- const infos = refactor . extractSymbol . getAvailableActions ( context ) ;
129- const actions = find ( infos , info => info . description === description . message ) . actions ;
101+ const t = extractTest ( text ) ;
102+ const selectionRange = t . ranges . get ( "selection" ) ;
103+ if ( ! selectionRange ) {
104+ throw new Error ( `Test ${ caption } does not specify selection range` ) ;
105+ }
106+
107+ [ Extension . Ts , Extension . Js ] . forEach ( extension =>
108+ it ( `${ caption } [${ extension } ]` , ( ) => runBaseline ( extension ) ) ) ;
109+
110+ function runBaseline ( extension : Extension ) {
111+ const f = {
112+ path : "/a" + extension ,
113+ content : t . source
114+ } ;
115+ const host = projectSystem . createServerHost ( [ f , projectSystem . libFile ] ) ;
116+ const projectService = projectSystem . createProjectService ( host ) ;
117+ projectService . openClientFile ( f . path ) ;
118+ const program = projectService . inferredProjects [ 0 ] . getLanguageService ( ) . getProgram ( ) ;
119+
120+ // Don't bother generating JS baselines for inputs that aren't valid JS.
121+ const diags = program . getSyntacticDiagnostics ( ) ;
122+ if ( diags && diags . length ) {
123+ assert . equal ( Extension . Js , extension ) ;
124+ return ;
125+ }
126+
127+ const sourceFile = program . getSourceFile ( f . path ) ;
128+ const context : RefactorContext = {
129+ cancellationToken : { throwIfCancellationRequested ( ) { } , isCancellationRequested ( ) { return false ; } } ,
130+ newLineCharacter,
131+ program,
132+ file : sourceFile ,
133+ startPosition : selectionRange . start ,
134+ endPosition : selectionRange . end ,
135+ rulesProvider : getRuleProvider ( )
136+ } ;
137+ const rangeToExtract = refactor . extractSymbol . getRangeToExtract ( sourceFile , createTextSpanFromBounds ( selectionRange . start , selectionRange . end ) ) ;
138+ assert . equal ( rangeToExtract . errors , undefined , rangeToExtract . errors && "Range error: " + rangeToExtract . errors [ 0 ] . messageText ) ;
139+ const infos = refactor . extractSymbol . getAvailableActions ( context ) ;
140+ const actions = find ( infos , info => info . description === description . message ) . actions ;
141+
142+ Harness . Baseline . runBaseline ( `${ baselineFolder } /${ caption } ${ extension } ` , ( ) => {
130143 const data : string [ ] = [ ] ;
131144 data . push ( `// ==ORIGINAL==` ) ;
132145 data . push ( sourceFile . text ) ;
@@ -140,7 +153,7 @@ namespace ts {
140153 }
141154 return data . join ( newLineCharacter ) ;
142155 } ) ;
143- } ) ;
156+ }
144157 }
145158
146159 export function testExtractSymbolFailed ( caption : string , text : string , description : DiagnosticMessage ) {
0 commit comments