Skip to content

Commit

Permalink
fix(mapper): specs fail in win32 due to double slash notation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Nemeth committed Jul 22, 2020
1 parent f0438ee commit ad42ca3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/config/getOsPath.spec.ts
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"`,
)
})
})
9 changes: 7 additions & 2 deletions src/config/getOsPath.ts
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)

0 comments on commit ad42ca3

Please sign in to comment.