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

Migrate jest-regex-util to Typescript #7822

Merged
merged 4 commits into from
Feb 6, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
- `[jest-regex-util]`: Migrate to TypeScript ([#7822](https://github.com/facebook/jest/pull/7822))

### Performance

Expand Down
1 change: 1 addition & 0 deletions packages/jest-regex-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

jest.mock('path');

import {replacePathSepForRegex} from '../index';
import path from 'path';
import {replacePathSepForRegex} from '../index';

describe('replacePathSepForRegex()', () => {
describe('posix', () => {
beforeEach(() => (path.sep = '/'));
beforeEach(() => ((path as any).sep = '/'));

it('should return the path', () => {
const expected = {};
expect(replacePathSepForRegex(expected)).toBe(expected);
expect(replacePathSepForRegex(expected as any)).toBe(expected);
});
});

describe('win32', () => {
beforeEach(() => (path.sep = '\\'));
beforeEach(() => ((path as any).sep = '\\'));

it('should replace POSIX path separators', () => {
expect(replacePathSepForRegex('a/b/c')).toBe('a\\\\b\\\\c');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import path from 'path';
Expand All @@ -25,7 +24,7 @@ export const replacePathSepForRegex = (string: string) => {
if (path.sep === '\\') {
return string.replace(
/(\/|(.)?\\(?![[\]{}()*+?.^$|\\]))/g,
(_match, p1, p2) => (p2 && p2 !== '\\' ? p2 + '\\\\' : '\\\\'),
(_match, _, p2) => (p2 && p2 !== '\\' ? p2 + '\\\\' : '\\\\'),
);
}
return string;
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-regex-util/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}