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

Windows watch mode fix #3563

Merged
merged 9 commits into from
May 17, 2017
Merged

Conversation

scottambroseio
Copy link
Contributor

Summary

Fixes #3516

Test plan

Run the 'can select a specific file name from the typeahead results' test in watch-filename-pattern-mode-test.js on both Windows and Unix based systems

@gaearon
Copy link
Contributor

gaearon commented May 16, 2017

This fixes the issue in my testing. Can we please get it in?

@thymikee
Copy link
Collaborator

Feel free to stamp it and @cpojer will merge soon. We could cut a patch release for that I think, but would need to double check for breaking changes

@cpojer
Copy link
Member

cpojer commented May 16, 2017

Yes we can do a patch with this tomorrow. Seems like this diff has lint errors, though. Can you fix them up and make CI pass?

@thymikee
Copy link
Collaborator

Although I'm not super happy we use a third party until just for that, but didn't have time to check what it does, maybe it's reasonable.

@cpojer
Copy link
Member

cpojer commented May 16, 2017

Yeah, it's only used in the test file – can we inline it rather than adding a dependency?

Why can't we use require('jest-regex-util').replacePathSepForRegex; in the test as well?

const isValidPath = require('./lib/isValidPath');
const preRunMessage = require('./preRunMessage');
const replacePathSepForRegex = require('jest-regex-util').replacePathSepForRegex;
Copy link
Member

Choose a reason for hiding this comment

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

nit: const {replacePathSepForRegex} = require('jest-regex-util');

@scottambroseio
Copy link
Contributor Author

Hey, just caught up on this.

You can see my last two comments at #3516 which explains the idea behind regex-slash. I wasn't sure whether to inline it, or make it a dependency like slash. I went the dependency route as I figured being like slash, other's might find it useful. The source is here https://github.com/scottrangerio/regex-slash/blob/master/index.js, it's just a one line function,

module.exports = (pathPattern) => pathPattern.replace(/\\\\/g, '/');

so it would be super easy to inline. I'm not a master at regex, so I'm not sure if there's a more optimal / better regex pattern?

As for using replacePathSepForRegex in the test, this is the result.

test

The test uses a snapshot of a Unix style path pattern. So on windows, for the test to pass, we need a function of the form

// path\\to\\file.js -> path/to/file.js

to match the snapshot so the test passes on Windows.

I'll push the code review fix in a moment. I'm happy to add that helper function to jest-regex-util if that's preferred.

const isValidPath = require('./lib/isValidPath');
const preRunMessage = require('./preRunMessage');
const { replacePathSepForRegex } = require('jest-regex-util');
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove the spaces.

@cpojer
Copy link
Member

cpojer commented May 16, 2017

Can we just inline this in the test? The function is not needed outside the test itself.

Proposal:

  • Inline the function.
  • Run yarn lint locally and fix the CI issues.

@gaearon
Copy link
Contributor

gaearon commented May 16, 2017

@scottrangerio If you don't mind I'll fix up the nits and push to your branch.

@scottambroseio
Copy link
Contributor Author

@gaearon Ah sorry, I only just saw this comment! I just pushed some code but feel free to take over from here on out! Cheers

@@ -2,6 +2,27 @@
# yarn lockfile v1

Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably revert this file?

@@ -145,6 +145,8 @@ describe('Watch mode flows', () => {
});

it('can select a specific file name from the typeahead results', () => {
const toUnixPathPattern = pathPattern => pathPattern.replace(/\\\\/g, '/');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we need to replace two backslashes with a single slash? Where does the second backslash come from?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess because we're dealing with a pattern, so it needs an escape.

Copy link
Contributor Author

@scottambroseio scottambroseio May 16, 2017

Choose a reason for hiding this comment

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

This was the original problem the function is trying to fix

970c1bf0-341a-11e7-92d2-09fc3f05c9de

Due to the backslashs needing escaping, the way I understand it is that behind the hood path\\to\\file is actually path\\\\to\\\\file, if that makes sense?

Edit: Yeah, you summarised it better than I could.

@gaearon
Copy link
Contributor

gaearon commented May 16, 2017

Seems like this is ready. I would really appreciate a patch for this.

@codecov-io
Copy link

Codecov Report

Merging #3563 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3563      +/-   ##
=========================================
+ Coverage   62.39%   62.4%   +<.01%     
=========================================
  Files         181     181              
  Lines        6646    6647       +1     
  Branches        6       6              
=========================================
+ Hits         4147    4148       +1     
  Misses       2496    2496              
  Partials        3       3
Impacted Files Coverage Δ
packages/jest-cli/src/watch.js 76.29% <100%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cf16f1...99d807b. Read the comment docs.

orta pushed a commit to orta/jest that referenced this pull request Jul 7, 2017
* Fix interactive watch arrow selection on Windows jestjs#3516

* Refactored fix for jestjs#3516 to use replacePathSepForRegex

* Fixed the failing test on Windows for the jestjs#3516 fix

* Bump regex-slash to 1.0.1 (provides a flow lib def)

* Update watch-filename-pattern-mode-test.js

* Code review feedback

* Fixed lint errors and implemented PR feedback

* Revert yarn.lock changes
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* Fix interactive watch arrow selection on Windows jestjs#3516

* Refactored fix for jestjs#3516 to use replacePathSepForRegex

* Fixed the failing test on Windows for the jestjs#3516 fix

* Bump regex-slash to 1.0.1 (provides a flow lib def)

* Update watch-filename-pattern-mode-test.js

* Code review feedback

* Fixed lint errors and implemented PR feedback

* Revert yarn.lock changes
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interactive watch arrow selection doesn't work on Windows.
6 participants