Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.


contexts[0].config = {rootDir: ''};
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);

Expand All @@ -164,7 +166,7 @@ describe('Watch mode flows', () => {

stdin.emit(KEYS.ENTER);

expect(argv.testPathPattern).toMatchSnapshot();
expect(toUnixPathPattern(argv.testPathPattern)).toMatchSnapshot();
});

it('Results in pattern mode get truncated appropriately', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import type {Context} from 'types/Context';

const ansiEscapes = require('ansi-escapes');
const chalk = require('chalk');
const {replacePathSepForRegex} = require('jest-regex-util');
const HasteMap = require('jest-haste-map');
const isCI = require('is-ci');
const createContext = require('./lib/createContext');
const isValidPath = require('./lib/isValidPath');
const preRunMessage = require('./preRunMessage');
const createContext = require('./lib/createContext');
const runJest = require('./runJest');
const updateArgv = require('./lib/updateArgv');
const SearchSource = require('./SearchSource');
Expand Down Expand Up @@ -201,7 +202,7 @@ const watch = (
testPathPattern => {
updateArgv(argv, 'watch', {
testNamePattern: '',
testPathPattern,
testPathPattern: replacePathSepForRegex(testPathPattern),
});

startRun();
Expand Down