Skip to content

fix failed tests on Windows #8737#8747

Merged
gaearon merged 5 commits intofacebook:masterfrom
jddxf:fix-failed-tests-on-windows
Jan 12, 2017
Merged

fix failed tests on Windows #8737#8747
gaearon merged 5 commits intofacebook:masterfrom
jddxf:fix-failed-tests-on-windows

Conversation

@jddxf
Copy link
Copy Markdown
Contributor

@jddxf jddxf commented Jan 11, 2017

No description provided.

Comment thread scripts/jest/ts-preprocessor.js Outdated
filename = path.normalize(filename);
var reactRegex = new RegExp(
path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$')
'\\' + path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this helps exactly? There is a comment right above:

 
       // `path.normalize` and `path.join` are used to turn forward slashes in
        // the file path into backslashes on Windows.

Are they not helping? Why?

Ideally I’d like to see us use one separator style, and normalize paths when necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They help to normalize the path.But we need more work to construct a RegExp instance.

image

The backslash added here is to escape the leading separator, which is an special character in regular expression.

Oh,Wait.All of a sudden, I find the dots need to be escaped too.So I'll change it to:

var reactRegex = new RegExp(
  path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$')
    .replace(/[\\.]/g, '\\$&')
);

Or more simple, if we don't mind matching files like XXXReact.d.ts:

var reactRegex = /(?:React|ReactDOM)(?:\.d)?\.ts$/;

@gaearon Which do you think would be better?

jddxf added 2 commits January 12, 2017 11:59
…eed to bother with escaping special character like `\` and `.`.

Note that by removing the path separator in regexp, I've relaxed the matching condition a little.Since there's little chance we have files like `XXXReact.d.ts`,it should not matter.
@gaearon gaearon merged commit e240470 into facebook:master Jan 12, 2017
@gaearon
Copy link
Copy Markdown
Collaborator

gaearon commented Jan 12, 2017

Thank you for fixing this!

@jddxf jddxf deleted the fix-failed-tests-on-windows branch January 13, 2017 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants