-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest-haste-map: watchman crawler: normalize paths (#3887)
* jest-haste-map: watchman crawler: normalize paths * also normalize path coming from watcher * simplify, add module + tests * add posix case
- Loading branch information
1 parent
c8a5135
commit fc48b91
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
'use strict'; | ||
|
||
describe('normalizePathSep', () => { | ||
it('does nothing on posix', () => { | ||
jest.resetModules(); | ||
jest.mock('path', () => require.requireActual('path').posix); | ||
const normalizePathSep = require('../normalize_path_sep'); | ||
expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo/bar/baz.js'); | ||
}); | ||
|
||
it('replace slashes on windows', () => { | ||
jest.resetModules(); | ||
jest.mock('path', () => require.requireActual('path').win32); | ||
const normalizePathSep = require('../normalize_path_sep'); | ||
expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo\\bar\\baz.js'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
const path = require('path'); | ||
|
||
let normalizePathSep; | ||
if (path.sep == '/') { | ||
normalizePathSep = (filePath: string) => filePath; | ||
} else { | ||
normalizePathSep = (filePath: string) => filePath.replace(/\//g, path.sep); | ||
} | ||
|
||
module.exports = normalizePathSep; |