Skip to content

Commit 6f90ef7

Browse files
qdr108meta-codesync[bot]
authored andcommitted
Add asset utils resource identifier tests (#57999)
Summary: Adds test coverage for `getAndroidResourceIdentifier` in `react-native/asset-utils`. The tests cover folder path encoding, Android resource-name normalization, and generated asset path prefix removal. ## Changelog: [INTERNAL] - Add test coverage for asset utils Android resource identifier normalization Pull Request resolved: #57999 Test Plan: Ran the package suite on this rebased commit: ``` yarn jest packages/asset-utils # 1 suite, 7 passed (4 pre-existing, 3 new) ``` Checked that the three new cases are non-vacuous by mutating `packages/asset-utils/src/AndroidPathUtils.js` one change at a time and re-running: | mutation | result | | --- | --- | | narrow the prefix regex to `^assets_` | 1 failed, 6 passed | | drop the `[^a-z0-9_]` illegal-char strip | 1 failed, 6 passed | | drop `toLowerCase()` | 1 failed, 6 passed | | restored | 7 passed | Each new test kills exactly one distinct mutant, so all three assert real behavior rather than padding coverage. The `^assets_` case matters most: the real regex is `^(?:assets|assetsunstable_path)_`, where the first alternative matches `assets` then fails on the following character, so the second alternative has to carry it. This PR only adds `describe` blocks to an existing test file that was already running, so there is no new test target to register. Reviewed By: christophpurrer Differential Revision: D117191484 Pulled By: fabriziocucci fbshipit-source-id: 7a13c01772669eaf0ddfdf29156d8f250fd5cada
1 parent 90a539c commit 6f90ef7

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

packages/asset-utils/src/__tests__/AndroidPathUtils-test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
* @format
99
*/
1010

11-
import {getAndroidResourceFolderName} from '../AndroidPathUtils';
11+
import {
12+
getAndroidResourceFolderName,
13+
getAndroidResourceIdentifier,
14+
} from '../AndroidPathUtils';
1215

1316
const DRAWABLE_ASSET = {
1417
httpServerLocation: '/assets/',
@@ -70,3 +73,35 @@ describe('getAndroidResourceFolderName', () => {
7073
expect(getAndroidResourceFolderName(NON_DRAWABLE_ASSET, 1.25)).toBe('raw');
7174
});
7275
});
76+
77+
describe('getAndroidResourceIdentifier', () => {
78+
test('encodes folder structure in the resource name', () => {
79+
expect(
80+
getAndroidResourceIdentifier({
81+
httpServerLocation: '/assets/images/icons',
82+
name: 'search',
83+
type: 'png',
84+
}),
85+
).toBe('images_icons_search');
86+
});
87+
88+
test('normalizes resource names to Android identifier characters', () => {
89+
expect(
90+
getAndroidResourceIdentifier({
91+
httpServerLocation: '/assets/images',
92+
name: 'My Icon@2x',
93+
type: 'png',
94+
}),
95+
).toBe('images_myicon2x');
96+
});
97+
98+
test('removes generated asset path prefixes', () => {
99+
expect(
100+
getAndroidResourceIdentifier({
101+
httpServerLocation: '/assetsunstable_path/packages/app',
102+
name: 'logo',
103+
type: 'png',
104+
}),
105+
).toBe('packages_app_logo');
106+
});
107+
});

0 commit comments

Comments
 (0)