Skip to content

Commit

Permalink
Migrate jest-regex-util to Typescript (#7822)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzorapetti authored and SimenB committed Feb 6, 2019
1 parent 0c07df0 commit 4621d05
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
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"
}
}

0 comments on commit 4621d05

Please sign in to comment.