Skip to content

Commit

Permalink
Fix issue with AppName stripping incorrectly.
Browse files Browse the repository at this point in the history
Handles cases where appName is empty.
  • Loading branch information
blakef committed Feb 26, 2024
1 parent b6bbf79 commit cca3815
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PACKAGE_NAMES } from '../constants'
import '../releases/__mocks__/index'
import {
getVersionsContentInDiff,
removeAppPathPrefix,
replaceAppDetails,
getChangelogURL,
} from '../utils'
Expand Down Expand Up @@ -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'
)
})
})
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cca3815

Please sign in to comment.