-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mapper): specs fail in win32 due to double slash notation
- Loading branch information
Sebastian Nemeth
committed
Jul 22, 2020
1 parent
f0438ee
commit ad42ca3
Showing
2 changed files
with
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { getWinPath } from './getOsPath' | ||
|
||
describe('getWinPath', () => { | ||
it('returns win32 paths on windows', () => { | ||
const input = `C:\\\\Users\\travis\\build\\kulshekhar\\ts-jest\\src\\config\\__helpers__\\project-1` | ||
|
||
expect(getWinPath(input)).toMatchInlineSnapshot( | ||
`"C:\\\\\\\\Users\\\\\\\\travis\\\\\\\\build\\\\\\\\kulshekhar\\\\\\\\ts-jest\\\\\\\\src\\\\\\\\config\\\\\\\\__helpers__\\\\\\\\project-1"`, | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import * as path from 'path' | ||
|
||
export const getOsPath = (...paths: string[]): string => { | ||
const MatchWinSeparator = /(?<!\\)(\\)(?!\\)/gm | ||
|
||
export const getWinPath = (...paths: string[]): string => { | ||
const joinedPath = path.join(...paths) | ||
|
||
return process.platform === 'win32' ? joinedPath.replace('\\', '\\\\') : joinedPath | ||
return joinedPath.replace(MatchWinSeparator, '\\\\') | ||
} | ||
|
||
export const getOsPath = (...paths: string[]): string => | ||
process.platform === 'win32' ? getWinPath(...paths) : path.join(...paths) |