From d80710b0ae8b30befc88a234554d906bfe336ce1 Mon Sep 17 00:00:00 2001 From: Thomas Broadley Date: Fri, 30 Oct 2015 10:22:50 +0900 Subject: [PATCH 1/2] fix for TypeScript test on Windows --- scripts/jest/ts-preprocessor.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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. From d77e161f99d09c55ca3134419cc2428df331d96e Mon Sep 17 00:00:00 2001 From: Thomas Broadley Date: Sat, 31 Oct 2015 07:38:47 +0900 Subject: [PATCH 2/2] use path library to normalize filepath --- scripts/jest/ts-preprocessor.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/jest/ts-preprocessor.js b/scripts/jest/ts-preprocessor.js index ec10c03109..ecfa149d89 100644 --- a/scripts/jest/ts-preprocessor.js +++ b/scripts/jest/ts-preprocessor.js @@ -19,15 +19,14 @@ function compile(content, contentFilename) { var output = null; var compilerHost = { getSourceFile: function(filename, languageVersion) { - var source, reactRegex; + var source; - // 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$/; - } + // `path.normalize` and `path.join` are used to turn forward slashes in + // the file path into backslashes on Windows. + filename = path.normalize(filename); + var reactRegex = new RegExp( + path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$') + ); if (filename === 'lib.d.ts') { source = fs.readFileSync(