From cca38150ffc0883081d15af5cc3d2a87aac9aa03 Mon Sep 17 00:00:00 2001 From: Blake Friedman Date: Mon, 26 Feb 2024 11:23:19 +0000 Subject: [PATCH] Fix issue with AppName stripping incorrectly. Handles cases where appName is empty. --- src/__tests__/utils.spec.ts | 19 +++++++++++++++++++ src/utils.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/__tests__/utils.spec.ts b/src/__tests__/utils.spec.ts index d01996b3..260af063 100644 --- a/src/__tests__/utils.spec.ts +++ b/src/__tests__/utils.spec.ts @@ -2,6 +2,7 @@ import { PACKAGE_NAMES } from '../constants' import '../releases/__mocks__/index' import { getVersionsContentInDiff, + removeAppPathPrefix, replaceAppDetails, getChangelogURL, } from '../utils' @@ -132,3 +133,21 @@ describe('replaceAppDetails ', () => { } ) }) + +describe('removeAppPathPrefix', () => { + test.each([ + ['RnDiffApp/package.json', 'package.json'], + ['RnDiffApp/RnDiffApp.ts', 'RnDiffApp.ts'], + ])('removeAppPathPrefix("%s") -> "%s"', (path, newPath) => { + expect(removeAppPathPrefix(path)).toEqual(newPath) + }) + + test('removeAppPathPrefix custom AppName', () => { + expect(removeAppPathPrefix('RnDiffApp/package.json', '')).toEqual( + 'RnDiffApp/package.json' + ) + expect(removeAppPathPrefix('Foobar/package.json', 'Foobar')).toEqual( + 'package.json' + ) + }) +}) diff --git a/src/utils.ts b/src/utils.ts index 1ae109e2..a22c1711 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -75,7 +75,7 @@ export const getBinaryFileURL = ({ } export const removeAppPathPrefix = (path: string, appName = DEFAULT_APP_NAME) => - path.replace(new RegExp(`${appName}/`), '') + path.replace(new RegExp(`^${appName}/`), '') /** * Replaces DEFAULT_APP_PACKAGE and DEFAULT_APP_NAME in str with custom