Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain posix paths in Jest config #1635

Merged
merged 1 commit into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ prompt(
// Add Jest config
console.log(' Adding ' + cyan('Jest') + ' configuration');
appPackage.jest = createJestConfig(
filePath => path.join('<rootDir>', filePath),
filePath => path.posix.join('<rootDir>', filePath),
Copy link
Contributor

Choose a reason for hiding this comment

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

This wouldn't fix any wrong slashes in filePath itself though, would it?

Copy link
Contributor Author

@Timer Timer Feb 24, 2017

Choose a reason for hiding this comment

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

No, it doesn't, but we always pass it /, and path.win32 switches those to \.
See https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/utils/createJestConfig.js#L24.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking at "setupFiles": [ "<rootDir>\\config\\polyfills.js" ] from #1417. Doesn't this mean the whole path needs to be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify, path.win32 supports / and \ (and outputs \) but path.posix only supports /.

See this discrete note at the bottom: https://nodejs.org/api/path.html#path_path_win32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking at "setupFiles": [ "\config\polyfills.js" ] from #1417. Doesn't this mean the whole path needs to be fixed?

The problem is that the windows flavor of path.join will switch / to \, this prevents that from happening. We always pass it / so we don't need to fix the whole path.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, just checked. 👍

null,
true
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createJestConfig = require('../utils/createJestConfig');
const path = require('path');
const paths = require('../config/paths');
argv.push('--config', JSON.stringify(createJestConfig(
relativePath => path.resolve(__dirname, '..', relativePath),
relativePath => path.posix.resolve(__dirname.replace(/[\\]+/g, path.posix.sep), '..', relativePath),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

path.posix doesn't replace \ with / so we have to do it manually.
/cc @gaearon

path.resolve(paths.appSrc, '..'),
false
)));
Expand Down