fix for TypeScript test on Windows
Thomas Broadley committed
Oct 30, 2015 at 10:22 UTC
d80710b0ae8b30befc88a234554d906bfe336ce1
1 file changed
+11
-2
scripts/jest/ts-preprocessor.js
+11
-2
@@ -19,7 +19,16 @@ function compile(content, contentFilename) {
19
var output = null;
20
var compilerHost = {
21
getSourceFile: function(filename, languageVersion) {
22
- var source;
22
+ var source, reactRegex;
23
+
24
+ // Accomodations for backslashes in Windows file paths.
25
+ if (process.platform === 'win32') {
26
+ filename = filename.replace(/\//g, '\\');
27
+ reactRegex = /\\(?:React|ReactDOM)(?:\.d)?\.ts$/;
28
+ } else {
29
+ reactRegex = /\/(?:React|ReactDOM)(?:\.d)?\.ts$/;
30
+ }
31
+
32
if (filename === 'lib.d.ts') {
33
source = fs.readFileSync(
34
require.resolve('typescript/bin/lib.d.ts')
@@ -30,7 +39,7 @@ function compile(content, contentFilename) {
39
).toString();
40
} else if (filename === contentFilename) {
41
source = content;
33
- } else if (/\/(?:React|ReactDOM)(?:\.d)?\.ts$/.test(filename)) {
42
+ } else if (reactRegex.test(filename)) {
43
// TypeScript will look for the .d.ts files in each ancestor directory,
44
// so there may not be a file at the referenced path as it climbs the
45
// hierarchy.