Skip to content

Commit

Permalink
fix for TypeScript test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroadley committed Oct 30, 2015
1 parent b8f502b commit d80710b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/jest/ts-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand Down

0 comments on commit d80710b

Please sign in to comment.