@@ -275,11 +275,26 @@ module FourSlash {
275275 }
276276 }
277277
278- constructor ( public testData : FourSlashData ) {
278+ private getLanguageServiceAdaptor ( testType : FourSlashTestType ) :
279+ { new ( cancellationToken ?: ts . CancellationToken , options ?: ts . CompilerOptions ) : Harness . LanguageService . LanguageServiceAdaptor } {
280+ switch ( testType ) {
281+ case FourSlashTestType . Native :
282+ return Harness . LanguageService . NativeLanugageServiceAdaptor ;
283+ break ;
284+ case FourSlashTestType . Shims :
285+ return Harness . LanguageService . ShimLanugageServiceAdaptor ;
286+ break ;
287+ default :
288+ throw new Error ( "Unknown FourSlash test type: " ) ;
289+ }
290+ }
291+
292+ constructor ( private basePath : string , private testType : FourSlashTestType , public testData : FourSlashData ) {
279293 // Create a new Services Adaptor
280294 this . cancellationToken = new TestCancellationToken ( ) ;
281295 var compilationOptions = convertGlobalOptionsToCompilerOptions ( this . testData . globalOptions ) ;
282- var languageServiceAdaptor = new Harness . LanguageService . NativeLanugageServiceAdaptor ( this . cancellationToken , compilationOptions ) ;
296+ var languageserviceAdaptorFactory = this . getLanguageServiceAdaptor ( testType ) ;
297+ var languageServiceAdaptor = new languageserviceAdaptorFactory ( this . cancellationToken , compilationOptions ) ;
283298 this . languageServiceAdaptorHost = languageServiceAdaptor . getHost ( ) ;
284299 this . languageService = languageServiceAdaptor . getLanguageService ( ) ;
285300
@@ -308,15 +323,15 @@ module FourSlash {
308323 // Add triple reference files into language-service host
309324 ts . forEach ( referencedFiles , referenceFile => {
310325 // Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path
311- var referenceFilePath = "tests/cases/fourslash/" + referenceFile . filename ;
326+ var referenceFilePath = this . basePath + '/' + referenceFile . filename ;
312327 this . addMatchedInputFile ( referenceFilePath ) ;
313328 } ) ;
314329
315330 // Add import files into language-service host
316331 ts . forEach ( importedFiles , importedFile => {
317332 // Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts"
318333 // so convert them before making appropriate comparison
319- var importedFilePath = "tests/cases/fourslash/" + importedFile . filename + ".ts" ;
334+ var importedFilePath = this . basePath + '/' + importedFile . filename + ".ts" ;
320335 this . addMatchedInputFile ( importedFilePath ) ;
321336 } ) ;
322337
@@ -1382,6 +1397,12 @@ module FourSlash {
13821397 }
13831398
13841399 private checkPostEditInvariants ( ) {
1400+ if ( this . testType !== FourSlashTestType . Native ) {
1401+ // getSourcefile() results can not be serialized. Only perform these verifications
1402+ // if running against a native LS object.
1403+ return ;
1404+ }
1405+
13851406 var incrementalSourceFile = this . languageService . getSourceFile ( this . activeFile . fileName ) ;
13861407 Utils . assertInvariants ( incrementalSourceFile , /*parent:*/ undefined ) ;
13871408
@@ -2052,7 +2073,7 @@ module FourSlash {
20522073 } else if ( typeof indexOrName === 'string' ) {
20532074 var name = < string > indexOrName ;
20542075 // names are stored in the compiler with this relative path, this allows people to use goTo.file on just the filename
2055- name = name . indexOf ( '/' ) === - 1 ? 'tests/cases/fourslash/' + name : name ;
2076+ name = name . indexOf ( '/' ) === - 1 ? ( this . basePath + '/' + name ) : name ;
20562077 var availableNames : string [ ] = [ ] ;
20572078 var foundIt = false ;
20582079 for ( var i = 0 ; i < this . testData . files . length ; i ++ ) {
@@ -2118,17 +2139,17 @@ module FourSlash {
21182139 var fsOutput = new Harness . Compiler . WriterAggregator ( ) ;
21192140 var fsErrors = new Harness . Compiler . WriterAggregator ( ) ;
21202141 export var xmlData : TestXmlData [ ] = [ ] ;
2121- export function runFourSlashTest ( fileName : string ) {
2142+ export function runFourSlashTest ( basePath : string , testType : FourSlashTestType , fileName : string ) {
21222143 var content = Harness . IO . readFile ( fileName ) ;
2123- var xml = runFourSlashTestContent ( content , fileName ) ;
2144+ var xml = runFourSlashTestContent ( basePath , testType , content , fileName ) ;
21242145 xmlData . push ( xml ) ;
21252146 }
21262147
2127- export function runFourSlashTestContent ( content : string , fileName : string ) : TestXmlData {
2148+ export function runFourSlashTestContent ( basePath : string , testType : FourSlashTestType , content : string , fileName : string ) : TestXmlData {
21282149 // Parse out the files and their metadata
2129- var testData = parseTestData ( content , fileName ) ;
2150+ var testData = parseTestData ( basePath , content , fileName ) ;
21302151
2131- currentTestState = new TestState ( testData ) ;
2152+ currentTestState = new TestState ( basePath , testType , testData ) ;
21322153
21332154 var result = '' ;
21342155 var host = Harness . Compiler . createCompilerHost ( [ { unitName : Harness . Compiler . fourslashFilename , content : undefined } ,
@@ -2171,7 +2192,7 @@ module FourSlash {
21712192 return lines . map ( s => s . substr ( 1 ) ) . join ( '\n' ) ;
21722193 }
21732194
2174- function parseTestData ( contents : string , fileName : string ) : FourSlashData {
2195+ function parseTestData ( basePath : string , contents : string , fileName : string ) : FourSlashData {
21752196 // Regex for parsing options in the format "@Alpha: Value of any sort"
21762197 var optionRegex = / ^ \s * @ ( \w + ) : ( .* ) \s * / ;
21772198
@@ -2239,7 +2260,7 @@ module FourSlash {
22392260 currentFileName = fileName ;
22402261 }
22412262
2242- currentFileName = 'tests/cases/fourslash /' + match [ 2 ] ;
2263+ currentFileName = basePath + ' /' + match [ 2 ] ;
22432264 currentFileOptions [ match [ 1 ] ] = match [ 2 ] ;
22442265 } else {
22452266 // Add other fileMetadata flag
0 commit comments