From ad42ca3c3e07972433d884268c0499e93b8b002d Mon Sep 17 00:00:00 2001 From: Sebastian Nemeth Date: Wed, 22 Jul 2020 16:53:21 +0300 Subject: [PATCH] fix(mapper): specs fail in win32 due to double slash notation --- src/config/getOsPath.spec.ts | 11 +++++++++++ src/config/getOsPath.ts | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/config/getOsPath.spec.ts diff --git a/src/config/getOsPath.spec.ts b/src/config/getOsPath.spec.ts new file mode 100644 index 0000000000..7392690af0 --- /dev/null +++ b/src/config/getOsPath.spec.ts @@ -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"`, + ) + }) +}) diff --git a/src/config/getOsPath.ts b/src/config/getOsPath.ts index 6f12159251..c98b7bd409 100644 --- a/src/config/getOsPath.ts +++ b/src/config/getOsPath.ts @@ -1,7 +1,12 @@ import * as path from 'path' -export const getOsPath = (...paths: string[]): string => { +const MatchWinSeparator = /(? { 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)