diff --git a/scripts/jest/ts-preprocessor.js b/scripts/jest/ts-preprocessor.js index bed9f1c4d2..ec10c03109 100644 --- a/scripts/jest/ts-preprocessor.js +++ b/scripts/jest/ts-preprocessor.js @@ -19,7 +19,16 @@ function compile(content, contentFilename) { var output = null; var compilerHost = { getSourceFile: function(filename, languageVersion) { - var source; + var source, reactRegex; + + // Accomodations for backslashes in Windows file paths. + if (process.platform === 'win32') { + filename = filename.replace(/\//g, '\\'); + reactRegex = /\\(?:React|ReactDOM)(?:\.d)?\.ts$/; + } else { + reactRegex = /\/(?:React|ReactDOM)(?:\.d)?\.ts$/; + } + if (filename === 'lib.d.ts') { source = fs.readFileSync( require.resolve('typescript/bin/lib.d.ts') @@ -30,7 +39,7 @@ function compile(content, contentFilename) { ).toString(); } else if (filename === contentFilename) { source = content; - } else if (/\/(?:React|ReactDOM)(?:\.d)?\.ts$/.test(filename)) { + } else if (reactRegex.test(filename)) { // TypeScript will look for the .d.ts files in each ancestor directory, // so there may not be a file at the referenced path as it climbs the // hierarchy.